From 9d0579a662d757de63022de415dd2e4e8a0a66e0 Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 10 Dec 2022 22:26:19 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jest.config.js | 33 ++++++++++++------------------ jest.setup.js | 6 ++++++ jest.setup.ts | 5 ----- package.json | 3 ++- {__tests__ => tests}/index.test.ts | 2 +- tsconfig.json | 1 - 6 files changed, 22 insertions(+), 28 deletions(-) create mode 100644 jest.setup.js delete mode 100644 jest.setup.ts rename {__tests__ => tests}/index.test.ts (82%) diff --git a/jest.config.js b/jest.config.js index 06030cd..54a29f7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,20 +1,13 @@ -module.exports = { - collectCoverageFrom: [ - '**/*.{js,jsx,ts,tsx}', - '!**/*.d.ts', - '!**/node_modules/**', - ], - setupFilesAfterEnv: ['/setupTests.js'], - testPathIgnorePatterns: ['/node_modules/', '/.next/'], - transform: { - '^.+\\.(js|jsx|ts|tsx)$': '/node_modules/babel-jest', - '^.+\\.css$': '/config/jest/cssTransform.js', - }, - transformIgnorePatterns: [ - '/node_modules/', - '^.+\\.module\\.(css|sass|scss)$', - ], - moduleNameMapper: { - '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy', - }, -} \ No newline at end of file +const nextJest = require('next/jest') + +const createJestConfig = nextJest({ + dir: './', +}) + +const customJestConfig = { + setupFilesAfterEnv: ['/jest.setup.js'], + moduleDirectories: ['node_modules', '/'], + testEnvironment: 'jest-environment-jsdom', +} + +module.exports = createJestConfig(customJestConfig) \ No newline at end of file diff --git a/jest.setup.js b/jest.setup.js new file mode 100644 index 0000000..bdc69d8 --- /dev/null +++ b/jest.setup.js @@ -0,0 +1,6 @@ +// Optional: configure or set up a testing framework before each test. +// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js` + +// Used for __tests__/testing-library.js +// Learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom/extend-expect' \ No newline at end of file diff --git a/jest.setup.ts b/jest.setup.ts deleted file mode 100644 index 309cb36..0000000 --- a/jest.setup.ts +++ /dev/null @@ -1,5 +0,0 @@ -// jest.setup.ts -import '@testing-library/jest-dom'; - - -configure({ adapter: new ReactAdapter() }); \ No newline at end of file diff --git a/package.json b/package.json index 98904fb..7c33125 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "start": "next start", "db": "npx prisma migrate reset --force", "test": "jest --watch", - "test-e2e" : "playwright test" + "test-e2e" : "playwright test", + "test:ci" : "jest --ci" }, "dependencies": { "@hookform/resolvers": "^2.9.10", diff --git a/__tests__/index.test.ts b/tests/index.test.ts similarity index 82% rename from __tests__/index.test.ts rename to tests/index.test.ts index d21ca48..b35b256 100644 --- a/__tests__/index.test.ts +++ b/tests/index.test.ts @@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/react' describe('Index', () => { - it('renders button discover my gift', () => { + it('should show win content if the code is valide', () => { const button = screen.getByRole('button', { name: /Découvrir mon cadeau \.js!/i, }) diff --git a/tsconfig.json b/tsconfig.json index 64578b0..c45febe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,7 +26,6 @@ "next-env.d.ts", "**/*.ts", "**/*.tsx", - "tests/**.ts" ], "ts-node": { "compilerOptions": {