Skip to content

Commit

Permalink
[jest/ts-jest] update ts-jest wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Sep 7, 2018
1 parent 718a9fa commit 80d2c44
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/dev/jest/ts_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@
* under the License.
*/

import { getCacheKey, install, process } from 'ts-jest';
import { JestConfig, TransformOptions } from 'ts-jest/dist/jest-types';
import TsJest from 'ts-jest';

import { getTsProjectForAbsolutePath } from '../typescript';

const DEFAULT_TS_CONFIG_PATH = require.resolve('../../../tsconfig.json');
const DEFAULT_BROWSER_TS_CONFIG_PATH = require.resolve('../../../tsconfig.browser.json');

function extendJestConfigJSON(jestConfigJSON: string, filePath: string) {
const jestConfig = JSON.parse(jestConfigJSON) as JestConfig;
const jestConfig = JSON.parse(jestConfigJSON) as jest.ProjectConfig;
return JSON.stringify(extendJestConfig(jestConfig, filePath));
}

function extendJestConfig(jestConfig: JestConfig, filePath: string) {
function extendJestConfig(jestConfig: jest.ProjectConfig, filePath: string) {
let tsConfigFile = getTsProjectForAbsolutePath(filePath).tsConfigPath;

// swap ts config file for jest tests
Expand All @@ -51,25 +50,25 @@ function extendJestConfig(jestConfig: JestConfig, filePath: string) {
}

module.exports = {
canInstrument: true,

process(
src: string,
filePath: string,
jestConfig: JestConfig,
transformOptions: TransformOptions
filePath: jest.Path,
jestConfig: jest.ProjectConfig,
transformOptions: jest.TransformOptions
) {
const extendedConfig = extendJestConfig(jestConfig, filePath);
return process(src, filePath, extendedConfig, transformOptions);
return TsJest.process(src, filePath, extendedConfig, transformOptions);
},

getCacheKey(
src: string,
filePath: string,
jestConfigJSON: string,
transformOptions: TransformOptions
transformOptions: jest.TransformOptions
) {
const extendedConfigJSON = extendJestConfigJSON(jestConfigJSON, filePath);
return getCacheKey(src, filePath, extendedConfigJSON, transformOptions);
return TsJest.getCacheKey!(src, filePath, extendedConfigJSON, transformOptions);
},

install,
};

0 comments on commit 80d2c44

Please sign in to comment.