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

Unknown% Coverage When updating past nyc@12.0.2 #1086

Closed
mschnee opened this issue Apr 24, 2019 · 3 comments
Closed

Unknown% Coverage When updating past nyc@12.0.2 #1086

mschnee opened this issue Apr 24, 2019 · 3 comments

Comments

@mschnee
Copy link

mschnee commented Apr 24, 2019

Link to bug demonstration repository

https://github.com/mschnee/nyc-unknown-example

Unknown% coverage when updating past nyc@12.0.2

Hey nyc team! To say that I love and depend on what you've done here would be an understatement.

We have run into a situation when upgrading from nyc@12.0.2 to latest nyc@14.0.0 or even 13.x. Post-upgrade, nyc is no longer collecting coverage and is reporting Unknown%.

I have a degree of confidence that this situation is likely related to some kind of configuration, but having tried all reasonable permutations now (including adding all source files as well), the original project has opted to downgrade and lock nyc to version 12.0.2 - because it works, and it is showing us the coverage we want to see. Google/StackOverflow haven't helped, and most published recipe guides are either out of date (published before the release of 12.0.0) or simply don't work. See #921 #946

I have pushed an example repository which can be cloned and examined. The pertinent facts:

  • There is an existing JavaScript project in the process of migration towatds TypeScript, with sources in ./src. Compiled files are in ./dist
  • Coverage intended to be collected through end-to-end integration testing by running with a docker-compose.yml file. Specifically, to ensure that changes to backend services (including three different kinds of data stores) do not violate a established api contracts.
  • nyc is currently configured to instrument the pre-compiled files in ./dist and expected to generate coverage reporting using the source maps provided.

Expected Behavior

Coverage is collected.
Coverage summary should be

=============================== Coverage summary ===============================
Statements   : 88.89% ( 24/27 )
Branches     : 100% ( 0/0 )
Functions    : 60% ( 3/5 )
Lines        : 88.89% ( 24/27 )
================================================================================

Observed Behavior

No coverage is collected.
Coverage Summary shows

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================

Environment Information

npx envinfo@latest --preset nyc
  System:
    OS: Linux 5.0 Ubuntu 19.04 (Disco Dingo)
    CPU: (8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
    Memory: 9.53 GB / 31.35 GB
  Binaries:
    Node: 10.15.2 - /usr/bin/node
  npmPackages:
    nyc: 12.0.2 => 12.0.2 
    source-map-support: ^0.5.12 => 0.5.12 
    typescript: ^3.4.5 => 3.4.5 

Relevant configuration files

ava.config.js

export default {
  files: [
    "dist/**/*.test.js"
  ],
  compileEnhancements: false,
  require: ["source-map-support/register"]
}

.nycrc.json

{
  "include": ["./src/**/*.js", "./dist/**/*.js"],
  "exclude": ["./src/**/*.spec.js", "./dist/**/*.test.js"],
  "reporter": ["lcov", "text-summary"],
  "sourceMap": true,
  "instrument": true,
  "cache": true,
  "all": false
}

tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist",
    "rootDir": "./src",
    "sourceMap": true,
    "inlineSources": true,
    "allowJs": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "module": "commonjs",
    "target": "es2018",
    "moduleResolution": "node",
    "incremental": true,
    "tsBuildInfoFile": ".tsBuildInfo"
  },
  "include": ["./src/**/*.js", "./src/**/*.json", "./src/**/*.ts"]
}

package.json

{
  "name": "nyc-unknown-example",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "ava": "^1.4.1",
    "body-parser": "^1.18.3",
    "cross-env": "^5.2.0",
    "express": "^4.16.4",
    "morgan": "^1.9.1",
    "nyc": "12.0.2",
    "source-map-support": "^0.5.12",
    "supertest": "^4.0.2",
    "typescript": "^3.4.5"
  },
  "devDependencies": {
    "@types/node": "^11.13.7",
    "rimraf": "^2.6.3"
  },
  "scripts": {
    "clean": "rimraf dist coverage .nyc_output .tsBuildInfo",
    "build": "tsc -p .",
    "pretest": "npm run build",
    "precover": "npm run build",
    "test": "cross-env NODE_ENV=test ava --fail-fast",
    "cover": "cross-env NODE_ENV=test nyc --reporter=html --reporter=text-summary ava --fail-fast"
  }
}

Instructions

npm install # get dependencies
npm run cover # precover will build for you
@coreyfarrell
Copy link
Member

It appears this is related to changes in our include/exclude processing. If you alter your .nycrc to remove the ./ from include/exclude patterns everything works:

{
  "include": ["src/**/*.js", "dist/**/*.js"],
  "exclude": ["src/**/*.spec.js", "dist/**/*.test.js"],
  "reporter": ["lcov", "text-summary"],
  "sourceMap": true,
  "instrument": true,
  "cache": true,
  "all": false
}

I tested this against nyc@14.1.0 (currently a prerelease but includes some fixes to source-maps that I recommend since you're using tsc).

@mschnee
Copy link
Author

mschnee commented Apr 25, 2019

Thanks @coreyfarrell - It looks like it was just something as small as that. Would it be possible to update the README.md with a small note about that? I completely overlooked the include/exclude patterns omitting the relative directory ./

@mschnee mschnee closed this as completed Apr 25, 2019
anishkny added a commit to anishkny/integrify that referenced this issue Apr 28, 2019
anishkny added a commit to anishkny/integrify that referenced this issue Apr 28, 2019
@nelsonic
Copy link

nelsonic commented Jun 1, 2021

Anyone seeing this error in the future and using Typescript, our .nycrc file is:

{
  "reporter": ["lcov", "cobertura", "text", "text-summary"],
  "include": ["**/*.ts"],
  "exclude": ["serverless.ts", "**/index.ts", "**/*.schema.ts", "config/**/*.ts", "**/*.test.ts"],
  "check-coverage": true,
  "sourceMap": true,
  "instrument": true,
  "cache": true,
  "all": false,
  "branches": 100,
  "functions": 100,
  "lines": 100,
  "statements": 100
}

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