Instrumenting with nyc produces invalid Typescript
See original GitHub issueLink 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:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@codefoster you are using
ts-node/register/transpile-only
, I’m guessing thatts-node/register
would experience this issue until thets-ignore
I’m added gets released.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):
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.