karma serving cached content that is set for nocache

Discussão em 'Angular' iniciado por Kenneth Carter, Março 10, 2025.

  1. in the karma.conf.js I have the following configuration:

    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')
    ],
    files: [
    { pattern: 'src/workers/**/*.worker', type: 'js', watched: true, included: false, nocache: true, served: true }
    ],
    proxies: {
    '/workers/': '/base/src/workers/'
    }, ... });


    I have a typescript library that is a web worker that compiles with ES2022 and WebWorker. I have another library that contains the consuming service that interacts with the worker.

    I have an injection token in this library that is used in the spec test for the service.

    {
    provide: ProxyWorkerToken,
    useFactory: () => {
    const url = new URL('http://localhost:9876/workers/identity.worker.js');
    if (url) {
    return new Worker(url, {
    name: 'identity.worker',
    type: 'module'
    });
    }
    throw new Error(`url is undefined, node_module path to worker could not be resolved.`);
    }
    }


    karma serves this file which initially contained the following export.

    export * from './subsonic-core-identity.worker';


    the file identity.worker.js was served, but the script loading process did not match to mjs that the transpile created when the identity.worker library was packaged and deployed.

    I have since updated the file to the following contents:

    export * from './subsonic-core-identity.worker.mjs';


    the karma dev server is serving the old file with out the .mjs. I have cleared the browser cache, I have made sure the pattern was set to nocache: true, I have restarted my computer and I deleted all cached data that is linked with chrome. I am unable to clear the karma cache holding onto the first instance of this file. I have loaded the mjs directly and the worker background thread is created just fine.

    just so you know how the folder location is set in the test run I will share the angular.json that makes up the project definition for the identity library.

    "@subsonic-core/identity": {
    "projectType": "library",
    "root": "projects/subsonic-core/identity",
    "sourceRoot": "projects/subsonic-core/identity/src",
    "prefix": "lib",
    "architect": {
    "build": {
    "builder": "@angular-devkit/build-angular:ng-packagr",
    "options": {
    "project": "projects/subsonic-core/identity/ng-package.json"
    },
    "configurations": {
    "production": {
    "tsConfig": "projects/subsonic-core/identity/tsconfig.lib.prod.json"
    },
    "development": {
    "tsConfig": "projects/subsonic-core/identity/tsconfig.lib.json"
    }
    },
    "defaultConfiguration": "production"
    },
    "test": {
    "builder": "@angular-devkit/build-angular:karma",
    "options": {
    "tsConfig": "projects/subsonic-core/identity/tsconfig.spec.json",
    "assets": [
    {
    "glob": "**/*",
    "input": "./node_modules/@subsonic-core/identity.worker/fesm2022",
    "output": "./workers"
    }
    ],
    "polyfills": [
    "zone.js",
    "zone.js/testing"
    ],
    "scripts": []
    }
    }
    }
    }

    Continue reading...

Compartilhe esta Página