Typescript transform plugin removes spec definition from source file
npm install typescript-transform-unspecfunction.ts with single function. Usually we create function.spec.ts with tests.ts
export function hello(greet = 'world') {
return hello ${greet};
}it('hello world test', () => {
expect(hello()).toBe('hello world');
});
`$3
`js
function hello(greet) {
if (greet === void 0) { greet = 'world'; }
return "hello " + greet;
}
``$3
\+ All in one file
\- Collecting coverage can be tricky Installation
`sh
npm install --save-dev typescript-transform-unspec
`Usage
#### webpack (with ts-loader or awesome-typescript-loader)
`js
// webpack.config.js
const unspecTransformer = require('typescript-transform-unspec');rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader', // or 'awesome-typescript-loader'
options: {
getCustomTransformers: program => ({
before: [
unspecTransformer(program),
]
})
}
},
]
`#### TTypescript
`json
// tsconfig.json
{
"compilerOptions": {
"plugins": [
{ "transform": "typescript-transform-unspec" },
]
},
}
`#### Rollup (with rollup-plugin-typescript2)
`js
// rollup.config.js
import typescript from 'rollup-plugin-typescript2';
import unspecTransformer from 'typescript-transform-unspec';plugins: [
typescript({
transformers: [
service => ({
before: [unspecTransformer(service.getProgram())],
after: [],
}),
],
}),
]
``