question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Karma test run fails frequently with 404s for bundled script files

See original GitHub issue

I’m submitting a bug report

  • Library Version: aurelia-cli@0.30.1 karma@1.7.0 karma-chrome-launcher@2.2.0 karma-cli@1.0.1 karma-jasmine@1.1.0 karma-typescript-preprocessor@0.3.1

  • Operating System: Windows 10

  • Node Version: 6.10.1

  • NPM Version: 3.10.10

  • Browser: Chrome 60

  • Language: TypeScript 2.2.2

Current behavior: We are experiencing major stability issues with the Karma web server when running tests using au test --watch.

Sometimes the tests run correctly for a test run, but very often the task fails with a whole slew of 404 warnings for bundled files, such as the following:

28 07 2017 12:22:01.601:INFO [launcher]: Launching browser Chrome with unlimited concurrency
28 07 2017 12:22:01.613:INFO [launcher]: Starting browser Chrome
28 07 2017 12:22:03.266:INFO [Chrome 60.0.3112 (Windows 10 0.0.0)]: Connected on socket VRL8rnxw6pOi57IrAAAA with id 187727
28 07 2017 12:22:03.676:WARN [web-server]: 404: /base/src/app.js
28 07 2017 12:22:03.678:WARN [web-server]: 404: /base/src/services/security/SecurityService.js
28 07 2017 12:22:03.678:WARN [web-server]: 404: /base/src/services/resources/ResourceService.js
28 07 2017 12:22:03.679:WARN [web-server]: 404: /base/src/model/EventNames.js
28 07 2017 12:22:03.679:WARN [web-server]: 404: /base/src/navigation/AuthorizeStep.js
28 07 2017 12:22:03.682:WARN [web-server]: 404: /base/src/model/observers/EntityGraphObserver.js
28 07 2017 12:22:03.683:WARN [web-server]: 404: /base/src/model/common-data/BankAccount.js
28 07 2017 12:22:03.684:WARN [web-server]: 404: /base/src/model/ObjectState.js
28 07 2017 12:22:03.684:WARN [web-server]: 404: /base/src/model/common-data/Address.js
Chrome 60.0.3112 (Windows 10 0.0.0) ERROR
  Uncaught Error: Script error for "src/app"
  http://requirejs.org/docs/errors.html#scripterror
  at wwwroot/scripts/vendor-bundle.js:4389

The exact files that result in 404s varies a lot as well, but they are always coming from app-bundle.js. The tests may run successfully to begin with, but if the underlying app code is touched then the next test run often breaks. Basically, it’s flaky as hell - on some of our developers’ boxes, they can barely get past this issue at all, so our developer workflow is broken in this area.

Here is our Karma configuration (very close to the base CLI file):

"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",
    "node_modules/jasmine-jquery/lib/jasmine-jquery.js",
    { pattern: "test/locales/*.json", watched: true, served: true, included: false },
    { pattern: "wwwroot/img/**/*", watched: false, served: true, included: false }  
];

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];
let files = [entryBundle].concat(testSrc).concat(appSrc);

module.exports = function (config) {
    config.set({
        basePath: "",
        frameworks: [project.testFramework.id],
        files: files,
        proxies: {
            "/img/": "/base/wwwroot/img/"
        },
        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', project.paths.root in this order so we can find
        // the root of the aurelia project.
        client: {
            args: ["aurelia-root", project.paths.root]
        }
    });
};

We haven’t made any changes to /test/aurelia-karma.js, or to the au test task, they are identical to current CLI versions for 0.30.1.

We really need some help in this area.

Expected/desired behavior: Running tests should be stable for the Karma configuration, and never result in intermittent 404s to files that are bundled and loaded using RequireJS.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:23 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
JeroenVinkecommented, Aug 6, 2017

I may have a lead. When I delay execution of the test files it seems to resolve the issue. Try and replace this line in aurelia-karma.js with setTimeout(() => require(allTestFiles, window.__karma__.start), 2000).

If you can confirm that this helps I can look for a more decent solution. Let me know

1reaction
JeroenVinkecommented, Aug 2, 2017

Thanks @sam-piper and @WizzApp. I’ve looked at this issue and found that if I use a minimal scss file (like one scss file with body { background-color: red}) I don’t get this issue. It might not be related to SASS, but instead it might have to do with the size of the app-bundle. Weird thing is that when I refresh Karma in the browser the tests run again. I haven’t been able to get to the bottom of it yet, hopefully I can tell more in the next couple of days

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to fix 404 warnings for images during karma unit testing
In your karma.conf.js file you should already have defined files and/or patterns like : // list of files / patterns to load in...
Read more >
Karma | RubyMine Documentation - JetBrains
Karma tests are run according to a karma.conf.js configuration file which is generated in the interactive mode.
Read more >
Why Do I Get A 404 Message From Karma Webserver?
Karma test run fails frequently with 404s for bundled script files #685 with a whole That way they'll be a step closer to...
Read more >
Continuous Integration, Delivery, and Deployment
Checking file sizes. Linting with JSHint. Running your Karma tests. Getting our site production ready. Minifying HTML. Minifying CSS. Bundling JavaScript ...
Read more >
angular/angular-cli - Gitter
Hi, I have a problem with ViewEncapsulation while using cli, any one heard ... to karma.config.js but nothing seems to change the output....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found