Skip to content

Commit

Permalink
Merge pull request #49 from bigcommerce/DATA-000
Browse files Browse the repository at this point in the history
feat: Setup testing environment
  • Loading branch information
bc-rmalyavc authored May 27, 2024
2 parents 3f006b3 + 05cc77c commit 8a9e366
Show file tree
Hide file tree
Showing 8 changed files with 3,731 additions and 330 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const config = {
parserOptions: {
project: path.join(__dirname, 'tsconfig.json'),
},
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', 'jest'],
extends: ['next/core-web-vitals', 'plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/consistent-type-imports': [
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/validate-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ jobs:
- name: Lint
run: SKIP_ENV_VALIDATION=true npm run lint

- name: Lint
- name: Build
run: SKIP_ENV_VALIDATION=true npm run build

- name: Test
run: SKIP_ENV_VALIDATION=true npm run test
20 changes: 20 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Config } from 'jest'
import nextJest from 'next/jest.js'

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})

const config: Config = {
coverageProvider: 'v8',
testEnvironment: 'jsdom',
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
setupFilesAfterEnv: ['./jest.setup.ts'],
setupFiles: ['./jest.setup.ts']
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
export default createJestConfig(config);
5 changes: 5 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Response, Request, Headers } from '@whatwg-node/fetch';

global.Response = Response;
global.Request = Request;
global.Headers = Headers;
3,987 changes: 3,664 additions & 323 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"start": "next start",
"type-check": "tsc --pretty --noEmit",
"format": "prettier --write **/*.{js,ts,tsx}",
"postinstall": "node ./postinstall.mjs"
"postinstall": "node ./postinstall.mjs",
"test": "jest",
"test:watch": "jest --watch"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -54,20 +56,29 @@
"zod": "^3.22.3"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^15.0.7",
"@types/eslint": "^8.37.0",
"@types/jest": "^29.5.12",
"@types/node": "18.18.4",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@whatwg-node/fetch": "^0.9.17",
"eslint": "^8.40.0",
"eslint-config-next": "^13.4.2",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-prettier": "^5.0.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lint-staged": "^13.2.3",
"prettier": "^3.0.1",
"request": "^2.88.2",
"ts-jest": "^29.1.3",
"ts-node": "^10.9.2",
"typescript": "^5.0.4"
},
"eslintIgnore": [
Expand Down
19 changes: 19 additions & 0 deletions src/app/page.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { render } from '@testing-library/react';
import Page from './page';

const mockHomePage = jest.fn(() => <div>Mock Home Page</div>);

jest.mock('./home-page', () => ({
__esModule: true,
default: () => mockHomePage(),
}));

describe('Page', () => {
it('renders Home page', () => {
render(<Page />);

expect(mockHomePage).toHaveBeenCalled();
});
});

6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"**/*.cjs",
"**/*.mjs",
".next/types/**/*.ts",
"postinstall.mjs"
"postinstall.mjs",
"jest.config.js"
],
"exclude": ["node_modules"]
"exclude": ["node_modules"],
"types": ["jest", "node"]
}

0 comments on commit 8a9e366

Please sign in to comment.