-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use swc to run jest unit test
- Loading branch information
Showing
69 changed files
with
3,596 additions
and
5,123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
"**/*.{ts,js}": ["eslint --fix"], | ||
"**/*.{ts,js,json,md,yml,yaml}": ["prettier --write"] | ||
"**/*.{json,md,yml,yaml}": ["prettier --write"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env node | ||
import fs from "fs-extra"; | ||
import { join } from "path"; | ||
|
||
async function writeCoverage(cwd) { | ||
const coveragePath = join(cwd, "coverage.json"); | ||
|
||
const { | ||
total: { lines, statements, functions, branches } | ||
} = await fs.readJson(join(cwd, "coverage/coverage-summary.json")); | ||
|
||
fs.writeJson( | ||
coveragePath, | ||
{ | ||
statements: statements.pct, | ||
branches: branches.pct, | ||
functions: functions.pct, | ||
lines: lines.pct | ||
}, | ||
{ spaces: 2 } | ||
); | ||
} | ||
|
||
writeCoverage(process.cwd()); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
|
||
// This is a custom Jest transformer turning style imports into empty objects. | ||
// http://facebook.github.io/jest/docs/en/webpack.html | ||
|
||
module.exports = { | ||
process() { | ||
return { code: "module.exports = {};" }; | ||
}, | ||
getCacheKey() { | ||
// The output is always the same. | ||
return "cssTransform"; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
|
||
const path = require("path"); | ||
const camelcase = require("camelcase"); | ||
|
||
// This is a custom Jest transformer turning file imports into filenames. | ||
// http://facebook.github.io/jest/docs/en/webpack.html | ||
|
||
module.exports = { | ||
process(src, filename) { | ||
const assetFilename = JSON.stringify(path.basename(filename)); | ||
|
||
if (filename.match(/\.svg$/)) { | ||
// Based on how SVGR generates a component name: | ||
// https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6 | ||
const pascalCaseFilename = camelcase(path.parse(filename).name, { | ||
pascalCase: true | ||
}); | ||
const componentName = `Svg${pascalCaseFilename}`; | ||
return { | ||
code: `const React = require('react'); | ||
module.exports = { | ||
__esModule: true, | ||
default: ${assetFilename}, | ||
ReactComponent: React.forwardRef(function ${componentName}(props, ref) { | ||
return { | ||
$$typeof: Symbol.for('react.element'), | ||
type: 'svg', | ||
ref: ref, | ||
key: null, | ||
props: Object.assign({}, props, { | ||
children: ${assetFilename} | ||
}) | ||
}; | ||
}), | ||
};` | ||
}; | ||
} | ||
|
||
return { code: `module.exports = ${assetFilename};` }; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** @type {import("ts-jest/dist/types").InitialOptionsTsJest} */ | ||
|
||
module.exports = { | ||
roots: ["<rootDir>/src"], | ||
collectCoverageFrom: ["src/**/*.{js,jsx,ts,tsx}", "!src/**/*.d.ts", "!src/mocks/**", "!src/__mock__/**"], | ||
coveragePathIgnorePatterns: [], | ||
testEnvironment: "node", | ||
transform: { | ||
"^.+\\.(t|j)sx?$": ["@swc/jest", require("./swc.node.json")] | ||
// "^.+\\.(t|j)sx?$": ["ts-jest"] | ||
}, | ||
transformIgnorePatterns: ["[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$", "^.+\\.module\\.(css|sass|scss)$"], | ||
modulePaths: ["<rootDir>/src"], | ||
moduleNameMapper: {}, | ||
moduleFileExtensions: [ | ||
// Place tsx and ts to beginning as suggestion from Jest team | ||
// https://jestjs.io/docs/configuration#modulefileextensions-arraystring | ||
"tsx", | ||
"ts", | ||
"js", | ||
"json", | ||
"jsx", | ||
"node" | ||
], | ||
watchPlugins: ["jest-watch-typeahead/filename", "jest-watch-typeahead/testname"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
roots: ['<rootDir>/src'], | ||
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts', '!src/mocks/**', '!src/__mock__/**'], | ||
coveragePathIgnorePatterns: [], | ||
testEnvironment: 'jsdom', | ||
setupFilesAfterEnv: [require.resolve('./setupTest.js')], | ||
transform: { | ||
'^.+\\.(t|j)sx?$': ['@swc/jest', require('./swc.web.json')], | ||
'^.+\\.css$': require.resolve('./cssTransform.js'), | ||
'^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': require.resolve('./fileTransform.js') | ||
}, | ||
transformIgnorePatterns: [ '^.+\\.module\\.(css|sass|scss)$'], | ||
modulePaths: ['<rootDir>/src'], | ||
moduleNameMapper: { | ||
'^react-native$': 'react-native-web', | ||
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy' | ||
}, | ||
moduleFileExtensions: [ | ||
// Place tsx and ts to beginning as suggestion from Jest team | ||
// https://jestjs.io/docs/configuration#modulefileextensions-arraystring | ||
'tsx', | ||
'ts', | ||
'web.js', | ||
'js', | ||
'web.ts', | ||
'web.tsx', | ||
'json', | ||
'web.jsx', | ||
'jsx', | ||
'node' | ||
], | ||
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import '@testing-library/jest-dom/extend-expect' | ||
|
||
window.matchMedia = (query) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn(), | ||
addListener: jest.fn(), | ||
removeListener: jest.fn() | ||
}) | ||
|
||
Object.defineProperty(URL, 'createObjectURL', { | ||
writable: true, | ||
value: jest.fn() | ||
}) | ||
|
||
if (typeof window !== 'undefined') { | ||
window.scrollTo = jest.fn() | ||
|
||
jest.mock( | ||
'react-svg', | ||
() => | ||
function Svg () { | ||
return '' | ||
} | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"jsc": { | ||
"target": "es2021", | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": true, | ||
"decorators": true, | ||
"dynamicImport": true, | ||
"privateMethod": true, | ||
"exportDefaultFrom": true, | ||
"importMeta": true | ||
}, | ||
"transform": { | ||
"hidden": { | ||
"jest": true | ||
}, | ||
"legacyDecorator": true, | ||
"decoratorMetadata": true | ||
} | ||
}, | ||
"module": { | ||
"type": "commonjs", | ||
"strict": false, | ||
"strictMode": true, | ||
"lazy": false, | ||
"noInterop": false | ||
} | ||
} |
Oops, something went wrong.