【发布时间】:2020-10-06 21:26:53
【问题描述】:
我无法将 karma 配置为代理网站根目录中的文件。我的 Angular 组件之一包含一个嵌入式 Ace 编辑器,它在 http://localhost:9876/worker-html.js 中查找文件。我已经使用 files 属性成功地在 Karma 中提供了文件
// Makes ace files available in tests
files: [
{ pattern: "../node_modules/ace-builds/src-min-noconflict/worker-html.js", watched: false, included:false, nocache:false, served:true }
],
并验证它是否已提供服务(通过检查 window.__karma__,它并不总是在 karma 浏览器窗口中定义,我不知道为什么,但这是一个单独的问题)。我还验证了我可以在这个路径访问所需的文件:
http://localhost:9876/absoluteD:/Evan/programming%20stuff/Projects/Gneus/node_modules/ace-builds/src-min-noconflict/worker-html.js
但是,我终其一生都无法将其代理到所需的 URL (http://localhost:9876/worker-html.js)。我已经尝试了所有我能想到的合理代理配置,所以我认为我缺少一些基本的东西。有人可以帮我吗?这是整个 karma 配置文件供参考,包括我最近的代理尝试:
// 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-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
// Don't run tests in random order
// If you update this, you have to restart ng test batch
jasmine: {
random: false
}
},
// Makes ace files available in tests
files: [
{ pattern: "../node_modules/ace-builds/src-min-noconflict/worker-html.js", watched: false, included:false, nocache:false, served:true }
],
proxies: {
'/worker-html.js': "http://localhost:9876/absoluteD:/Evan/programming stuff/Gneus/node_modules/ace-builds/src-min-noconflict/worker-html.js"
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
});
};
【问题讨论】:
-
谢谢约翰!你的医生让我去那里。我将对该问题发布更正式的答案以供参考
标签: angular proxy jasmine karma-jasmine karma-runner