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 seems to disregard .ts files #3066

Closed
m90 opened this issue Jun 27, 2018 · 4 comments
Closed

Karma seems to disregard .ts files #3066

m90 opened this issue Jun 27, 2018 · 4 comments

Comments

@m90
Copy link

m90 commented Jun 27, 2018

Expected behaviour

I am trying to run a testsuite that is composed of TypeScript and JavaScript files. They are all named following a *.test.* pattern (i.e. foo.test.js and bar.test.ts). I would expect Karma to run all matching files.

TypeScript is being handled using karma-browserify and the tsify plugin.

Actual behaviour

Instead, only files ending with .js are being run. Compilation of TypeScript sources works correctly though as .js-tests are able to consume the sources.

Environment Details

  • Karma version (output of karma --version):
Karma version: 2.0.4
===
"karma-browserify": "^5.3.0",
"karma-mocha": "^1.3.0",
  • Relevant part of your karma.config.js file
frameworks: ['mocha', 'browserify'],
browserify: {
  plugin: ['tsify']
},
files: [
  { pattern: 'testdata/**/*.*', included: false },
  'lib/**/*.test.*'
],
exclude: [
],
preprocessors: {
  'lib/**/*.*': ['browserify']
}

Steps to reproduce the behaviour

  1. Create a Karma config using karma-browserify and the tsify plugin
  2. Create tests using a .ts suffix
  3. See no tests being run

This issue over at karma-browserify makes me think the overall approach is viable. I don't know if this is a regression since then or if I am doing something wrong.

@johnjbarton
Copy link
Contributor

karma-runner is a nodejs process that runs plugins based on your config, starts a server, launches a browser, and directs the browser to the server. None of these steps work with TypeScript. Therefore literally "karma seems to disregard .ts files" is working as designed: .ts files don't work in this system.

Various plugins and tools that run before karma can transform .ts files to .js files allowing TypeScript to be used for tests, code under test, config and plugins. So your problem has to be either in your config or in one of the plugins or tools you use.

Run your code with --log-level debug or config.logLevel=config.LOG_DEBUG. Look through the result to see what actions karma applies -- or doesn't apply -- to .ts file types.

@m90
Copy link
Author

m90 commented Jun 28, 2018

The idea behind the used setup that the transpiling happens artifact-free, i.e. without any .js files being created. In the mentioned setup I could require(./thing') and it would pick up thing.ts and transpile it on the fly.

Does this mean if I wanted to use Karma in this context I'd need a transpilation step that creates .js-artifacts in order to be tested?

@johnjbarton
Copy link
Contributor

No, I am saying that what ever your issue is, karma-runner source code can't fix it. Your issue is very unlikely to be resolved here. By running with the debug settings and studying the output you can track down your issue. It is mostly likely a configuration setting relating to one of the plugins.

@m90 m90 closed this as completed Jun 28, 2018
@paddotk
Copy link

paddotk commented Jun 29, 2022

I have the exact opposite, only .ts files are run but not .js files.

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

3 participants