Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在网站根目录配置karma代理时出现问题_Angular_Proxy_Jasmine_Karma Jasmine_Karma Runner - Fatal编程技术网

Angular 在网站根目录配置karma代理时出现问题

Angular 在网站根目录配置karma代理时出现问题,angular,proxy,jasmine,karma-jasmine,karma-runner,Angular,Proxy,Jasmine,Karma Jasmine,Karma Runner,我无法将karma配置为代理我网站根目录下的文件。我的一个angular组件包含一个嵌入式Ace编辑器,它在以下位置查找文件:http://localhost:9876/worker-html.js。我已经使用文件属性成功地在业力中服务了文件 // Makes ace files available in tests files: [ { pattern: "../node_modules/ace-builds/src-min-noconflict/worker-html.js&q

我无法将karma配置为代理我网站根目录下的文件。我的一个angular组件包含一个嵌入式Ace编辑器,它在以下位置查找文件:http://localhost:9876/worker-html.js。我已经使用文件属性成功地在业力中服务了文件

// 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 }
],
并验证它是否被提供(通过检查窗口。_ukarma__;,这并不总是在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-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的链接使我找到了正确的代理配置。我的问题有两个方面:我不理解代理对象的各个部分,而且我复制的链接有一个错误(经典)。以下是工作配置文件的相关部分,供可能需要帮助的人参考:

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"
  }
},


也许这对你有帮助。谢谢你,约翰!你的医生带我去的。我将发布一个更正式的问题答案,以供参考