gpt4 book ai didi

angular - ng test 要求我在运行任何单元测试之前修复所有 linting

转载 作者:行者123 更新时间:2023-12-03 16:50:22 25 4
gpt4 key购买 nike

我的 ng test 的输出如下:

> ng test

24 12 2019 14:20:07.854:WARN [karma]: No captured browser, open http://localhost:9876/
24 12 2019 14:20:07.860:INFO [karma-server]: Karma v4.4.1 server started at http://0.0.0.0:9876/
24 12 2019 14:20:07.860:INFO [launcher]: Launching browsers ChromeNoSandbox with concurrency unlimited
24 12 2019 14:20:07.865:INFO [launcher]: Starting browser ChromeHeadless

app/shared/forms/templates/templates.component.ts:11:1 - error TS6133: 'MatDialog' is declared but its value is never read.

11 import { MatDialog } from '@angular/material';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 12 2019 14:20:11.633:INFO [HeadlessChrome 79.0.3945 (Mac OS X 10.15.2)]: Connected on socket 9OfTSV7nahQakrDOAAAA with id 85821004
HeadlessChrome 79.0.3945 (Mac OS X 10.15.2): Executed 0 of 0 SUCCESS (0 secs / 0 secs)
HeadlessChrome 79.0.3945 (Mac OS X 10.15.2): Executed 0 of 0 SUCCESS (0.002 secs / 0 secs)
TOTAL: 0 SUCCESS
TOTAL: 0 SUCCESS

我遇到的问题是,如果我有 任何 如果我的 src 代码中出现 linting 错误,那么单元测试将无法运行,当我只想在这里和那里尝试进行测试驱动开发时,这非常不方便。我宁愿只收到这些 linting 错误的警告,我可以一次性修复它们。

我使用的是 Angular 版本, "@angular/core": "8.1.2"和 karma 版本:
"karma": "4.4.1",
"karma-chrome-launcher": "3.1.0",
"karma-cli": "2.0.0",
"karma-coverage-istanbul-reporter": "2.1.1",
"karma-jasmine": "2.0.1",
"karma-jasmine-html-reporter": "1.4.2",
"karma-junit-reporter": "2.0.1",
"karma-verbose-reporter": "0.0.6",

在 Angular 7 上,我没有遇到任何问题,无论 linting 错误如何,我的单元测试都会执行。我不确定发生了什么变化或我应该检查哪些配置以阻止这种情况发生。

最终目标是让单元测试能够运行,而不管 linting 错误的频率如何。
angular.json包含测试配置:
    "test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"karmaConfig": "./karma.conf.js",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
...etc...

karma.conf
// 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: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-junit-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
require('karma-verbose-reporter')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},

reporters: config.angularCli && config.angularCli.codeCoverage ? ['progress', 'coverage-istanbul', 'junit'] : ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeNoSandbox'],
singleRun: false,
junitReporter: {
outputDir: process.env.JUNIT_REPORT_PATH,
outputFile: process.env.JUNIT_REPORT_NAME,
useBrowserName: false
},
customLaunchers: {
ChromeNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
}
});
};

最佳答案

这是 TypeScript 错误,意思是 noUnusedLocals设置为 truetsconfig.spec.json .

我认为您可以创建继承的配置,即 tsconfig.spec.dev.json (使用“扩展”:“./tsconfig.spec.json”)并覆盖 noUnusedLocals值与 false .那么你需要添加configurations部分:

    "test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.dev.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"tsConfig": "tsconfig.spec.json"
}
}
}

现在您可以将 dev 运行为 ng test或生产为 ng test --prod .

关于angular - ng test 要求我在运行任何单元测试之前修复所有 linting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59470300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com