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

Question: How to coverage Typescript using Tape #497

Closed
kevincaradant opened this issue Jan 18, 2017 · 12 comments

Comments

@kevincaradant
Copy link

commented Jan 18, 2017

Hi

I'm a little bit lost with all the libraries between karma, mocha etc

I decided to use Tape.

This is my scripts in the package.json:

"scripts": {
        "start": "npm run build",
        "clean": "rimraf bin && rimraf coverage",
        "lint": "tslint './src/**/*.ts' ",
        "check": "npm run lint -s && dependency-check ./package.json",
        "pretest": "tsc",
        "test": "tape bin/tests/**/*.spec.js | tspec",
        "test:watch": "onchange \"tests/**/*.ts\" \"src/**/*.ts\" -i -p -- npm run test",
        "compile": "tsc",
        "compile:watch": "onchange \"src/**/*.ts\" -i -p -- npm run compile",
        "build": "npm run compile",
        "postbuild": "npm run check -s && npm run test -s",
        "coverage": "nyc npm run test",
        "coveralls": "npm run coverage -s && coveralls < coverage/lcov.info",
        "postcoveralls": "rimraf ./coverage",
        "prepublish": "npm run build -s",
        "deploy": "git pull --rebase origin master && git push origin master",
        "patch": "npm version patch && npm publish",
        "minor": "npm version minor && npm publish",
        "major": "npm version major && npm publish",
        "postpublish": "git push origin master --follow-tags",
        "autocl": "auto-changelog"
    },

My .nyc file:

{
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "tests/**/*.spec.js",
    "bin/**/*.spec.js",
    "bin/**/*.map"
  ],
  "reporter": [
    "lcov",
    "text-summary"
  ],
  "extension": [
    ".ts"
  ],
  "require": [
      "ts-node/register"
   ],
  "all": true,
  "check-coverage": true
}

Can I coverage cleanly using my way with npm run test and npm run coverage ?
Or what I have to do ?

Thank you in advance, sorry if it's trivial.

npm run coverage comand:
This is my output:
image

@bcoe

This comment has been minimized.

Copy link
Member

commented Jan 18, 2017

@kevincaradant nyc should work just fine with tape, my guess is that something is getting lost in translation in the transpilation step -- maybe we're ultimately excluding the source files.

I'm looping in @JaKXz who's had a bit more experience on this end of things than me. Is this a library that we can check-out and experiment with?

@kevincaradant

This comment has been minimized.

Copy link
Author

commented Jan 18, 2017

@bcoe ,Thanks, to glance a look at my issue.

This is my repository ( in building for dev branch ):
https://github.com/kevincaradant/generate_check_md5/tree/dev

Go in the dev branch otherwise you will be with babel and not typescript.
Then, write the command yarn
Than you can: npm run test and npm run coverage

Let me know if you need something else.

For information:
nyc: V10.0.0
tape: V4.6.3
Node: V7.4.0
OS: Ubuntu 64bits

@kevincaradant

This comment has been minimized.

Copy link
Author

commented Jan 23, 2017

Any news about this issue ?
I'm motivated to have again a coverage which works :)
Maybe it's a bad use from me.
I think it's not link to TS, even with JS files, something wrong and I get always 0%

@JaKXz

This comment has been minimized.

Copy link
Member

commented Jan 24, 2017

@kevincaradant I took a brief look tonight, and it seems the underlying complexity to get nyc, tape, and typescript to play nice is very high. 😞

In the short term, I'd recommend AVA's typescript recipe (since the assertion API is very similar to tape): https://github.com/avajs/ava/blob/master/docs/recipes/typescript.md if you need to move fast and get coverage. tap is also a worthy option: https://remysharp.com/2016/02/08/testing-tape-vs-tap

I can take a more in depth look only later in the week (unfortunately I was very ill last week and have lots to catch up on ATM).

@kevincaradant

This comment has been minimized.

Copy link
Author

commented Jan 24, 2017

@JaKXz, thank you to try to have a look knowing that you was sick. I understand now, you will have some works to catch up.
I will try to look ava or tap.

The main problem is that I use mock-fs to mock my files in my unit tests. So, I know sometimes, some unit testing doesn't work properly with this library. I hope ava or tap will work. Otherwise, I will be patient waiting a fix with nyc for tape and ts :).

@bcoe bcoe added the help wanted label Feb 6, 2017

@bcoe

This comment has been minimized.

Copy link
Member

commented Feb 6, 2017

@kevincaradant would love your help further documenting typescript related configurations, once you have a chance to dig into things further.

we have tutorials here that I'd love to see us build out further.

@kevincaradant

This comment has been minimized.

Copy link
Author

commented Feb 6, 2017

I was looking for use ava or tap. But I met some different problems and any workaround satisfied me. I would a compilation on the fly and use mock-fs in more, I would keep nyc so I will try to help you but to be honest, I didn't understand really that you want. I will try to look your tutorials tomorrow :). I will back to you if I need some info

@bcoe

This comment has been minimized.

Copy link
Member

commented May 14, 2017

@kevincaradant did you ever make any progress on this?

@huan

This comment has been minimized.

Copy link

commented Mar 20, 2018

It seems nyc will not work with tape right now?

@Bibliofile

This comment has been minimized.

Copy link

commented May 5, 2018

Using nyc with tape is correctly generating coverage for me.

Relevant parts of package.json:

  "devDependencies": {
    "@types/tape": "^4.2.32",
    "nyc": "^11.7.1",
    "tap-prettify": "^0.0.2",
    "tape": "^4.9.0",
    "ts-node": "^6.0.2",
    "typescript": "^2.8.3"
  },
  "scripts": {
    "test": "tape -r ts-node/register src/*.test.ts | tap-prettify -",
    "coverage": "nyc yarn test",
    "report": "nyc report --reporter=html"
  },
  "nyc": {
    "extension": [
      ".ts"
    ],
    "exclude": [
      "**/*.test.ts"
    ]
  }

@JaKXz JaKXz added doc TypeScript and removed help wanted labels Jan 3, 2019

@stale

This comment has been minimized.

Copy link

commented Mar 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 6, 2019

@stale stale bot closed this Mar 14, 2019

@JaKXz JaKXz added question and removed stale labels Mar 14, 2019

@JaKXz

This comment has been minimized.

Copy link
Member

commented Mar 14, 2019

Since @Bibliofile's comment, you can simplify it even further with the recently published nyc-config-typescript package.

  1. npm i -D @istanbuljs/nyc-config-typescript
"nyc": {
  "extends": "@istanbuljs/nyc-config-typescript"
}
@styfle styfle referenced this issue Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.