Karma为图像提供404(AureliaJS)

时间:2017-07-13 12:15:10

标签: karma-runner karma-jasmine aurelia aurelia-cli aurelia-framework

使用Aurelia CLI我使用au test运行单元测试。 Karma记录到控制台(多次请求一遍又一遍):

WARN [web-server]: 404: /src/assets/images/avatar-backup.png

我知道包含我的图像文件并不是必需的,我可以更改日志级别以忽略这些警告,但这似乎应该是一个非问题。如果没有别的,我想知道为什么如何来解决这个问题。

我尝试了herehere(以及其他地方)找到的不同方法的组合,但我仍然无法弄清楚我做错了什么。我对Karma和Aurelia还有点新鲜,所以也许我错过了一些基本的理解......我不知道。

目前我的这是我的karma.conf.js

'use strict';
const path = require('path');
const project = require('./aurelia_project/aurelia.json');
const tsconfig = require('./tsconfig.json');

let testSrc = [
  { pattern: project.unitTestRunner.source, included: false },
  'test/aurelia-karma.js'
];

let output = project.platform.output;
let appSrc = project.build.bundles.map(x => path.join(output, x.name));
let entryIndex = appSrc.indexOf(path.join(output, project.build.loader.configTarget));
let entryBundle = appSrc.splice(entryIndex, 1)[0];

// Added the image file sources
let imgFiles = [
  {pattern: 'src/assets/images/*', watched: false, included: false, served: true, nocache: false},

  // Added an exact path in case my pattern was somehow wrong, still doesn't load 
  {pattern: 'src/assets/images/avatar-backup.png', watched: false, included: false, served: true, nocache: false}
  ];

// Concat imgFiles to file array
let files = [entryBundle].concat(imgFiles).concat(testSrc).concat(appSrc);

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: [project.testFramework.id],
    files: files,
    exclude: [],
    preprocessors: {
      [project.unitTestRunner.source]: [project.transpiler.id]
    },
    typescriptPreprocessor: {
      typescript: require('typescript'),
      options: tsconfig.compilerOptions
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    // client.args must be a array of string.
    // Leave 'aurelia-root', projectName.paths.root in this order so we can find
    // the root of the aurelia projectName.
    client: {
      args: ['aurelia-root', project.paths.root]
    },
    browserConsoleLogOptions: {
      terminal: true,
      level: ""
    },

    // Not sure how to use proxy in combination with my added file sources or if I even need to...
    // proxies: {
    //   "/img/": "http://localhost:9876/base/src/assets/images/"
    // },
  });
};

我的应用文件结构如下:

app
  - src
    - assets
      - images
        - (..images)
  - test
    - unit
      - (..tests)

0 个答案:

没有答案