Skip to content

Commit

Permalink
Fix indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kulshekhar committed Jan 5, 2018
1 parent 0982e22 commit 532ad4c
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 226 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
@@ -1,7 +1,7 @@
[*.ts]
indent_style = space
indent_size = 4
indent_size = 2

[*.tsx]
indent_style = space
indent_size = 4
indent_size = 2
19 changes: 9 additions & 10 deletions src/install.ts
Expand Up @@ -2,17 +2,16 @@ import * as sourceMapSupport from 'source-map-support';
import { defaultRetrieveFileHandler } from './default-retrieve-file-handler';

export function install(filePath: string, fileContent: string) {
const options: sourceMapSupport.Options = {};
const options: sourceMapSupport.Options = {};

// options.retrieveFile = defaultRetrieveFileHandler;
options.retrieveFile = path =>
path === filePath ? fileContent : undefined;
// options.retrieveFile = defaultRetrieveFileHandler;
options.retrieveFile = path => (path === filePath ? fileContent : undefined);

/* tslint:disable */
// disabling tslint because the types for the source-map-support version
// in use here don't have the 'environment' property on options
options['environment'] = 'node';
/* tslint:disable */
/* tslint:disable */
// disabling tslint because the types for the source-map-support version
// in use here don't have the 'environment' property on options
options['environment'] = 'node';
/* tslint:disable */

return sourceMapSupport.install(options);
return sourceMapSupport.install(options);
}
123 changes: 60 additions & 63 deletions src/preprocessor.ts
Expand Up @@ -3,87 +3,84 @@ import * as tsc from 'typescript';
import { JestConfig, Path, TransformOptions } from './jest-types';
import { getPostProcessHook } from './postprocess';
import {
cacheFile,
getTSConfig,
getTSJestConfig,
injectSourcemapHook,
cacheFile,
getTSConfig,
getTSJestConfig,
injectSourcemapHook,
} from './utils';

export function process(
src: string,
filePath: Path,
jestConfig: JestConfig,
transformOptions: TransformOptions = { instrument: false },
src: string,
filePath: Path,
jestConfig: JestConfig,
transformOptions: TransformOptions = { instrument: false },
) {
// transformOptions.instrument is a proxy for collectCoverage
// https://github.com/kulshekhar/ts-jest/issues/201#issuecomment-300572902
const compilerOptions = getTSConfig(
jestConfig.globals,
transformOptions.instrument,
);
// transformOptions.instrument is a proxy for collectCoverage
// https://github.com/kulshekhar/ts-jest/issues/201#issuecomment-300572902
const compilerOptions = getTSConfig(
jestConfig.globals,
transformOptions.instrument,
);

const isTsFile = /\.tsx?$/.test(filePath);
const isJsFile = /\.jsx?$/.test(filePath);
const isHtmlFile = /\.html$/.test(filePath);
const isTsFile = /\.tsx?$/.test(filePath);
const isJsFile = /\.jsx?$/.test(filePath);
const isHtmlFile = /\.html$/.test(filePath);

// This is to support angular 2. See https://github.com/kulshekhar/ts-jest/pull/145
if (isHtmlFile && jestConfig.globals.__TRANSFORM_HTML__) {
src = 'module.exports=`' + src + '`;';
}
// This is to support angular 2. See https://github.com/kulshekhar/ts-jest/pull/145
if (isHtmlFile && jestConfig.globals.__TRANSFORM_HTML__) {
src = 'module.exports=`' + src + '`;';
}

const processFile =
compilerOptions.allowJs === true ? isTsFile || isJsFile : isTsFile;
const processFile =
compilerOptions.allowJs === true ? isTsFile || isJsFile : isTsFile;

if (!processFile) {
return src;
}
if (!processFile) {
return src;
}

const tsTranspiled = tsc.transpileModule(src, {
compilerOptions,
fileName: filePath,
});
const tsTranspiled = tsc.transpileModule(src, {
compilerOptions,
fileName: filePath,
});

const postHook = getPostProcessHook(
compilerOptions,
jestConfig,
getTSJestConfig(jestConfig.globals),
);
const postHook = getPostProcessHook(
compilerOptions,
jestConfig,
getTSJestConfig(jestConfig.globals),
);

const outputText = postHook(
tsTranspiled.outputText,
filePath,
jestConfig,
transformOptions,
);
const outputText = postHook(
tsTranspiled.outputText,
filePath,
jestConfig,
transformOptions,
);

const modified = injectSourcemapHook(
filePath,
tsTranspiled.outputText,
outputText,
);
const modified = injectSourcemapHook(
filePath,
tsTranspiled.outputText,
outputText,
);

cacheFile(jestConfig, filePath, modified);
cacheFile(jestConfig, filePath, modified);

return modified;
return modified;
}

export function getCacheKey(
fileData: string,
filePath: Path,
jestConfigStr: string,
transformOptions: TransformOptions = { instrument: false },
fileData: string,
filePath: Path,
jestConfigStr: string,
transformOptions: TransformOptions = { instrument: false },
): string {
const jestConfig: JestConfig = JSON.parse(jestConfigStr);
const jestConfig: JestConfig = JSON.parse(jestConfigStr);

const tsConfig = getTSConfig(
jestConfig.globals,
transformOptions.instrument,
);
const tsConfig = getTSConfig(jestConfig.globals, transformOptions.instrument);

return crypto
.createHash('md5')
.update(JSON.stringify(tsConfig), 'utf8')
.update(JSON.stringify(transformOptions), 'utf8')
.update(fileData + filePath + jestConfigStr, 'utf8')
.digest('hex');
return crypto
.createHash('md5')
.update(JSON.stringify(tsConfig), 'utf8')
.update(JSON.stringify(transformOptions), 'utf8')
.update(fileData + filePath + jestConfigStr, 'utf8')
.digest('hex');
}

0 comments on commit 532ad4c

Please sign in to comment.