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.

Instrumenting with nyc produces invalid Typescript

See original GitHub issue

Link to bug demonstration repository

https://github.com/jedateach/nyc-typescript/runs/515835523

Expected Behavior

Instrument command produces valid typescript that has no errors

Observed Behavior

When instrumenting this file: https://github.com/jedateach/nyc-typescript/blob/master/src/constants.ts

We get this output: https://github.com/jedateach/nyc-typescript/blob/master/instrumented/constants.ts#L49

Then trying to run a typescript compiler using tsc instrumented/index.ts, gives:

instrumented/comparitor.ts:98:3 - error TS2539: Cannot assign to 'cov_1qahgqgynf' because it is not a variable.

98   cov_1qahgqgynf = function () {
     ~~~~~~~~~~~~~~

instrumented/constants.ts:49:3 - error TS2539: Cannot assign to 'cov_1im0zfgwer' because it is not a variable.

49   cov_1im0zfgwer = function () {

Troubleshooting steps

  • still occurring when I put cache: false in my nyc config

Environment Information

npx: installed 1 in 1.263s

  System:
    OS: macOS 10.15.3
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 1.26 GB / 32.00 GB
  Binaries:
    Node: 8.16.2 - ~/.nvm/versions/node/v8.16.2/bin/node
    Yarn: 1.3.2 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v8.16.2/bin/npm
  npmPackages:
    nyc: ^15.0.0 => 15.0.0 
    source-map-support: ^0.5.16 => 0.5.16 
    ts-node: ^8.6.2 => 8.6.2 
    typescript: ^3.8.3 => 3.8.3 

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
coreyfarrellcommented, Apr 15, 2020

@codefoster you are using ts-node/register/transpile-only, I’m guessing that ts-node/register would experience this issue until the ts-ignore I’m added gets released.

1reaction
coreyfarrellcommented, Mar 20, 2020

https://github.com/istanbuljs/istanbuljs/blob/master/packages/istanbul-lib-instrument/src/visitor.js#L550 is the line which generates code that offends TypeScript. The generated code is (clipped for briefness):

function cov_XXXXXX() {
 // Clipped initialization of actualCoverage
 cov_XXXXXX = function () {
   return actualCoverage;
 }
 return actualCoverage;
}

So TypeScript does not allow cov_XXXXXX to be re-assigned, JavaScript does. If TypeScript has a configuration option to allow this I don’t think it’s appropriate for istanbuljs to require that users set it when we can just inject a ts-ignore hint into the generated code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Instrumenting with nyc produces invalid Typescript -
When instrumenting this file: https://github.com/jedateach/nyc-typescript/blob/master/src/constants.ts. We get this output:
Read more >
Trying to use Typescript/Mocha/NYC together but am ... - Reddit
I've recently attached NYC to my Typescript project but am confused about how it determines when code is covered. Below is an example...
Read more >
Code coverage when running e2e tests on a project with ...
I cannot generate code coverage when I am running my e2e tests. It seems that there is no instrumentation done in this case....
Read more >
NYC: The Istanbul Command Line interface - Morioh
Please start with the pre-configured @istanbuljs/nyc-config-typescript preset. ... When a file is require() 'd, nyc creates and returns an instrumented ...
Read more >
Test runner Addon | Storybook: Frontend workshop for UI ...
The test runner is simple in design – it just visits each story from a running Storybook instance and makes sure the component...
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