Skip to content

Commit 09500c2

Browse files
committed
fix: fixes coverage and tests
1 parent e46caae commit 09500c2

36 files changed

Lines changed: 85 additions & 147 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"build": "tsc -p tsconfig.build.json",
99
"build:watch": "tsc -p tsconfig.build.json -w",
10-
"test:nolint": "npm run clean-build && node scripts/tests.js",
10+
"test:nolint": "npm run clean-build && jest --clearCache && node scripts/tests.js",
1111
"clean": "rimraf dist/**/* && rimraf tests/*/coverage && rimraf tests/*/debug.txt && rimraf tests/*/node_modules",
1212
"clean-build": "npm run clean && npm run build",
1313
"pretest": "npm run tslint && npm run clean-build",

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ const createTransformer = (options?: any): jest.Transformer => {
3131
};
3232
};
3333

34-
export default createTransformer();
35-
export { createTransformer };
34+
const mod = createTransformer();
35+
mod.createTransformer = createTransformer;
36+
export = mod;

src/utils/get-cache-key.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ export default function getCacheKey(
99
args: JestCacheKeyArguments,
1010
ctx: TsJestContext,
1111
): string {
12-
const [fileData, filePath, jestConfigString, { instrument, rootDir }] = args;
12+
const [
13+
fileData,
14+
filePath,
15+
jestConfigString,
16+
{ instrument = false, rootDir = process.cwd() } = {},
17+
] = args;
1318
const glob = JSON.parse(jestConfigString).globals || {};
1419
return createHash('md5')
1520
.update(MY_PACKAGE_CONTENT)

src/utils/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function flushLogs(): void {
3131
return; // only output stuff for the first invocation and if logging is enabled.
3232
}
3333
logsFlushed = true;
34-
const rootPath = path.resolve(__dirname, '../');
34+
const rootPath = path.resolve(__dirname, '..', '..');
3535
const JSONifiedLogs = logs.map(convertToJSONIfPossible);
3636
const logString = JSONifiedLogs.join('\n');
3737
const filePath = path.resolve(rootPath, 'debug.txt');
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Typescript async coverage Should generate the correct async coverage numbers 1`] = `
4+
"
5+
=============================== Coverage summary ===============================
6+
Statements : 68.75% ( 11/16 )
7+
Branches : 33.33% ( 2/6 )
8+
Functions : 66.67% ( 4/6 )
9+
Lines : 73.33% ( 11/15 )
10+
================================================================================
11+
"
12+
`;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Typescript coverage Should generate the correct coverage numbers. 1`] = `
4+
"
5+
=============================== Coverage summary ===============================
6+
Statements : 68.75% ( 11/16 )
7+
Branches : 33.33% ( 2/6 )
8+
Functions : 66.67% ( 4/6 )
9+
Lines : 73.33% ( 11/15 )
10+
================================================================================
11+
"
12+
`;

tests/__tests__/html-transform.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { process } from '../../src/preprocessor';
1+
import * as tsJest from '../..';
22

33
const path = '/path/to/file.html';
4-
const config = { globals: {} as any };
4+
const config: jest.ProjectConfig = { globals: {} } as any;
55
// wrap a transformed source so that we can fake a `require()` on it by calling the returned wrapper
66
const wrap = (src: string) =>
77
new Function(`var module={}; ${src} return module.exports;`) as any;
@@ -14,10 +14,10 @@ const source = `<div class="html-test">
1414
describe('Html transforms', () => {
1515
it('transforms html if config.globals.__TRANSFORM_HTML__ is set', () => {
1616
// get the untransformed version
17-
const untransformed = process(source, path, config);
17+
const untransformed = tsJest.process(source, path, config);
1818
// ... then the one which should be transformed
19-
config.globals.__TRANSFORM_HTML__ = true;
20-
const transformed = process(source, path, config) as string;
19+
(config.globals as any).__TRANSFORM_HTML__ = true;
20+
const transformed = tsJest.process(source, path, config) as string;
2121
// ... finally the result of a `require('module-with-transformed-version')`
2222
const exported = wrap(transformed)();
2323

tests/__tests__/postprocess.spec.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ jest.mock('@babel/core', () => {
99
import { getPostProcessHook } from '../../src/postprocess';
1010

1111
describe('postprocess', () => {
12-
function runHook(tsCompilerOptions = {}, jestConfig = {}, tsJestConfig = {}) {
13-
return getPostProcessHook(tsCompilerOptions, jestConfig, tsJestConfig)(
14-
{ code: 'input_code', map: 'input_source_map' },
15-
'fake_file',
16-
{},
17-
{ instrument: null },
18-
);
12+
function runHook(
13+
tsCompilerOptions = {},
14+
jestConfig: Partial<jest.ProjectConfig> = {},
15+
tsJestConfig = {},
16+
) {
17+
return getPostProcessHook(
18+
tsCompilerOptions,
19+
jestConfig as any,
20+
tsJestConfig,
21+
)({ code: 'input_code', map: 'input_source_map' }, 'fake_file', {} as any, {
22+
instrument: null,
23+
});
1924
}
2025

2126
it('skips postprocess when skipBabel=true', () => {
@@ -29,10 +34,10 @@ describe('postprocess', () => {
2934
const transformMock = require.requireMock('@babel/core').transform;
3035

3136
runHook();
32-
getPostProcessHook({}, {}, {})(
37+
getPostProcessHook({}, {} as any, {})(
3338
{ code: 'input_code', map: 'input_source_map' },
3439
'fake_file',
35-
{},
40+
{} as any,
3641
{ instrument: null },
3742
);
3843
expect(transformMock).lastCalledWith(

tests/__tests__/transpile-if-ts.spec.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/__tests__/ts-coverage-async.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ describe('Typescript async coverage', () => {
66

77
const output = result.stdout;
88

9-
expect(output).toContain('Statements : 71.43% ( 10/14 )');
10-
expect(output).toContain('Branches : 33.33% ( 2/6 )');
11-
expect(output).toContain('Functions : 66.67% ( 4/6 )');
12-
expect(output).toContain('Lines : 66.67% ( 8/12 )');
9+
expect(output).toMatchSnapshot();
1310
});
1411
});

0 commit comments

Comments
 (0)