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

TypeError: Cannot read property 'startsWith' of undefined at Coverage.hasNoOutput #341

Open
alireza-salemian opened this issue Jun 26, 2019 · 11 comments

Comments

@alireza-salemian
Copy link

alireza-salemian commented Jun 26, 2019

Hi
I get 'TypeError: Cannot read property 'startsWith' of undefined at Coverage.hasNoOutput' after run karma test.
a complete log attached for more details.
log.txt

@simonvizzini
Copy link

I have the same issue. Have you found a solution or workaround yet?

@simonvizzini
Copy link

I got rid of this error by setting instrumentation to false:

karmaTypescriptConfig: {
  tsconfig: "./tsconfig.json",
  coverageOptions: {
    instrumentation: false
  }
}

But no tests execute, Chrome opens an empty page, with just a green header: Karma v4.4.1 - connected. The CLI outputs the following:

Chrome 78.0.3904 (Linux 0.0.0): Executed 0 of 0 SUCCESS (0.001 secs / 0 secs)

I tried to add the mime option to my karma.conf.js file as suggested in a couple StackOverflow answers:

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

but no luck.

@vidartf
Copy link
Contributor

vidartf commented Jul 24, 2020

I also have this problem. An initial investigation by stepping through the code reveals that this occurs when the typescript compile-host for some reason do not call the writeFile callback for any of the files. The compilation is otherwise marked as a success ("Compiled 164 files in X ms`). I'll keep investigating to see if I can figure out what causes this to happen.

@vidartf
Copy link
Contributor

vidartf commented Jul 24, 2020

Hm. For me it got fixed by setting noEmitOnError: false, even though I don't get any errors reported. Note that I do need to use skipLibCheck: true in my project in order to avoid some upstream typing issues (no idea if related), but I am still normally able to emit code when this flag is set.

Hopefully this can help someone else either work around the issue, or figure out the root problem :)

@tva-TIS
Copy link

tva-TIS commented Oct 23, 2020

Do you have any exlusions set within coverageOptions? I get the error too, but only if I use the exlude option.

@tva-TIS
Copy link

tva-TIS commented Oct 23, 2020

So I just realized I forgot to exclude the d.ts files. This would explain why the outputText is undefined (d.ts files dont result in any js being compiled), so I guess that you are feeding empty files to istanbul too.

@guoyunhe
Copy link

I have the same error. Hope someone can fix it.

@cefn
Copy link

cefn commented Jul 3, 2021

Has karma-typescript been broken in this way for 2 years without any resolution?

I hit the same dead end after starting up a brand new repo with just one React component and trying to follow the basics of using karma-jasmine karma-typescript jasmine-enzyme and battled with it for hours in various ways - never functioned to load and run my single React component test and was always running 0 of 0 tests.

As a workaround I started with https://github.com/medington/jasmine-enzyme-ts (thanks @medington) which was a proof-of-concept repro of a working Jasmine+Enzyme+Karma test suite. Unfortunately things have moved on since then and it doesn't work out of the box - unpinned packages at their latest versions break it.

However, I fixed it up so that the Enzyme tests pass by updating it to all the latest packages, and tweaking here and there. You can see the changes at cefn/jasmine-enzyme-ts@9003027

At the time of writing the repo at https://github.com/cefn/jasmine-enzyme-ts now runs two Enzyme tests written in Typescript correctly using Jasmine tests in a Chrome Karma instance without hitting the errors described in this issue. It uses a webpack configuration to transform the typescript rather than the prior approach I attempted based on karma-typescript which was broken.

For CI and hopefully later reproduction for others I have committed pnpm-lock.yaml so installing the project with pnpm install --frozen-lockfile shouldn't be susceptible to packages which update and break it.

@timvahlbrock
Copy link

Has karma-typescript been broken in this way for 2 years without any resolution?

I hit the same dead end after starting up a brand new repo with just one React component and trying to follow the basics of using karma-jasmine karma-typescript jasmine-enzyme and battled with it for hours in various ways - never functioned to load and run my single React component test and was always running 0 of 0 tests.

As a workaround I started with https://github.com/medington/jasmine-enzyme-ts (thanks @medington) which was a proof-of-concept repro of a working Jasmine+Enzyme+Karma test suite. Unfortunately things have moved on since then and it doesn't work out of the box - unpinned packages at their latest versions break it.

However, I fixed it up so that the Enzyme tests pass by updating it to all the latest packages, and tweaking here and there. You can see the changes at cefn/jasmine-enzyme-ts@9003027

At the time of writing the repo at https://github.com/cefn/jasmine-enzyme-ts now runs two Enzyme tests written in Typescript correctly using Jasmine tests in a Chrome Karma instance without hitting the errors described in this issue. It uses a webpack configuration to transform the typescript rather than the prior approach I attempted based on karma-typescript which was broken.

For CI and hopefully later reproduction for others I have committed pnpm-lock.yaml so installing the project with pnpm install --frozen-lockfile shouldn't be susceptible to packages which update and break it.

@cefn

I've left a little investigation report in #480, which again confirmed, that this is an error message that does not contain enough information. The report also contains a little info on how to set a fitting debugging point, which files the output cannot be found for.

@D4nte
Copy link

D4nte commented Jul 14, 2021

I was able to fix that by ensuring that I use a tsconfig file with:

  "compilerOptions": {
    "noEmit": false
  },

Now I am getting a Uncaught Error: Can't find ... error that I am investigating

@moughxyz
Copy link

moughxyz commented Aug 7, 2021

Issue for me was emitDeclarationOnly was set to true in tsconfig. Should be false.

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

No branches or pull requests

10 participants