我正在将NX Monorepo从版本13迁移到14,除了Jest迁移之外,一切都很顺利。我遇到了这个错误。我尝试过删除jest缓存、nx缓存、删除整个node_modules,并重新安装,但什么都没有用。如果有人遇到这个问题或者有任何想法,请告诉我。谢谢。
在运行测试时,会出现此错误。
FAIL lib-name libs/lib/src/lib-name/select-options-picker/select-options-picker.component.spec.ts
● Test suite failed to run
EBUSY: resource busy or locked, open 'C:\Users\User\AppData\Local\Temp\jest\ts-jest\c4\1501b067977ee4d35c48eb9ca4f97116c5dfef\e9a8ee471bc676fe755c57379268f21a1390a7a4'
at NgJestTransformer.TsJestTransformer.getCacheKey (../../node_modules/jest-preset-angular/node_modules/ts-jest/dist/ts-jest-transformer.js:245:40)
at ScriptTransformer._getCacheKey (../../node_modules/@jest/transform/build/ScriptTransformer.js:281:41)
at ScriptTransformer._getFileCachePath (../../node_modules/@jest/transform/build/ScriptTransformer.js:352:27)
at ScriptTransformer.transformSource (../../node_modules/@jest/transform/build/ScriptTransformer.js:595:32)
at ScriptTransformer._transformAndBuildScript (../../node_modules/@jest/transform/build/ScriptTransformer.js:765:40)
at ScriptTransformer.transform (../../node_modules/@jest/transform/build/ScriptTransformer.js:822:19)
这是我的package.json文件
{
"name": "rsa",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"ng": "nx",
"postinstall": "node ./decorate-angular-cli.js && ngcc --properties es2020 browser module main",
"start": "ng serve --open",
"test": "nx test",
"test:coverage": "nx test --coverage --watch=false"
},
"private": true,
"dependencies": {
"@angular/animations": "14.1.3",
"@angular/cdk": "14.1.3",
"@angular/common": "14.1.3",
"@angular/compiler": "14.1.3",
"@angular/core": "14.1.3",
"@angular/flex-layout": "^10.0.0-beta.32",
"@angular/forms": "14.1.3",
"@angular/material": "14.1.3",
"@angular/material-moment-adapter": "14.1.3",
"@angular/platform-browser": "14.1.3",
"@angular/platform-browser-dynamic": "14.1.3",
"@angular/router": "14.1.3",
"@ngrx/effects": "14.0.2",
"@ngrx/entity": "14.0.2",
"@ngrx/router-store": "14.0.2",
"@ngrx/store": "14.0.2",
"@ngx-translate/core": "14.0.0",
"@ngx-translate/http-loader": "7.0.0",
"@nrwl/angular": "14.5.10",
"@storybook/core-server": "6.5.10",
"angular-2-local-storage": "^3.0.2",
"apexcharts": "^3.35.0",
"crypto-js": "3.3.0",
"font-awesome": "^4.7.0",
"hammerjs": "^2.0.8",
"highlight.js": "^10.4.1",
"jquery": "^3.5.1",
"keycloak-angular": "^8.0.1",
"keycloak-js": "^11.0.2",
"lodash-es": "^4.17.21",
"moment": "^2.29.3",
"ng-apexcharts": "^1.5.6",
"ng2-pdf-viewer": "^6.3.2",
"ngx-cookie-service": "^10.1.1",
"ngx-material-file-input": "^2.1.1",
"ngx-permissions": "^8.1.1",
"ngx-toastr": "^13.2.0",
"perfect-scrollbar": "1.5.0",
"postcss-loader": "^6.2.1",
"postcss-nested": "^5.0.6",
"postcss-nesting": "^8.0.1",
"postcss-preset-env": "7.5.0",
"postcss-scss": "^4.0.2",
"primeicons": "^5.0.0",
"primeng": "^11.4.5",
"rxjs": "7.5.6",
"simple-keyboard": "^2.29.67",
"tslib": "^2.3.1",
"zone.js": "0.11.4"
},
"devDependencies": {
"@angular-builders/custom-webpack": "^13.1.0",
"@angular-devkit/build-angular": "14.1.3",
"@angular-devkit/core": "14.1.3",
"@angular-eslint/eslint-plugin": "14.0.3",
"@angular-eslint/eslint-plugin-template": "14.0.3",
"@angular-eslint/template-parser": "14.0.3",
"@angular/cli": "~14.1.0",
"@angular/compiler-cli": "14.1.3",
"@angular/language-service": "14.1.3",
"@angularclass/hmr": "^3.0.0",
"@commitlint/cli": "^11.0.0",
"@ngrx/schematics": "14.0.2",
"@ngrx/store-devtools": "14.0.2",
"@nrwl/cli": "14.5.10",
"@nrwl/cypress": "14.5.10",
"@nrwl/eslint-plugin-nx": "14.5.10",
"@nrwl/jest": "14.5.10",
"@nrwl/linter": "14.5.10",
"@nrwl/storybook": "14.5.10",
"@nrwl/workspace": "14.5.10",
"@storybook/addon-actions": "^6.3.0",
"@storybook/addon-controls": "^6.4.1",
"@storybook/addon-docs": "^6.4.22",
"@storybook/addon-essentials": "6.5.10",
"@storybook/addon-knobs": "^6.3.0",
"@storybook/addon-postcss": "~2.0.0",
"@storybook/angular": "6.5.10",
"@storybook/builder-webpack5": "6.5.10",
"@storybook/manager-webpack5": "6.5.10",
"@types/angular-material": "^1.1.71",
"@types/crypto-js": "3.1.47",
"@types/highlight.js": "9.12.4",
"@types/jasmine": "4.0.3",
"@types/jasminewd2": "2.0.8",
"@types/jest": "27.4.1",
"@types/lodash-es": "4.17.3",
"@types/node": "14.14.33",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"autoprefixer": "^10.4.0",
"barrelsby": "^2.2.0",
"codelyzer": "6.0.0-next.1",
"comment-json": "^4.1.0",
"commitizen": "^4.2.2",
"commitlint-config-cz": "^0.13.2",
"conventional-changelog-cli": "2.1.1",
"cross-env": "^7.0.3",
"cypress": "^9.5.4",
"cz-customizable": "^6.3.0",
"dotenv": "10.0.0",
"eslint": "8.15.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-cypress": "^2.10.3",
"html-webpack-plugin": "^5.5.0",
"husky": "^4.2.5",
"jasmine-core": "4.2.0",
"jasmine-marbles": "~0.8.3",
"jasmine-spec-reporter": "7.0.0",
"jest": "27.5.1",
"jest-canvas-mock": "^2.2.0",
"jest-preset-angular": "11.1.2",
"lint-staged": "^10.2.11",
"lodash": "^4.17.19",
"ng-packagr": "14.1.0",
"nx": "14.5.10",
"postcss": "^8.4.4",
"postcss-import": "14.1.0",
"postcss-url": "10.1.3",
"prettier": "2.6.2",
"protractor": "7.0.0",
"sass": "^1.44.0",
"stylelint": "^13.9.0",
"stylelint-config-standard": "^20.0.0",
"stylelint-scss": "^3.18.0",
"tailwindcss": "^2.2.16",
"ts-jest": "27.1.4",
"ts-node": "10.9.1",
"typescript": "4.7.4",
"webpack": "^5.50.0",
"webpack-bundle-analyzer": "^4.4.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged --concurrent false",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"docs/**/*.md": [
"node docs/check-kb-labels",
"node docs/check-dead-links fast",
"node docs/check-documentation-overview",
"node docs/check-sentence-newline"
],
"*.{scss,css}": [
"stylelint --fix"
],
"*": [
"prettier --loglevel warn --write"
],
"*.ts": [
"jest --ci --bail --findRelatedTests --detectOpenHandles"
]
},
"commitlint": {
"extends": [
"cz"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-customizable"
}
},
"postinstall": {
"jest-extended/types": "copy node_modules/@types/jest-extended"
}
}
Jest.preset.js
const nxPreset = require('@nrwl/jest/preset').default;
module.exports = {
...nxPreset,
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
transform: {
'^.+\\.(ts|js|html)$': 'ts-jest',
},
// resolver: '@nrwl/jest/plugins/resolver',
testRunner: 'jest-jasmine2',
moduleFileExtensions: ['ts', 'js', 'html'],
coverageReporters: ['html'],
moduleNameMapper: {
'^lodash-es$': 'lodash',
},
};
Jest.config.ts
/* eslint-disable */
export default {
displayName: 'donor-ui',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
},
coverageDirectory: '../../coverage/apps/donor-ui',
transform: {
'^.+\\.(ts|mjs|js|html)$': 'jest-preset-angular',
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
};