Skip to content

Commit

Permalink
test: add jest resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed May 6, 2022
1 parent 736b483 commit fe7cadf
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const tsModuleNameMapper = pathsToModuleNameMapper(tsconfig.compilerOptions.path
const baseConfig = {
preset: 'ts-jest',
testRunner: 'jest-jasmine2',
resolver: '<rootDir>/tools/dev-tool/src/jest-resolver.js',
coverageProvider: process.env.JEST_COVERAGE_PROVIDER || 'babel',
// https://dev.to/vantanev/make-your-jest-tests-up-to-20-faster-by-changing-a-single-setting-i36
maxWorkers: '50%',
Expand Down
1 change: 0 additions & 1 deletion packages/core-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"ajv": "^6.10.0",
"classnames": "2.2.6",
"clsx": "^1.0.4",
"file-icons-js": "^1.0.3",
"font-awesome": "^4.7.0",
"fuzzy": "^0.1.3",
"jsonc-parser": "^2.1.0",
Expand Down
16 changes: 16 additions & 0 deletions tools/dev-tool/src/jest-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 关于 resolver 的文档请看: https://jestjs.io/docs/configuration#resolver-string

module.exports = (path, options) =>
// Call the defaultResolver, so we leverage its cache, error handling, etc.
options.defaultResolver(path, {
...options,
// Use packageFilter to process parsed `package.json` before the resolution (see https://www.npmjs.com/package/resolve#resolveid-opts-cb)
packageFilter: (pkg) => {
if (pkg.name === 'nanoid') {
// 一个对于 jest@28 的 workaround,具体原因请见:https://github.com/microsoft/accessibility-insights-web/pull/5421/commits/9ad4e618019298d82732d49d00aafb846fb6bac7
delete pkg['exports'];
delete pkg['module'];
}
return pkg;
},
});
4 changes: 0 additions & 4 deletions typings/css.escape/index.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions typings/file-icons-js/index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion typings/path-match/index.d.ts

This file was deleted.

9 changes: 0 additions & 9 deletions typings/rc/index.d.ts

This file was deleted.

0 comments on commit fe7cadf

Please sign in to comment.