Skip to content
This repository was archived by the owner on Oct 5, 2021. It is now read-only.

Commit dcac89a

Browse files
committed
feat: jest plugin
close #49
1 parent 81e1445 commit dcac89a

File tree

4 files changed

+2905
-0
lines changed

4 files changed

+2905
-0
lines changed

packages/typewiz-jest/package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "typewiz-jest",
3+
"version": "0.1.0",
4+
"main": "dist/index.js",
5+
"typings": "dist/index.d.ts",
6+
"repository": "https://github.com/urish/typewiz",
7+
"author": "Uri Shaked <[email protected]>",
8+
"license": "MIT",
9+
"scripts": {
10+
"build": "rimraf dist && tsc",
11+
"prepublish": "npm run build"
12+
},
13+
"files": ["dist"],
14+
"engines": {
15+
"node": ">= 6.4.0"
16+
},
17+
"dependencies": {
18+
"ts-jest": "^22.4.2",
19+
"typewiz": "^0.7.0"
20+
},
21+
"devDependencies": {
22+
"@types/babel-core": "^6.25.3",
23+
"rimraf": "^2.6.2"
24+
}
25+
}

packages/typewiz-jest/src/index.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { getCacheKey, process as originalProcess } from 'ts-jest';
2+
import { JestConfig, Path, TransformOptions } from 'ts-jest/dist/jest-types';
3+
import { instrument } from 'typewiz';
4+
5+
function process(
6+
src: string,
7+
filePath: Path,
8+
jestConfig: JestConfig,
9+
transformOptions: TransformOptions = { instrument: false },
10+
) {
11+
src =
12+
`require('typewiz').register();` +
13+
instrument(src, filePath, {
14+
instrumentCallExpressions: true,
15+
instrumentImplicitThis: true,
16+
tsConfig: 'tsconfig.json', // TODO read it from jest config?
17+
});
18+
return originalProcess(src, filePath, jestConfig, transformOptions);
19+
}
20+
21+
export { getCacheKey, process };

packages/typewiz-jest/tsconfig.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"strictNullChecks": true,
7+
"removeComments": false,
8+
"sourceMap": true,
9+
"declaration": true,
10+
"newLine": "LF",
11+
"noEmitOnError": true,
12+
"noUnusedLocals": true,
13+
"noImplicitThis": true,
14+
"noImplicitAny": true,
15+
"noFallthroughCasesInSwitch": true,
16+
"rootDir": "src",
17+
"outDir": "dist",
18+
"lib": ["es5", "es2015.core", "es2015.promise", "es2015.collection", "es2015.iterable"]
19+
},
20+
"include": ["src/**/*.ts"]
21+
}

0 commit comments

Comments
 (0)