【发布时间】:2020-01-13 12:22:42
【问题描述】:
我有使用 Karma 和 Jasmine 运行的 Angular 前端测试,我想使用 Visual Studio Code 进行调试。测试在 puppeteer 实例中运行。
- 当调试器尝试连接时,它会超时,并告诉我套接字已挂起。
- 当我访问我的 puppeteer 实例正在监听的 http://localhost:9333/ 时,我得到一个
ERR_EMPTY_RESPONSE。 - 将调试器连接到以
chrome --headless --remote-debugging-port=9333开头的无头 Chrome 实例可以正常工作。
我的 karma.conf.js:
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-spec-reporter'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
mime: {
'text/x-typescript': ['ts', 'tsx'],
},
coverageIstanbulReporter: {
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true,
},
angularCli: {
environment: 'dev',
},
reporters:
config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
debug: true,
flags: ['--no-sandbox', '--remote-debugging-port=9333'],
},
},
browserNoActivityTimeout: 120000,
singleRun: false,
});
};
我的launch.json的相关部分:
{
"type": "chrome",
"request": "attach",
"name": "Debug Frontend Tests",
"address": "localhost",
"port": 9333,
"sourceMaps": true,
"webRoot": "${workspaceFolder}/client/web",
}
【问题讨论】:
标签: google-chrome visual-studio-code karma-jasmine karma-runner puppeteer