我正在尝试在 github 管道上运行,并且添加了测试部分。所以所有测试都通过了,但它以这个错误结束
✔ Browser application bundle generation complete.
12 01 2024 08:38:12.950:INFO [karma-server]: Karma v6.4.2 server started at http://localhost:9876/
12 01 2024 08:38:12.952:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
12 01 2024 08:38:12.959:INFO [launcher]: Starting browser ChromeHeadless
12 01 2024 08:38:16.312:INFO [Chrome Headless 120.0.6099.199 (Linux x86_64)]: Connected on socket DWOuKXQLVla7uEp-AAAB with id 43272771
Chrome Headless 120.0.6099.199 (Linux x86_64): Executed 0 of 2 SUCCESS (0 secs / 0 secs)
Chrome Headless 120.0.6099.199 (Linux x86_64): Executed 1 of 2 SUCCESS (0 secs / 0.076 secs)
Chrome Headless 120.0.6099.199 (Linux x86_64): Executed 2 of 2 SUCCESS (0 secs / 0.088 secs)
Chrome Headless 120.0.6099.199 (Linux x86_64): Executed 2 of 2 SUCCESS (0.147 secs / 0.088 secs)
TOTAL: 2 SUCCESS
✔ Browser application bundle generation complete.
✔ Browser application bundle generation complete.
- Generating browser application bundles (phase: setup)...
✔ Browser application bundle generation complete.
12 01 2024 08:38:30.019:INFO [karma-server]: Karma v6.4.2 server started at http://localhost:9876/
12 01 2024 08:38:30.020:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
12 01 2024 08:38:30.023:INFO [launcher]: Starting browser ChromeHeadless
12 01 2024 08:38:30.260:INFO [Chrome Headless 120.0.6099.199 (Linux x86_64)]: Connected on socket ZG7l0ICZB34c5IMgAAAD with id 30559897
Chrome Headless 120.0.6099.199 (Linux x86_64): Executed 0 of 0 SUCCESS (0 secs / 0 secs)
Chrome Headless 120.0.6099.199 (Linux x86_64): Executed 0 of 0 SUCCESS (0.009 secs / 0 secs)
✔ Browser application bundle generation complete.
TOTAL: 0 SUCCESS
✔ Browser application bundle generation complete.
Error: Process completed with exit code 1.
我不确定这是什么意思以及为什么会发生这种情况,因为本地所有都正确通过
运行命令在这里:
"test:prod": "ng test --browsers=ChromeHeadless --no-watch",
karma.conf.js 文件内容在这里
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'**/*.spec.ts',
'*.spec.ts',
],
exclude: [],
preprocessors: {
'**/*.spec.ts': ['webpack'],
'*.spec.ts': ['webpack'],
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadless'],
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: ['--headless', '--disable-gpu', '--no-sandbox', '--remote-debugging-port=9222'],
},
},
singleRun: false,
concurrency: 2, // Adjust the concurrency level as needed
});
};
tsconfig.spec.json 内容在这里
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": ["jasmine", "@angular/localize"]
},
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}
随着这成为习惯,大多数情况下你需要自己寻找解决方案,这是同一个例子。
我自己找到了解决方案,所以如果有人遇到这个问题,解决方案就是。 查找任何其他 tsconfig.spec.json,在我的例子中,它位于我的项目中生成的库中,并且它也在 angular.json 中设置,因此出于这个原因,它为此文件执行了另一轮。
ChatGPT 在更多情况下是比这个论坛更好的帮手,这是遗憾。