[英]Configure `jest-preset-angular` with angular workspace
File structure:文件结构:
- projects
- projectA
- tsconfig.app.json
- tsconfig.spec.json
- projectB
- tsconfig.app.json
- tsconfig.spec.json
- jest.config.js
- setup-jest.ts
- tsconfig.base.json
- tsconfig.json
I followed the installation https://thymikee.github.io/jest-preset-angular/docs/getting-started/installation .我按照安装https://thymikee.github.io/jest-preset-angular/docs/getting-started/installation安装。
If I go with https://thymikee.github.io/jest-preset-angular/docs/guides/angular-ivy#control-ngcc-processing , it obviously doesn't find tsconfig.spec.json
:如果我 go 与https://thymikee.github.io/jest-preset-angular/docs/guides/angular-ivy#control-ngcc-processing ,它显然找不到
tsconfig.spec.json
:
File not found: <rootDir>/tsconfig.spec.json
In my case, I have one tsconfig.spec.json
per project...就我而言,每个项目有一个
tsconfig.spec.json
...
// jest.config.js
globalThis.ngJest = {
skipNgcc: true,
tsconfig: 'tsconfig.spec.json', // this is the project root tsconfig
};
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
globalSetup: 'jest-preset-angular/global-setup',
// https://thymikee.github.io/jest-preset-angular/docs/getting-started/installation#avoid-karma-conflicts
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/test.ts',
'<rootDir>/projects/projectA/src/test.ts',
'<rootDir>/projects/projectB/src/test.ts',
]
// projects: [
// "<rootDir>/projects/fvl"
// ]
};
Without the ngcc skip:没有 ngcc 跳过:
// jest.config.js
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
globalSetup: 'jest-preset-angular/global-setup',
// https://thymikee.github.io/jest-preset-angular/docs/getting-started/installation#avoid-karma-conflicts
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/test.ts',
'<rootDir>/projects/projectA/src/test.ts',
'<rootDir>/projects/projectB/src/test.ts',
]
// projects: [
// "<rootDir>/projects/fvl"
// ]
};
I get the ngcc error:我收到 ngcc 错误:
ngcc-jest-processor: running ngcc
Warning: The inferred tsconfig file "root_project/tsconfig.json" appears to be "solution-style" since it contains no root files but does contain project references.
This is probably not wanted, since ngcc is unable to infer settings like "paths" mappings from such a file.
Perhaps you should have explicitly specified one of the referenced projects using the --tsconfig option. For example:
ngcc ... --tsconfig "./projects/projectA/tsconfig.app.json"
ngcc ... --tsconfig "./projects/projectA/tsconfig.spec.json"
ngcc ... --tsconfig "./projects/projectB/tsconfig.app.json"
ngcc ... --tsconfig "./projects/projectB/tsconfig.spec.json"
I appreciate if someone has a working configuration with jest-preset-angular
and angular workspaces.如果有人具有
jest-preset-angular
和 angular 工作区的工作配置,我将不胜感激。
I got it working with:我得到它的工作:
workspace-project/jest-config.js工作区项目/jest-config.js
module.exports = {
preset: 'jest-preset-angular',
globalSetup: 'jest-preset-angular/global-setup',
setupFilesAfterEnv: [ '<rootDir>/../../setup-jest.ts' ]
};
workspace-project/setup-jest.ts工作区项目/setup-jest.ts
import 'jest-preset-angular/setup-jest';
workspace-project/projects/my-library1/jest.config.js工作区项目/项目/my-library1/jest.config.js
const baseConfig = require('../../jest.config');
module.exports = {
...baseConfig,
coverageDirectory: '<rootDir>/../../dist/my-library1/__coverage'
};
workspace-project/tsconfig.spec.js工作区项目/tsconfig.spec.js
workspace-project/projects/my-library1/tsconfig.spec.json工作区项目/项目/my-library1/tsconfig.spec.json
...
"compilerOptions": {
...
"module": "CommonJs",
"types": [ "jest" ]
}
workspace-project/package.json工作区项目/package.json
...
"scripts": {
...
"test:my-library1": "jest --config ./projects/my-library1/jest.config.js"
},
I hope it's usefull for someone!我希望它对某人有用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.