提问人:Amphyx 提问时间:11/17/2023 更新时间:11/17/2023 访问量:29
角度测试 - 排除特定规范文件
Angular tests - Exclude specific spec files
问:
我在 Angular 项目的某些规范文件中有错误,并希望将它们从编译中排除。
我把这些文件放在:exclude
tsconfig.spec.json
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
],
"exclude": [
"src/**/ms-dialog.spec.ts" // Should be excluded
]
}
但是当我执行时,出现以下错误:ng test
./src/app/core/models/ms-dialog.spec.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: /home/user/Documents/Projects/my-project/src/app/core/models/ms-dialog.spec.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
可能是我文件中的原因:tsconfig.base.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"useDefineForClassFields": true,
"module": "es2020",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2022",
"typeRoots": ["node_modules/@types"],
"types": ["node"],
"lib": ["es2018", "dom"],
"paths": {
"core-js/es7/reflect": [
"../node_modules/core-js/proposals/reflect-metadata"
],
"core-js/es6/*": ["../node_modules/core-js/es/*"],
"@env": ["./environments/environment"],
"@shared/*": ["./app/shared/*"],
"@core/*": ["./app/core/*"],
}
}
}
还有我的:test.ts
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false },
});
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
答: 暂无答案
评论
xdescribe
test.ts
<file> is missing from the TypeScript compilation
context.keys().filter(...filterlogic...).map(context)