本文整理汇总了TypeScript中@jest/transform.ScriptTransformer.transform方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ScriptTransformer.transform方法的具体用法?TypeScript ScriptTransformer.transform怎么用?TypeScript ScriptTransformer.transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@jest/transform.ScriptTransformer
的用法示例。
在下文中一共展示了ScriptTransformer.transform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _execModule
private _execModule(
localModule: InitialModule,
options: InternalModuleOptions | undefined,
moduleRegistry: ModuleRegistry,
from: Config.Path | null,
) {
// If the environment was disposed, prevent this module from being executed.
if (!this._environment.global) {
return;
}
const isInternalModule = !!(options && options.isInternalModule);
const filename = localModule.filename;
const lastExecutingModulePath = this._currentlyExecutingModulePath;
this._currentlyExecutingModulePath = filename;
const origCurrExecutingManualMock = this._isCurrentlyExecutingManualMock;
this._isCurrentlyExecutingManualMock = filename;
const dirname = path.dirname(filename);
localModule.children = [];
Object.defineProperty(localModule, 'parent', {
enumerable: true,
get() {
const key = from || '';
return moduleRegistry[key] || null;
},
});
localModule.paths = this._resolver.getModulePaths(dirname);
Object.defineProperty(localModule, 'require', {
value: this._createRequireImplementation(localModule, options),
});
const extraGlobals = this._config.extraGlobals || [];
const transformedFile = this._scriptTransformer.transform(
filename,
{
changedFiles: this._coverageOptions.changedFiles,
collectCoverage: this._coverageOptions.collectCoverage,
collectCoverageFrom: this._coverageOptions.collectCoverageFrom,
collectCoverageOnlyFrom: this._coverageOptions.collectCoverageOnlyFrom,
extraGlobals,
isInternalModule,
},
this._cacheFS[filename],
);
if (transformedFile.sourceMapPath) {
this._sourceMapRegistry[filename] = transformedFile.sourceMapPath;
if (transformedFile.mapCoverage) {
this._needsCoverageMapped.add(filename);
}
}
const runScript = this._environment.runScript(transformedFile.script);
if (runScript === null) {
this._logFormattedReferenceError(
'You are trying to `import` a file after the Jest environment has been torn down.',
);
process.exitCode = 1;
return;
}
const wrapper = runScript[ScriptTransformer.EVAL_RESULT_VARIABLE];
const moduleArguments = new Set([
localModule, // module object
localModule.exports, // module exports
localModule.require, // require implementation
dirname, // __dirname
filename, // __filename
this._environment.global, // global object
this._createJestObjectFor(
filename,
localModule.require as LocalModuleRequire,
), // jest object
...extraGlobals.map(globalVariable => {
if (this._environment.global[globalVariable]) {
return this._environment.global[globalVariable];
}
throw new Error(
`You have requested '${globalVariable}' as a global variable, but it was not present. Please check your config or your global environment.`,
);
}),
]);
wrapper.call(localModule.exports, ...Array.from(moduleArguments));
this._isCurrentlyExecutingManualMock = origCurrExecutingManualMock;
this._currentlyExecutingModulePath = lastExecutingModulePath;
}