将 Angular 从 v14 更新到 v15 后,我看到 Angular CLI 从 src/test.ts 文件中删除了行。这些行是:
declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
<T>(id: string): T;
keys(): string[];
};
};
Run Code Online (Sandbox Code Playgroud)
和
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().forEach(context);
Run Code Online (Sandbox Code Playgroud)
这当然导致“npm run test”命令在本地失败,因为测试文件没有明确提供给 Angular。所以我将线路添加回来,一切都开始在本地工作。CI/CD 机器无法再运行“npm run test”命令。该命令将以下内容打印到标准输出:
29 11 2022 13:00:59.161:INFO [karma-server]: Karma v6.3.20 server started at http://localhost:9876/
29 11 2022 13:00:59.167:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
29 …Run Code Online (Sandbox Code Playgroud)