本文整理匯總了TypeScript中jest-snapshot.buildSnapshotResolver函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript buildSnapshotResolver函數的具體用法?TypeScript buildSnapshotResolver怎麽用?TypeScript buildSnapshotResolver使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了buildSnapshotResolver函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: default
export default ({
config,
globalConfig,
localRequire,
testPath,
}: SetupOptions) => {
// Jest tests snapshotSerializers in order preceding built-in serializers.
// Therefore, add in reverse because the last added is the first tested.
config.snapshotSerializers
.concat()
.reverse()
.forEach(path => {
addSerializer(localRequire(path));
});
patchJasmine();
const {expand, updateSnapshot} = globalConfig;
const snapshotResolver = buildSnapshotResolver(config);
const snapshotPath = snapshotResolver.resolveSnapshotPath(testPath);
const snapshotState = new SnapshotState(snapshotPath, {
expand,
getBabelTraverse: () => require('@babel/traverse').default,
getPrettier: () =>
config.prettierPath ? require(config.prettierPath) : null,
updateSnapshot,
});
setState({snapshotState, testPath});
// Return it back to the outer scope (test runner outside the VM).
return snapshotState;
};
示例2: DependencyResolver
(runtimeContext: any) => {
dependencyResolver = new DependencyResolver(
runtimeContext.resolver,
runtimeContext.hasteFS,
buildSnapshotResolver(config),
);
},
示例3: findRelatedTests
findRelatedTests(
allPaths: Set<Config.Path>,
collectCoverage: boolean,
): SearchResult {
const dependencyResolver = new DependencyResolver(
this._context.resolver,
this._context.hasteFS,
buildSnapshotResolver(this._context.config),
);
if (!collectCoverage) {
return {
tests: toTests(
this._context,
dependencyResolver.resolveInverse(
allPaths,
this.isTestFilePath.bind(this),
{skipNodeResolution: this._context.config.skipNodeResolution},
),
),
};
}
const testModulesMap = dependencyResolver.resolveInverseModuleMap(
allPaths,
this.isTestFilePath.bind(this),
{skipNodeResolution: this._context.config.skipNodeResolution},
);
const allPathsAbsolute = Array.from(allPaths).map(p => path.resolve(p));
const collectCoverageFrom = new Set();
testModulesMap.forEach(testModule => {
if (!testModule.dependencies) {
return;
}
testModule.dependencies
.filter(p => allPathsAbsolute.includes(p))
.map(filename => {
filename = replaceRootDirInPath(
this._context.config.rootDir,
filename,
);
return path.isAbsolute(filename)
? path.relative(this._context.config.rootDir, filename)
: filename;
})
.forEach(filename => collectCoverageFrom.add(filename));
});
return {
collectCoverageFrom,
tests: toTests(
this._context,
testModulesMap.map(testModule => testModule.file),
),
};
}
示例4:
contexts.forEach(context => {
const status = snapshot.cleanup(
context.hasteFS,
this._globalConfig.updateSnapshot,
snapshot.buildSnapshotResolver(context.config),
);
aggregatedResults.snapshot.filesRemoved += status.filesRemoved;
});
示例5: throat
export const initialize = ({
config,
environment,
getPrettier,
getBabelTraverse,
globalConfig,
localRequire,
parentProcess,
testPath,
}: {
config: Config.ProjectConfig;
environment: JestEnvironment;
getPrettier: () => null | any;
getBabelTraverse: () => Function;
globalConfig: Config.GlobalConfig;
localRequire: (path: Config.Path) => any;
testPath: Config.Path;
parentProcess: Process;
}) => {
const mutex = throat(globalConfig.maxConcurrency);
Object.assign(global, globals);
global.xit = global.it.skip;
global.xtest = global.it.skip;
global.xdescribe = global.describe.skip;
global.fit = global.it.only;
global.fdescribe = global.describe.only;
global.test.concurrent = (test => {
const concurrent = (
testName: string,
testFn: () => Promise<any>,
timeout?: number,
) => {
// For concurrent tests we first run the function that returns promise, and then register a
// nomral test that will be waiting on the returned promise (when we start the test, the promise
// will already be in the process of execution).
// Unfortunately at this stage there's no way to know if there are any `.only` tests in the suite
// that will result in this test to be skipped, so we'll be executing the promise function anyway,
// even if it ends up being skipped.
const promise = mutex(() => testFn());
global.test(testName, () => promise, timeout);
};
concurrent.only = (
testName: string,
testFn: () => Promise<any>,
timeout?: number,
) => {
const promise = mutex(() => testFn());
// eslint-disable-next-line jest/no-focused-tests
test.only(testName, () => promise, timeout);
};
concurrent.skip = test.skip;
return concurrent;
})(global.test);
addEventHandler(eventHandler);
if (environment.handleTestEvent) {
addEventHandler(environment.handleTestEvent.bind(environment));
}
dispatch({
name: 'setup',
parentProcess,
testNamePattern: globalConfig.testNamePattern,
});
if (config.testLocationInResults) {
dispatch({
name: 'include_test_location_in_result',
});
}
// Jest tests snapshotSerializers in order preceding built-in serializers.
// Therefore, add in reverse because the last added is the first tested.
config.snapshotSerializers
.concat()
.reverse()
.forEach(path => {
addSerializer(localRequire(path));
});
const {expand, updateSnapshot} = globalConfig;
const snapshotResolver = buildSnapshotResolver(config);
const snapshotPath = snapshotResolver.resolveSnapshotPath(testPath);
const snapshotState = new SnapshotState(snapshotPath, {
expand,
getBabelTraverse,
getPrettier,
updateSnapshot,
});
setState({snapshotState, testPath});
// Return it back to the outer scope (test runner outside the VM).
return {globals, snapshotState};
//.........這裏部分代碼省略.........