Skip to content

Instantly share code, notes, and snippets.

@lorenzofox3
Created May 10, 2021 13:51
Show Gist options
  • Save lorenzofox3/81c201346b28239b477643b1119bbbe9 to your computer and use it in GitHub Desktop.
Save lorenzofox3/81c201346b28239b477643b1119bbbe9 to your computer and use it in GitHub Desktop.
ts-setup-example ts-setup-example
{
"name": "zora-coverage",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "ts-node sum.spec.ts",
"test:only": "RUN_ONLY=true ts-node sum.spec.ts",
"test:coverage": "c8 --exclude to-be-excluded.ts ts-node sum.spec.ts",
"dev": "nodemon sum.spec.ts"
},
"author": "",
"license": "ISC",
"devDependencies": {
"c8": "~7.7.2",
"nodemon": "~2.0.7",
"ts-node": "~9.1.1",
"zora": "^4.1.0"
}
}
import {test} from 'zora';
import sum from './sum'
test(`sum`, (t) =>{
t.eq(sum(0,4), 4);
})
import {foo} from './to-be-excluded';
foo();
export default (a: number, b: number): number => a + b;
export const foo = () => {
console.log(foo);
}
@mindplay-dk
Copy link

I've had no luck with this.

I use esbuild, which requires "type": "module", and this won't work with that. (the same issue probably affects other bundlers that rely on type - like parcel or microbundle...)

I also tried the experimental ESM feature in ts-node - so node --loader ts-node/esm instead of ts-node, that doesn't work either, just errors at the first import or export statement.

I had more luck with this approach in zora-recipes:

https://github.com/lorenzofox3/zora-recipes/blob/master/3_node_typescript/package.json

Still, no luck with c8 and code-coverage though. (will post more on that here.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment