小编kan*_* op的帖子

Angular v15 npm 运行测试在 CI/CD 机器中失败,并出现错误“Uncaught TypeError: __webpack_require__(...).context is not a function”

将 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)

testing angular cicd angular15

5
推荐指数
1
解决办法
2746
查看次数

标签 统计

angular ×1

angular15 ×1

cicd ×1

testing ×1