Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

karma fails with "An error was thrown in afterAll \n Error: Can't find ./index" #3794

Closed
chickencoding123 opened this issue May 13, 2022 · 1 comment

Comments

@chickencoding123
Copy link

chickencoding123 commented May 13, 2022

A simple out-of-box karma setup fails to run. I've made a sample repo to reproduce this issue here. All details such as error message are also included in the repo. To run the repo, clone it and run npm run test to see the error. Ideas are welcomed on how to fix this.

ERROR

  An error was thrown in afterAll
  Error: Can't find ./index [<repo-clone-path>/index.ts] (required by <repo-clone-path>/index.test.ts)
  require@node_modules/karma-typescript/dist/client/commonjs.js:13:23
  require/<@node_modules/karma-typescript/dist/client/commonjs.js:18:24
  global.wrappers["<repo-clone-path>/index.test.ts"]<@index.test.ts:1:1 <- index.test.js:39:22
  require@node_modules/karma-typescript/dist/client/commonjs.js:17:25
  @node_modules/karma-typescript/dist/client/commonjs.js:38:16
  @node_modules/karma-typescript/dist/client/commonjs.js:37:40
  @node_modules/karma-typescript/dist/client/commonjs.js:40:3

karma.conf.js

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

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


    // frameworks to use
    // available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
    frameworks: ['jasmine', 'karma-typescript'],


    // list of files / patterns to load in the browser
    files: [
      "*.test.ts"
    ],


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


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor
    preprocessors: {
      "*.ts": "karma-typescript"
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://www.npmjs.com/search?q=keywords: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://www.npmjs.com/search?q=keywords:karma-launcher
    browsers: ['Firefox'],


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

    // Concurrency level
    // how many browser instances should be started simultaneously
    concurrency: Infinity
  })
}

Environment

  • OS: Ubuntu
  • Browser: Firefox 100
  • IDE: Visual Studio Code
@devoto13
Copy link
Collaborator

devoto13 commented May 13, 2022

@chickencoding123 Karma is not capable of analyzing the imports graph to determine all files which need to be served or loaded - they need to be listed explicitly. So that's why you get an error: transpiled index.ts is not served by Karma dev-server and not loaded by the test page. The solution is to change files: ["*.test.ts"] to files: ["*.ts"] to ensure that index.ts is correctly included.

See #2966 and #3335 for discussions about this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants