1

Using the Aurelia CLI I run my unit tests with au test. Karma logs to console (over and over again for multiple requests):

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

I understand that including my image files with tests isn't necessary and I could change the log levels to ignore these warnings, but this seems like it should really be a non issue. If for nothing else I want to know why and how to fix this for my own curiosity.

I've tried a combination of different methods found here and here (and elsewhere), but I still cannot figure out what I'm doing wrong. I'm still somewhat new to Karma and Aurelia so maybe I'm missing some fundamental understanding... I don't know.

Currently my this is my 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/"
    // },
  });
};

My app file structure looks like:

app
  - src
    - assets
      - images
        - (..images)
  - test
    - unit
      - (..tests)
DjH
  • 1,448
  • 2
  • 22
  • 41
  • Did you ever find a solution for this? I've been down your exact path and I'm still getting the warnings. – Capo Dec 26 '17 at 20:20
  • 1
    @Capo I did not. I believe I ended up just configuring log levels to ignore the warnings. Sorry :( – DjH Dec 26 '17 at 22:24
  • thanks for the response. I was able to suppress mine using: proxies: { "/assets/": "/assets/" }, – Capo Dec 27 '17 at 23:08

0 Answers0