在网站根目录配置 karma 代理时遇到问题

Trouble configuring karma proxy at website root

我无法配置 karma 来代理我网站根目录下的文件。我的 angular 组件之一包含一个嵌入式 Ace 编辑器,它在 http://localhost:9876/worker-html.js 查找文件。我已使用 属性

文件在 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__,这并不总是在业力浏览器 window 中定义,我不知道为什么,但这是一个单独的问题)。我还验证了我可以在这个路径访问所需的文件:

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,

    
  });
};

John 在上面的评论中的 link (dev.to/jwp/angular-karma-proxy-configuration-1kbb) 使我找到了正确的代理配置。我的问题是two-fold:我没看懂代理对象的各个部分,我复制的link有一个错误(经典)。以下是工作配置文件的相关部分,可能对任何人有帮助:

basePath: '',
...

// 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": { 
    "target": "http://localhost:9876/absoluteD:/Evan/programming stuff/Projects/Gneus/node_modules/ace-builds/src-min-noconflict/worker-html.js"
  }
},