Initial pass
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import { Config } from '@jest/types';
|
||||
import { Options, TransformResult } from './types';
|
||||
export default class ScriptTransformer {
|
||||
static EVAL_RESULT_VARIABLE: 'Object.<anonymous>';
|
||||
private _cache;
|
||||
private _config;
|
||||
private _transformCache;
|
||||
constructor(config: Config.ProjectConfig);
|
||||
private _getCacheKey;
|
||||
private _getFileCachePath;
|
||||
private _getTransformPath;
|
||||
private _getTransformer;
|
||||
private _instrumentFile;
|
||||
private _getRealPath;
|
||||
preloadTransformer(filepath: Config.Path): void;
|
||||
transformSource(filepath: Config.Path, content: string, instrument: boolean): {
|
||||
code: string;
|
||||
mapCoverage: boolean;
|
||||
sourceMapPath: string | null;
|
||||
};
|
||||
private _transformAndBuildScript;
|
||||
transform(filename: Config.Path, options: Options, fileSource?: string): TransformResult;
|
||||
transformJson(filename: Config.Path, options: Options, fileSource: string): string;
|
||||
/**
|
||||
* @deprecated use `this.shouldTransform` instead
|
||||
*/
|
||||
private _shouldTransform;
|
||||
shouldTransform(filename: Config.Path): boolean;
|
||||
}
|
||||
//# sourceMappingURL=ScriptTransformer.d.ts.map
|
||||
+1
File diff suppressed because one or more lines are too long
+746
File diff suppressed because it is too large
Load Diff
+2
@@ -0,0 +1,2 @@
|
||||
export default function enhanceUnexpectedTokenMessage(e: Error): Error;
|
||||
//# sourceMappingURL=enhanceUnexpectedTokenMessage.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"enhanceUnexpectedTokenMessage.d.ts","sourceRoot":"","sources":["../src/enhanceUnexpectedTokenMessage.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,OAAO,UAAU,6BAA6B,CAAC,CAAC,EAAE,KAAK,SA2B7D"}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = enhanceUnexpectedTokenMessage;
|
||||
|
||||
function _chalk() {
|
||||
const data = _interopRequireDefault(require('chalk'));
|
||||
|
||||
_chalk = function _chalk() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
|
||||
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
const DOT = ' \u2022 ';
|
||||
|
||||
function enhanceUnexpectedTokenMessage(e) {
|
||||
e.stack =
|
||||
`${_chalk().default.bold.red('Jest encountered an unexpected token')}
|
||||
|
||||
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
|
||||
|
||||
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
|
||||
|
||||
Here's what you can do:
|
||||
${DOT}To have some of your "node_modules" files transformed, you can specify a custom ${_chalk().default.bold(
|
||||
'"transformIgnorePatterns"'
|
||||
)} in your config.
|
||||
${DOT}If you need a custom transformation specify a ${_chalk().default.bold(
|
||||
'"transform"'
|
||||
)} option in your config.
|
||||
${DOT}If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the ${_chalk().default.bold(
|
||||
'"moduleNameMapper"'
|
||||
)} config option.
|
||||
|
||||
You'll find more details and examples of these config options in the docs:
|
||||
${_chalk().default.cyan('https://jestjs.io/docs/en/configuration.html')}
|
||||
|
||||
${_chalk().default.bold.red('Details:')}
|
||||
|
||||
` + e.stack;
|
||||
return e;
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
export { default as ScriptTransformer } from './ScriptTransformer';
|
||||
export { default as shouldInstrument } from './shouldInstrument';
|
||||
export { Transformer, ShouldInstrumentOptions, Options as TransformationOptions, } from './types';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,IAAI,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,OAAO,IAAI,qBAAqB,GACjC,MAAM,SAAS,CAAC"}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, 'ScriptTransformer', {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _ScriptTransformer.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'shouldInstrument', {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _shouldInstrument.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'Transformer', {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _types.Transformer;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'ShouldInstrumentOptions', {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _types.ShouldInstrumentOptions;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'TransformationOptions', {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _types.Options;
|
||||
}
|
||||
});
|
||||
|
||||
var _ScriptTransformer = _interopRequireDefault(require('./ScriptTransformer'));
|
||||
|
||||
var _shouldInstrument = _interopRequireDefault(require('./shouldInstrument'));
|
||||
|
||||
var _types = require('./types');
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import { Config } from '@jest/types';
|
||||
import { ShouldInstrumentOptions } from './types';
|
||||
export default function shouldInstrument(filename: Config.Path, options: ShouldInstrumentOptions, config: Config.ProjectConfig): boolean;
|
||||
//# sourceMappingURL=shouldInstrument.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"shouldInstrument.d.ts","sourceRoot":"","sources":["../src/shouldInstrument.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAInC,OAAO,EAAC,uBAAuB,EAAC,MAAM,SAAS,CAAC;AAMhD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,QAAQ,EAAE,MAAM,CAAC,IAAI,EACrB,OAAO,EAAE,uBAAuB,EAChC,MAAM,EAAE,MAAM,CAAC,aAAa,GAC3B,OAAO,CA4ET"}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.default = shouldInstrument;
|
||||
|
||||
function _path() {
|
||||
const data = _interopRequireDefault(require('path'));
|
||||
|
||||
_path = function _path() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _jestRegexUtil() {
|
||||
const data = require('jest-regex-util');
|
||||
|
||||
_jestRegexUtil = function _jestRegexUtil() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _jestUtil() {
|
||||
const data = require('jest-util');
|
||||
|
||||
_jestUtil = function _jestUtil() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _micromatch() {
|
||||
const data = _interopRequireDefault(require('micromatch'));
|
||||
|
||||
_micromatch = function _micromatch() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {default: obj};
|
||||
}
|
||||
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
const MOCKS_PATTERN = new RegExp(
|
||||
(0, _jestRegexUtil().escapePathForRegex)(
|
||||
_path().default.sep + '__mocks__' + _path().default.sep
|
||||
)
|
||||
);
|
||||
|
||||
function shouldInstrument(filename, options, config) {
|
||||
if (!options.collectCoverage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
config.forceCoverageMatch.length &&
|
||||
_micromatch().default.any(filename, config.forceCoverageMatch)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
!config.testPathIgnorePatterns.some(pattern => !!filename.match(pattern))
|
||||
) {
|
||||
if (config.testRegex.some(regex => new RegExp(regex).test(filename))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
_micromatch().default.some(
|
||||
(0, _jestUtil().replacePathSepForGlob)(filename),
|
||||
config.testMatch
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
// This configuration field contains an object in the form of:
|
||||
// {'path/to/file.js': true}
|
||||
options.collectCoverageOnlyFrom &&
|
||||
!options.collectCoverageOnlyFrom[filename]
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
// still cover if `only` is specified
|
||||
!options.collectCoverageOnlyFrom &&
|
||||
options.collectCoverageFrom &&
|
||||
!_micromatch().default.some(
|
||||
(0, _jestUtil().replacePathSepForGlob)(
|
||||
_path().default.relative(config.rootDir, filename)
|
||||
),
|
||||
options.collectCoverageFrom
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
config.coveragePathIgnorePatterns.some(pattern => !!filename.match(pattern))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config.globalSetup === filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config.globalTeardown === filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config.setupFiles.includes(filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config.setupFilesAfterEnv.includes(filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (MOCKS_PATTERN.test(filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.changedFiles && !options.changedFiles.has(filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
import { Script } from 'vm';
|
||||
import { RawSourceMap } from 'source-map';
|
||||
import { Config } from '@jest/types';
|
||||
export declare type ShouldInstrumentOptions = Pick<Config.GlobalConfig, 'collectCoverage' | 'collectCoverageFrom' | 'collectCoverageOnlyFrom'> & {
|
||||
changedFiles: Set<Config.Path> | undefined;
|
||||
};
|
||||
export declare type Options = ShouldInstrumentOptions & Pick<Config.GlobalConfig, 'extraGlobals'> & {
|
||||
isCoreModule?: boolean;
|
||||
isInternalModule?: boolean;
|
||||
};
|
||||
declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
||||
interface FixedRawSourceMap extends Omit<RawSourceMap, 'version'> {
|
||||
version: number;
|
||||
}
|
||||
export declare type TransformedSource = {
|
||||
code: string;
|
||||
map?: FixedRawSourceMap | string | null;
|
||||
};
|
||||
export declare type TransformResult = {
|
||||
script: Script;
|
||||
mapCoverage: boolean;
|
||||
sourceMapPath: string | null;
|
||||
};
|
||||
export declare type TransformOptions = {
|
||||
instrument: boolean;
|
||||
};
|
||||
export declare type CacheKeyOptions = {
|
||||
config: Config.ProjectConfig;
|
||||
instrument: boolean;
|
||||
rootDir: string;
|
||||
};
|
||||
export interface Transformer {
|
||||
canInstrument?: boolean;
|
||||
createTransformer?: (options?: any) => Transformer;
|
||||
getCacheKey: (fileData: string, filePath: Config.Path, configStr: string, options: CacheKeyOptions) => string;
|
||||
process: (sourceText: string, sourcePath: Config.Path, config: Config.ProjectConfig, options?: TransformOptions) => string | TransformedSource;
|
||||
}
|
||||
export {};
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
+1
File diff suppressed because one or more lines are too long
+1
@@ -0,0 +1 @@
|
||||
'use strict';
|
||||
Reference in New Issue
Block a user