本文整理汇总了TypeScript中jest-runtime.requireInternalModule函数的典型用法代码示例。如果您正苦于以下问题:TypeScript requireInternalModule函数的具体用法?TypeScript requireInternalModule怎么用?TypeScript requireInternalModule使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了requireInternalModule函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
const jestAdapter = async (
globalConfig: Config.GlobalConfig,
config: Config.ProjectConfig,
environment: JestEnvironment,
runtime: Runtime,
testPath: string,
): Promise<TestResult> => {
const {
initialize,
runAndTransformResultsToJestFormat,
} = runtime.requireInternalModule(FRAMEWORK_INITIALIZER);
runtime
.requireInternalModule(path.resolve(__dirname, './jestExpect.js'))
.default({
expand: globalConfig.expand,
});
const getPrettier = () =>
config.prettierPath ? require(config.prettierPath) : null;
const getBabelTraverse = () => require('@babel/traverse').default;
const {globals, snapshotState} = initialize({
config,
environment,
getBabelTraverse,
getPrettier,
globalConfig,
localRequire: runtime.requireModule.bind(runtime),
parentProcess: process,
testPath,
});
if (config.timers === 'fake') {
// during setup, this cannot be null (and it's fine to explode if it is)
environment.fakeTimers!.useFakeTimers();
}
globals.beforeEach(() => {
if (config.resetModules) {
runtime.resetModules();
}
if (config.clearMocks) {
runtime.clearAllMocks();
}
if (config.resetMocks) {
runtime.resetAllMocks();
if (config.timers === 'fake') {
// during setup, this cannot be null (and it's fine to explode if it is)
environment.fakeTimers!.useFakeTimers();
}
}
if (config.restoreMocks) {
runtime.restoreAllMocks();
}
});
config.setupFilesAfterEnv.forEach(path => runtime.requireModule(path));
runtime.requireModule(testPath);
const results = await runAndTransformResultsToJestFormat({
config,
globalConfig,
testPath,
});
return _addSnapshotData(results, snapshotState);
};
示例2: jasmine2
async function jasmine2(
globalConfig: Config.GlobalConfig,
config: Config.ProjectConfig,
environment: JestEnvironment,
runtime: Runtime,
testPath: string,
): Promise<TestResult> {
const reporter = new JasmineReporter(globalConfig, config, testPath);
const jasmineFactory = runtime.requireInternalModule(JASMINE);
const jasmine = jasmineFactory.create({
process,
testPath,
});
const env = jasmine.getEnv();
const jasmineInterface = jasmineFactory.interface(jasmine, env);
Object.assign(environment.global, jasmineInterface);
env.addReporter(jasmineInterface.jsApiReporter);
// TODO: Remove config option if V8 exposes some way of getting location of caller
// in a future version
if (config.testLocationInResults === true) {
const originalIt = environment.global.it;
environment.global.it = ((...args) => {
const stack = getCallsite(1, runtime.getSourceMaps());
const it = originalIt(...args);
// @ts-ignore
it.result.__callsite = stack;
return it;
}) as Global.Global['it'];
const originalXit = environment.global.xit;
environment.global.xit = ((...args) => {
const stack = getCallsite(1, runtime.getSourceMaps());
const xit = originalXit(...args);
// @ts-ignore
xit.result.__callsite = stack;
return xit;
}) as Global.Global['xit'];
const originalFit = environment.global.fit;
environment.global.fit = ((...args) => {
const stack = getCallsite(1, runtime.getSourceMaps());
const fit = originalFit(...args);
// @ts-ignore
fit.result.__callsite = stack;
return fit;
}) as Global.Global['fit'];
}
jasmineAsyncInstall(globalConfig, environment.global);
installEach(environment);
environment.global.test = environment.global.it;
environment.global.it.only = environment.global.fit;
environment.global.it.todo = env.todo;
environment.global.it.skip = environment.global.xit;
environment.global.xtest = environment.global.xit;
environment.global.describe.skip = environment.global.xdescribe;
environment.global.describe.only = environment.global.fdescribe;
if (config.timers === 'fake') {
environment.fakeTimers!.useFakeTimers();
}
env.beforeEach(() => {
if (config.resetModules) {
runtime.resetModules();
}
if (config.clearMocks) {
runtime.clearAllMocks();
}
if (config.resetMocks) {
runtime.resetAllMocks();
if (config.timers === 'fake') {
environment.fakeTimers!.useFakeTimers();
}
}
if (config.restoreMocks) {
runtime.restoreAllMocks();
}
});
env.addReporter(reporter);
runtime
.requireInternalModule(path.resolve(__dirname, './jestExpect.js'))
.default({
expand: globalConfig.expand,
//.........这里部分代码省略.........
示例3: runTestInternal
//.........这里部分代码省略.........
const cacheFS = {[path]: testSource};
setGlobal(environment.global, 'console', testConsole);
runtime = new Runtime(config, environment, resolver, cacheFS, {
changedFiles: context && context.changedFiles,
collectCoverage: globalConfig.collectCoverage,
collectCoverageFrom: globalConfig.collectCoverageFrom,
collectCoverageOnlyFrom: globalConfig.collectCoverageOnlyFrom,
});
const start = Date.now();
const sourcemapOptions: SourceMapOptions = {
environment: 'node',
handleUncaughtExceptions: false,
retrieveSourceMap: source => {
const sourceMaps = runtime && runtime.getSourceMaps();
const sourceMapSource = sourceMaps && sourceMaps[source];
if (sourceMapSource) {
try {
return {
map: JSON.parse(fs.readFileSync(sourceMapSource, 'utf8')),
url: source,
};
} catch (e) {}
}
return null;
},
};
// For tests
runtime
.requireInternalModule(
require.resolve('source-map-support'),
'source-map-support',
)
.install(sourcemapOptions);
// For runtime errors
sourcemapSupport.install(sourcemapOptions);
if (
environment.global &&
environment.global.process &&
environment.global.process.exit
) {
const realExit = environment.global.process.exit;
environment.global.process.exit = function exit(...args: Array<any>) {
const error = new ErrorWithStack(
`process.exit called with "${args.join(', ')}"`,
exit,
);
const formattedError = formatExecError(
error,
config,
{noStackTrace: false},
undefined,
true,
);
process.stderr.write(formattedError);
return realExit(...args);