Skip to content

Commit

Permalink
fix(tests): fix tests (because of esm module breaking jest)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvcol committed Apr 10, 2022
1 parent 4862669 commit 31105c3
Show file tree
Hide file tree
Showing 7 changed files with 13,881 additions and 13,867 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"parserOptions": {
"project": [
"tsconfig.json",
"tsconfig.test.json"
"tsconfig.spec.json"
]
},
"rules": {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
uses: ArtiomTr/jest-coverage-report-action@v2.0.5
with:
package-manager: yarn
test-script: yarn test
test-script: yarn test:unit
40 changes: 26 additions & 14 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
/** @type {import("ts-jest/dist/types").InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
preset: "ts-jest",
testEnvironment: "jsdom",

// The root of your source code
roots: ['<rootDir>/src'],
roots: [ "<rootDir>/src" ],

// Target test tsconfig
globals: {
"ts-jest": {
tsconfig: "<rootDir>/tsconfig.spec.json",
"useESM": true
}
},

// Jest transformations -- this adds support for TypeScript using ts-jest
transform: {
'^.+\\.tsx?$': 'ts-jest',
"^.+\\.tsx?$": "ts-jest"
},

// Test spec file resolution pattern
// Matches parent folder `__tests__` and filename should contain `test` or `spec`.
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",

// Minimum coverage thresholds
// TODO : Increase threshold after implementing tests
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
branches: 0,
functions: 0,
lines: 0,
statements: 0
}
},

// Module file extensions for importing
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
moduleFileExtensions: [ "ts", "tsx", "js", "jsx", "json", "node" ],

extensionsToTreatAsEsm: [ ".ts", ".tsx" ],
// Webpack alias config=
moduleNameMapper: {
'^@src/(.*)$': '<rootDir>/src/$1',
"^@src/(.*)$": "<rootDir>/src/$1"
},

// Setup scripts before tests
setupFilesAfterEnv: ['<rootDir>/test/setup.test.ts'],
setupFilesAfterEnv: [
"<rootDir>/test/setup.test.ts"
]
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@mui/material": "^5.5.0",
"@reduxjs/toolkit": "^1.7.2",
"notistack": "^2.0.3",
"pretty-bytes": "^6.0.0",
"pretty-bytes": "^5.6.0",
"query-string": "^7.1.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand All @@ -59,7 +59,7 @@
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.3",
"@types/chrome": "^0.0.180",
"@types/jest": "^27.4.0",
"@types/jest": "^27.4.1",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.13",
"@types/react-redux": "^7.1.22",
Expand All @@ -72,6 +72,7 @@
"@typescript-eslint/eslint-plugin": "^5.18.0",
"@typescript-eslint/parser": "^5.18.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^27.5.1",
"babel-loader": "^8.2.3",
"babel-preset-react-app": "^10.0.1",
"chrome-webstore-upload-cli": "^2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ exports[`material-icon.tsx component Renders game icon: game 1`] = `
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-testid="PhotoLibraryIcon"
data-testid="VideogameAssetIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M22 16V4c0-1.1-.9-2-2-2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2zm-11-4 2.03 2.71L16 11l4 5H8l3-4zM2 6v14c0 1.1.9 2 2 2h14v-2H4V6H2z"
d="M21 6H3c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm-10 7H8v3H6v-3H3v-2h3V8h2v3h3v2zm4.5 2c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5zm4-3c-.83 0-1.5-.67-1.5-1.5S18.67 9 19.5 9s1.5.67 1.5 1.5-.67 1.5-1.5 1.5z"
/>
</svg>
</DocumentFragment>
Expand Down
File renamed without changes.

0 comments on commit 31105c3

Please sign in to comment.