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.

Allow for karma.conf.ts (TypeScript) when using cli

See original GitHub issue

When running node_modules/.bin/karma start karma.conf.ts (1) (written in TypeScript) I get:

ERROR [config]: Invalid config file!
  SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.parseConfig (node_modules/karma/lib/config.js:276:22)
    at new Server (node_modules/karma/lib/server.js:56:20)
    at Object.exports.run (node_modules/karma/lib/cli.js:231:7)
    at Object.<anonymous> (node_modules/karma/bin/karma:3:23)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)

Also it does not seem to automatically detect karma.conf.ts when running node_modules/.bin/karma start:

[karma]: No captured browser, open http://localhost:9876/
INFO [karma]: Karma v0.13.15 server started at http://localhost:9876/
INFO [Chrome]: Connected on socket 9S-HxtcaP6-xFCRfAAAA with id manual-8425
Chrome ERROR
  You need to include some adapter that implements __karma__.start method!

On the other hand when running the task using gulp and the same karma.conf.ts:

// File gulpfile.ts (written in TypeScript)
import * as gulp from 'gulp';
import * as karma from 'karma';

function runKarma(done): void {
  const config = {
    configFile: __dirname + '/karma.conf.ts'
  };

  const server = new karma.Server(config, done);
  server.start();
}

gulp.task('test', done => runKarma(done));

Everything works as expected so I suspect code specific to the cli to not support TypeScript.

(1) or $(npm bin)/karma start karma.conf.ts

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
aj-rcommented, Jun 20, 2018

This works for me using TypeScript 2:

npm install -D typescript ts-node karma @types/karma

In package.json:

{
  "scripts": {
    "test": "ts-node node_modules/karma/bin/karma start karma.conf.ts",
  },
}

Also don’t forget to add this to your karma config file:

    mime: {
      "text/x-typescript": ["ts", "tsx"],
    },

Then run npm test

1reaction
caseyhowardcommented, Jul 11, 2016

Even with this merged (https://github.com/karma-runner/karma/pull/2224) I still can’t figure out how to use ES6 modules. Is this supported. I get the following error:

11 07 2016 11:23:38.903:ERROR [config]: Invalid config file!
  SyntaxError: Unexpected reserved word
Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration File - Karma
The easiest way to generate an initial configuration file is by using the karma init command. This page lists all of the available...
Read more >
Karma Config - JavaScript Dev Tools
Karma Config will auto-detect most CI environments. This option can also be enabled by setting the CI or KARMA_CI environment variables.
Read more >
Unable to load *.vue files using karma and karma-typescript
I was able to produce a webpack.config.js using "vue inspect" and created a webpack.config.js file locally within the root of the project. karma...
Read more >
Karma Configuration - Rangle.io : Angular Training
Karma is the foundation of our testing workflow. It brings together our other testing tools to define the framework we want to use,...
Read more >
karma-typescript - npm
Simplifying running unit tests with coverage for Typescript projects.. Latest version: 5.5.3, last published: a year ago.
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