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.

All files are showing Unknown with plugin.

See original GitHub issue

Also posted on StackOverflow

I’m trying to get nyc ava and babel to all place nice together.

I’ve done this a bunch of times, I’m not sure what’s going wrong now.

I was having an issue where async / await branches were showing as not covered, so this was working, I’m having trouble integrating the babel-plugin-istanbul plugin for tests.

I have two files in the project, src/index.js and src/test.js.

{
    "name": "example",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "test": "ava",
        "coverage": "NODE_ENV=test nyc npm run test",
        "report": "nyc report --reporter=html",
        "report:open": "open ./coverage/index.html",
        "cover": "npm run coverage && npm run report && npm run report:open"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
        "babel-runtime": "^6.26.0",
        "bluebird": "^3.5.0",
        "lodash": "^4.17.4"
    },
    "devDependencies": {
        "ava": "^0.22.0",
        "babel-cli": "^6.26.0",
        "babel-plugin-istanbul": "^4.1.4",
        "babel-plugin-transform-runtime": "^6.23.0",
        "babel-preset-env": "^1.6.0",
        "babel-register": "^6.26.0",
        "nyc": "^11.2.1",
        "sinon": "^3.2.1",
        "testdouble": "^3.2.4"
    },
    "babel": {
        "presets": ["env"],
        "plugins": ["transform-runtime"],
        "env": {
            "test": {
                "plugins": ["istanbul"]
            }
        }
    },
    "ava": {
        "require": ["babel-register"],
        "babel": "inherit"
    },
    "nyc": {
        "sourceMap": false,
        "instrument": false
    }
}

Here’s whats running:

> example@1.0.0 coverage /Users/me/Desktop/example
> NODE_ENV=test nyc npm run test


> example@1.0.0 test /Users/me/Desktop/example
> ava


  11 passed
----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files |  Unknown |  Unknown |  Unknown |  Unknown |                |
----------|----------|----------|----------|----------|----------------|

> example@1.0.0 report /Users/me/Desktop/example
> nyc report --reporter=html


> example@1.0.0 report:open /Users/em/Desktop/example
> open ./coverage/index.html

Why isn’t src/index.js showing in the coverage?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:14

github_iconTop GitHub Comments

8reactions
kumarmudurcommented, Oct 13, 2017

I have same problem in nyc@11.2.1 version.

2reactions
reggicommented, Mar 23, 2018

Still having this issue months after I created this ticket, and I just dug deeper into the issue, here are my findings.

I was receiving this issue in my HTML output for each file: https://github.com/istanbuljs/nyc/issues/239

And I was also receiving this in the newer version of nyc + babel-plugin-istanbul.

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|

I just learned several things the main one for now that I have confirmed is that:

⚠️ The babel-plugin-istanbul plugin needs to be the first babel plugin.

It seems I can get it working consistently by making this simple tweak to my settings.

This is what I am using, and it’s working properly.

⚠️ Something to look out for is to ensure that while you’re tinkering with settings, you don’t inadvertently ignore or exclude or not include the very files you are trying to cover, best to leave all these fields in nyc as default while trying to get it to work, when you do then you can fiddle with these settings.

{
  "scripts": {
    "babel": "babel --copy-files src -d dist --ignore test.js",
    "babel:watch": "npm run build --- --watch",
    "prebuild": "rm -rf dist",
    "build": "npm run babel",
    "build:watch": "npm run babel:watch",
    "coverage:file": "nyc npm run test:file",
    "coverage:files": "nyc npm run test:files",
    "lint": "npm run standard",
    "lint:fix": "npm run standard:fix",
    "pretest": "npm run standard",
    "test": "npm run coverage:files",
    "test:file": "NODE_ENV=test mocha --require babel-register",
    "test:files": "npm run test:file -- src/**/test.js"
  },
  "babel": {
    "env": {
      "test": {
        "plugins": [
          "istanbul",
          "rewire",
          "transform-runtime"
        ]
      }
    },
    "plugins": [
      "transform-runtime"
    ],
    "presets": [
      [
        "env",
        {
          "targets": {
            "node": "4.0.0"
          }
        }
      ],
      "stage-0"
    ]
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.2.2",
    "babel-plugin-istanbul": "^4.1.5",
    "babel-plugin-rewire": "^1.1.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-stage-0": "^6.24.1",
    "babel-register": "^6.26.0",
    "babel-template": "^6.26.0",
    "babel-types": "^6.26.0",
    "mocha": "^5.0.1",
    "nyc": "11.6.0",
  },
  "nyc": {
    "require": [
      "babel-register"
    ],
    "reporter": [
      "json",
      "lcov",
      "html",
      "text"
    ],
    "check-coverage": true,
    "per-file": false,
    "lines": 100,
    "statements": 100,
    "functions": 100,
    "branches": 100,
    "sourceMap": false,
    "instrument": false,
    "all": true
  },
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Dealing With Unknown File Type | Tech Tip Tuesday! - YouTube
How do you deal with unknown file types within Windows 10. Chapters0:00 Introduction0:16 Windows 10 Version0:26 Folder on Desktop0:33 ...
Read more >
How to open an unknown file in Windows - Digital Citizen
Simply search using the file extension first and then add terms like “file type” or “file extension,” similar to the screenshot above.
Read more >
Unknown file in WordPress core
My webhost just fixed an issue with my website and now I have 454 results showing (99% are Unknown file in WordPress core)....
Read more >
How to Read Unknown File Extensions
1. Right-click the file with the unknown extension and select "Scan with..." to first determine that it contains no viruses. · 2. Double-click...
Read more >
How to setup a specific application to open all files with ...
Here I'll show you, how to create a item menu in the right click context menu, ... Now, if you need open a...
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