Angular 15升级至17后单元测试无法检测的问题求助
Angular 17升级后单元测试无法检测且出现node模块处理错误
多方查找未找到可靠解决方案,特发布此问题求助。在Angular 15中运行一切正常,但升级至Angular 17后,单元测试完全无法被检测,执行结果显示Executed 0 of 0 SUCCESS。在此提示前,还收到以下错误信息,二者可能相关:
node:fs/promises - Error: Module build failed: UnhandledSchemeError: Reading from "node:fs/promises" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "node:" URIs. node:fs - Error: Module build failed: UnhandledSchemeError: Reading from "node:fs" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "node:" URIs. node:path - Error: Module build failed: UnhandledSchemeError: Reading from "node:path" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "node:" URIs. node:url - Error: Module build failed: UnhandledSchemeError: Reading from "node:url" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "node:" URIs.
已创建独立的Angular 17新项目对比配置,未发现明显差异,且测试用例在新项目中可正常检测,说明用例本身无问题。现附上相关配置代码,若需更多信息请告知。
karma.conf.js
// Karma configuration file, see link for more information // https://karma-runner.github.io/1.0/config/configuration-file.html module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine', '@angular-devkit/build-angular'], plugins: [ 'karma-jasmine', 'karma-chrome-launcher', 'karma-jasmine-html-reporter', 'karma-coverage', 'karma-junit-reporter', '@angular-devkit/build-angular/plugins/karma' ], client: { clearContext: false // leave Jasmine Spec Runner output visible in browser }, coverageReporter: { dir: require('path').join(__dirname, './coverage'), type: 'lcov', subdir: '.', reports: ['html', 'lcovonly', 'text-summary'], fixWebpackSourcePaths: true, check: { global: { statements: 80, branches: 80, functions: 80, lines: 80 } } }, reporters: ['progress', 'junit', 'kjhtml','coverage'], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, customLaunchers: { ChromeHeadlessNoSandbox: { base: 'ChromiumHeadless', flags: ['--no-sandbox'] } }, junitReporter : { outputDir : './junit/test-reports' }, browsers: ['Chrome'], singleRun: false, restartOnFileChange: true }); };
angular.json中的"test"配置段
"test": { "builder": "@angular-devkit/build-angular:karma", "options": { "polyfills": ["zone.js", "zone.js/testing"], "tsConfig": "tsconfig.spec.json", "karmaConfig": "karma.conf.js", "codeCoverage": true, "assets": [ "src/favicon.ico", "src/assets", "src/manifest.webmanifest" ], "styles": [ "src/styles.scss", "src/styles/spartacus/storefinder.scss", "src/styles/spartacus/user.scss", "src/styles/spartacus/qualtrics-embedded-feedback.scss", "src/styles/spartacus/product.scss", "src/styles/spartacus/pdf-invoices.scss" ], "scripts": [] } },
内容的提问来源于stack exchange,提问作者Terry Windwalker
相关产品推荐
相关产品推荐

