Karma tests with typescript: Could not find requested file

273 views Asked by At

I'm adding integration tests with Karma to a React project, and I have a pile of Mocha tests with Chai written in TypeScript which use ES6 module imports. Hoping that everything works together, I've added karma-typescript, karma-sourcemap-loader and @open-wc/karma-esm to transpile the typescript tests.

To run those tests with Karma I've initialized the following project with karma init my.conf.js:

// Karma configuration
// Generated on Tue Sep 22 2020 23:59:00 GMT+0200 (Central European Summer Time)

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',

    plugins: [
      require.resolve('@open-wc/karma-esm'),
      'karma-*'
    ],

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: [
      'mocha',
      'chai',
      'karma-typescript',
      'esm'
    ],


    // list of files / patterns to load in the browser
    files: [
      'test/global.ts',
      {pattern: 'test/**/*.karma.ts', module: true}
    ],


    // list of files / patterns to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      'test/**/*.ts': ['karma-typescript', 'sourcemap']
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity,

    karmaTypescriptConfig: {
      bundlerOptions: {
        sourceMap: true
      },
      compilerOptions: {
        emitDecoratorMetadata: true,
        experimentalDecorators: true,
        allowSyntheticDefaultImports: true,
        jsx: "react",
        module: "es6",
        moduleResolution: "node",
        sourceMap: true,
        target: "ES5"
      },
      exclude: ["node_modules"]
    }
  })
}

However, when I run these tests with $ npx karma start --log-level debug --no-single-run my.conf.js I get the following error:

(...)
[karma-esm]: Could not find requested file: /test/sometest.karma.js?7f18cbf56f32714fa3b45bed3920cbf0123c0f13
(...)
TOTAL: 0 SUCCESS

Does anyone know why is the test failing?

0

There are 0 answers