Skip to content

Commit

Permalink
test: setup test to run jsdom and node enviroment
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhyen99 committed Sep 13, 2024
1 parent cd5fc36 commit 745b300
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

- name: Run tests
run: |
yarn run test --changedSince=origin/next --ci --json --coverage --testLocationInResults --outputFile=report.json
yarn jest --changedSince=origin/next --ci --json --coverage --testLocationInResults --outputFile=report.json
- name: Coverage
uses: artiomtr/jest-coverage-report-action@v2
Expand Down
77 changes: 65 additions & 12 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { defaults } from 'jest-config';
import ComponentPkg from './packages/components/package.json' assert { type: 'json' };
import MockAppPkg from './packages/mock-app/package.json' assert { type: 'json' };

export default {
rootDir: './',
Expand All @@ -10,25 +12,76 @@ export default {
'!**/types/**',
'!**/build/**',
'!**/node_modules/**',
'!packages/services/src/identityProviders/GS1Provider.ts' // This file call a function that is not exported
],
coverageReporters: ['text', 'lcov', 'json'],
coverageProvider: 'v8',
coverageDirectory: './coverage',
extensionsToTreatAsEsm: ['.ts'],
testMatch: ['**/__tests__/**/*.test.*'],
testPathIgnorePatterns: ['<rootDir>/node_modules/'],
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
],
testEnvironment: 'node',
automock: false,
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.m?tsx?$': [
'ts-jest',
{
useESM: true,
tsconfig: './packages/tsconfig.settings.json',
extensionsToTreatAsEsm: ['.ts'],
projects: [
{
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/packages/components/src/setupTests.ts'],
displayName: ComponentPkg.name,
testMatch: ['<rootDir>/packages/components/**/?(*.)+(spec|test).[jt]s?(x)'],
transform: {
'^.+\\.m?tsx?$': [
'ts-jest',
{
useESM: true,
tsconfig: '<rootDir>/packages/components/tsconfig.json',
},
],
},
],
},
},
{
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/packages/mock-app/jest.config.js'],
displayName: MockAppPkg.name,
testMatch: ['<rootDir>/packages/mock-app/jest.config.js'],
transform: {
'^.+\\.m?tsx?$': [
'ts-jest',
{
useESM: true,
tsconfig: '<rootDir>/packages/mock-app/tsconfig.json',
},
],
},
},
{
// Default Node.js environment tests for all other packages
preset: 'ts-jest',
displayName: 'Node.js environment',
testEnvironment: 'node',
testMatch: ['<rootDir>/packages/**/src/**/?(*.)+(spec|test).[jt]s?(x)'],
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/packages/components',
'<rootDir>/packages/mock-app',
'<rootDir>/packages/services/src/__tests__/gs1.test.ts' // This file call a library that is not exported, so it is ignored
],
transform: {
'^.+\\.m?tsx?$': [
'ts-jest',
{
useESM: true,
tsconfig: '<rootDir>/packages/tsconfig.settings.json',
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
}
},
],
};

0 comments on commit 745b300

Please sign in to comment.