karma-runner / karma-runner/karma

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

Open
#1,727 7 comments 3 reactions 0 assignees View on GitHub
type: feature
Dominant language
JavaScript
Stars
12k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

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. (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`:

``` TypeScript
// 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`

Contributor guide

Open the contributing guide

Research direction

Start with the CLI entry points in karma/lib/cli.js and karma/bin/karma, then inspect config loading in karma/lib/config.js, especially parseConfig. Compare the explicit karma.conf.ts path and no-path invocation with the gulp example. Done means the CLI accepts and discovers the TypeScript configuration without the reported syntax or missing-adapter behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
cli, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.