id
int64 0
3.78k
| code
stringlengths 13
37.9k
| declarations
stringlengths 16
64.6k
|
---|---|---|
1,400 | function messageFormatter({error, message, passed}: Options) {
if (passed) {
return 'Passed.';
}
if (message) {
return message;
}
if (typeof error === 'string') {
return error;
}
if (
// duck-type Error, see #2549
error &&
typeof error === 'object' &&
typeof error.message === 'string' &&
typeof error.name === 'string'
) {
if (error.message === '') {
return error.name;
}
return `${error.name}: ${error.message}`;
}
return `thrown: ${prettyFormat(error, {maxDepth: 3})}`;
} | interface Options
extends ShouldInstrumentOptions,
CallerTransformOptions {
isInternalModule?: boolean;
} |
1,401 | function messageFormatter({error, message, passed}: Options) {
if (passed) {
return 'Passed.';
}
if (message) {
return message;
}
if (typeof error === 'string') {
return error;
}
if (
// duck-type Error, see #2549
error &&
typeof error === 'object' &&
typeof error.message === 'string' &&
typeof error.name === 'string'
) {
if (error.message === '') {
return error.name;
}
return `${error.name}: ${error.message}`;
}
return `thrown: ${prettyFormat(error, {maxDepth: 3})}`;
} | type Options = {
clearTimeout: (typeof globalThis)['clearTimeout'];
fail: (error: Error) => void;
onException: (error: Error) => void;
queueableFns: Array<QueueableFn>;
setTimeout: (typeof globalThis)['setTimeout'];
userContext: unknown;
}; |
1,402 | function messageFormatter({error, message, passed}: Options) {
if (passed) {
return 'Passed.';
}
if (message) {
return message;
}
if (typeof error === 'string') {
return error;
}
if (
// duck-type Error, see #2549
error &&
typeof error === 'object' &&
typeof error.message === 'string' &&
typeof error.name === 'string'
) {
if (error.message === '') {
return error.name;
}
return `${error.name}: ${error.message}`;
}
return `thrown: ${prettyFormat(error, {maxDepth: 3})}`;
} | type Options = {
matcherName: string;
passed: boolean;
actual?: any;
error?: any;
expected?: any;
message?: string | null;
}; |
1,403 | function messageFormatter({error, message, passed}: Options) {
if (passed) {
return 'Passed.';
}
if (message) {
return message;
}
if (typeof error === 'string') {
return error;
}
if (
// duck-type Error, see #2549
error &&
typeof error === 'object' &&
typeof error.message === 'string' &&
typeof error.name === 'string'
) {
if (error.message === '') {
return error.name;
}
return `${error.name}: ${error.message}`;
}
return `thrown: ${prettyFormat(error, {maxDepth: 3})}`;
} | type Options = {
nodeComplete: (suite: TreeNode) => void;
nodeStart: (suite: TreeNode) => void;
queueRunnerFactory: any;
runnableIds: Array<string>;
tree: TreeNode;
}; |
1,404 | function messageFormatter({error, message, passed}: Options) {
if (passed) {
return 'Passed.';
}
if (message) {
return message;
}
if (typeof error === 'string') {
return error;
}
if (
// duck-type Error, see #2549
error &&
typeof error === 'object' &&
typeof error.message === 'string' &&
typeof error.name === 'string'
) {
if (error.message === '') {
return error.name;
}
return `${error.name}: ${error.message}`;
}
return `thrown: ${prettyFormat(error, {maxDepth: 3})}`;
} | type Options = {
lastCommit?: boolean;
withAncestor?: boolean;
changedSince?: string;
includePaths?: Array<string>;
}; |
1,405 | function messageFormatter({error, message, passed}: Options) {
if (passed) {
return 'Passed.';
}
if (message) {
return message;
}
if (typeof error === 'string') {
return error;
}
if (
// duck-type Error, see #2549
error &&
typeof error === 'object' &&
typeof error.message === 'string' &&
typeof error.name === 'string'
) {
if (error.message === '') {
return error.name;
}
return `${error.name}: ${error.message}`;
}
return `thrown: ${prettyFormat(error, {maxDepth: 3})}`;
} | type Options = {
cacheDirectory?: string;
computeDependencies?: boolean;
computeSha1?: boolean;
console?: Console;
dependencyExtractor?: string | null;
enableSymlinks?: boolean;
extensions: Array<string>;
forceNodeFilesystemAPI?: boolean;
hasteImplModulePath?: string;
hasteMapModulePath?: string;
id: string;
ignorePattern?: HasteRegExp;
maxWorkers: number;
mocksPattern?: string;
platforms: Array<string>;
resetCache?: boolean;
retainAllFiles: boolean;
rootDir: string;
roots: Array<string>;
skipPackageJson?: boolean;
throwOnModuleCollision?: boolean;
useWatchman?: boolean;
watch?: boolean;
}; |
1,406 | function messageFormatter({error, message, passed}: Options) {
if (passed) {
return 'Passed.';
}
if (message) {
return message;
}
if (typeof error === 'string') {
return error;
}
if (
// duck-type Error, see #2549
error &&
typeof error === 'object' &&
typeof error.message === 'string' &&
typeof error.name === 'string'
) {
if (error.message === '') {
return error.name;
}
return `${error.name}: ${error.message}`;
}
return `thrown: ${prettyFormat(error, {maxDepth: 3})}`;
} | interface Options
extends Omit<RequiredOptions, 'compareKeys' | 'theme'> {
compareKeys: CompareKeys;
theme: Required<RequiredOptions['theme']>;
} |
1,407 | function stackFormatter(
options: Options,
initError: Error | undefined,
errorMessage: string,
) {
if (options.passed) {
return '';
}
if (options.error) {
if (typeof options.error.stack === 'string') {
return options.error.stack;
}
if (options.error === errorMessage) {
return errorMessage;
}
}
if (initError) {
return `${errorMessage.trimRight()}\n\n${initError.stack}`;
}
return new Error(errorMessage).stack;
} | interface Options
extends ShouldInstrumentOptions,
CallerTransformOptions {
isInternalModule?: boolean;
} |
1,408 | function stackFormatter(
options: Options,
initError: Error | undefined,
errorMessage: string,
) {
if (options.passed) {
return '';
}
if (options.error) {
if (typeof options.error.stack === 'string') {
return options.error.stack;
}
if (options.error === errorMessage) {
return errorMessage;
}
}
if (initError) {
return `${errorMessage.trimRight()}\n\n${initError.stack}`;
}
return new Error(errorMessage).stack;
} | type Options = {
clearTimeout: (typeof globalThis)['clearTimeout'];
fail: (error: Error) => void;
onException: (error: Error) => void;
queueableFns: Array<QueueableFn>;
setTimeout: (typeof globalThis)['setTimeout'];
userContext: unknown;
}; |
1,409 | function stackFormatter(
options: Options,
initError: Error | undefined,
errorMessage: string,
) {
if (options.passed) {
return '';
}
if (options.error) {
if (typeof options.error.stack === 'string') {
return options.error.stack;
}
if (options.error === errorMessage) {
return errorMessage;
}
}
if (initError) {
return `${errorMessage.trimRight()}\n\n${initError.stack}`;
}
return new Error(errorMessage).stack;
} | type Options = {
matcherName: string;
passed: boolean;
actual?: any;
error?: any;
expected?: any;
message?: string | null;
}; |
1,410 | function stackFormatter(
options: Options,
initError: Error | undefined,
errorMessage: string,
) {
if (options.passed) {
return '';
}
if (options.error) {
if (typeof options.error.stack === 'string') {
return options.error.stack;
}
if (options.error === errorMessage) {
return errorMessage;
}
}
if (initError) {
return `${errorMessage.trimRight()}\n\n${initError.stack}`;
}
return new Error(errorMessage).stack;
} | type Options = {
nodeComplete: (suite: TreeNode) => void;
nodeStart: (suite: TreeNode) => void;
queueRunnerFactory: any;
runnableIds: Array<string>;
tree: TreeNode;
}; |
1,411 | function stackFormatter(
options: Options,
initError: Error | undefined,
errorMessage: string,
) {
if (options.passed) {
return '';
}
if (options.error) {
if (typeof options.error.stack === 'string') {
return options.error.stack;
}
if (options.error === errorMessage) {
return errorMessage;
}
}
if (initError) {
return `${errorMessage.trimRight()}\n\n${initError.stack}`;
}
return new Error(errorMessage).stack;
} | type Options = {
lastCommit?: boolean;
withAncestor?: boolean;
changedSince?: string;
includePaths?: Array<string>;
}; |
1,412 | function stackFormatter(
options: Options,
initError: Error | undefined,
errorMessage: string,
) {
if (options.passed) {
return '';
}
if (options.error) {
if (typeof options.error.stack === 'string') {
return options.error.stack;
}
if (options.error === errorMessage) {
return errorMessage;
}
}
if (initError) {
return `${errorMessage.trimRight()}\n\n${initError.stack}`;
}
return new Error(errorMessage).stack;
} | type Options = {
cacheDirectory?: string;
computeDependencies?: boolean;
computeSha1?: boolean;
console?: Console;
dependencyExtractor?: string | null;
enableSymlinks?: boolean;
extensions: Array<string>;
forceNodeFilesystemAPI?: boolean;
hasteImplModulePath?: string;
hasteMapModulePath?: string;
id: string;
ignorePattern?: HasteRegExp;
maxWorkers: number;
mocksPattern?: string;
platforms: Array<string>;
resetCache?: boolean;
retainAllFiles: boolean;
rootDir: string;
roots: Array<string>;
skipPackageJson?: boolean;
throwOnModuleCollision?: boolean;
useWatchman?: boolean;
watch?: boolean;
}; |
1,413 | function stackFormatter(
options: Options,
initError: Error | undefined,
errorMessage: string,
) {
if (options.passed) {
return '';
}
if (options.error) {
if (typeof options.error.stack === 'string') {
return options.error.stack;
}
if (options.error === errorMessage) {
return errorMessage;
}
}
if (initError) {
return `${errorMessage.trimRight()}\n\n${initError.stack}`;
}
return new Error(errorMessage).stack;
} | interface Options
extends Omit<RequiredOptions, 'compareKeys' | 'theme'> {
compareKeys: CompareKeys;
theme: Required<RequiredOptions['theme']>;
} |
1,414 | function expectationResultFactory(
options: Options,
initError?: Error,
): FailedAssertion {
const message = messageFormatter(options);
const stack = stackFormatter(options, initError, message);
if (options.passed) {
return {
error: options.error,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
}
return {
actual: options.actual,
error: options.error,
expected: options.expected,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
} | interface Options
extends ShouldInstrumentOptions,
CallerTransformOptions {
isInternalModule?: boolean;
} |
1,415 | function expectationResultFactory(
options: Options,
initError?: Error,
): FailedAssertion {
const message = messageFormatter(options);
const stack = stackFormatter(options, initError, message);
if (options.passed) {
return {
error: options.error,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
}
return {
actual: options.actual,
error: options.error,
expected: options.expected,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
} | type Options = {
clearTimeout: (typeof globalThis)['clearTimeout'];
fail: (error: Error) => void;
onException: (error: Error) => void;
queueableFns: Array<QueueableFn>;
setTimeout: (typeof globalThis)['setTimeout'];
userContext: unknown;
}; |
1,416 | function expectationResultFactory(
options: Options,
initError?: Error,
): FailedAssertion {
const message = messageFormatter(options);
const stack = stackFormatter(options, initError, message);
if (options.passed) {
return {
error: options.error,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
}
return {
actual: options.actual,
error: options.error,
expected: options.expected,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
} | type Options = {
matcherName: string;
passed: boolean;
actual?: any;
error?: any;
expected?: any;
message?: string | null;
}; |
1,417 | function expectationResultFactory(
options: Options,
initError?: Error,
): FailedAssertion {
const message = messageFormatter(options);
const stack = stackFormatter(options, initError, message);
if (options.passed) {
return {
error: options.error,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
}
return {
actual: options.actual,
error: options.error,
expected: options.expected,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
} | type Options = {
nodeComplete: (suite: TreeNode) => void;
nodeStart: (suite: TreeNode) => void;
queueRunnerFactory: any;
runnableIds: Array<string>;
tree: TreeNode;
}; |
1,418 | function expectationResultFactory(
options: Options,
initError?: Error,
): FailedAssertion {
const message = messageFormatter(options);
const stack = stackFormatter(options, initError, message);
if (options.passed) {
return {
error: options.error,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
}
return {
actual: options.actual,
error: options.error,
expected: options.expected,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
} | type Options = {
lastCommit?: boolean;
withAncestor?: boolean;
changedSince?: string;
includePaths?: Array<string>;
}; |
1,419 | function expectationResultFactory(
options: Options,
initError?: Error,
): FailedAssertion {
const message = messageFormatter(options);
const stack = stackFormatter(options, initError, message);
if (options.passed) {
return {
error: options.error,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
}
return {
actual: options.actual,
error: options.error,
expected: options.expected,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
} | type Options = {
cacheDirectory?: string;
computeDependencies?: boolean;
computeSha1?: boolean;
console?: Console;
dependencyExtractor?: string | null;
enableSymlinks?: boolean;
extensions: Array<string>;
forceNodeFilesystemAPI?: boolean;
hasteImplModulePath?: string;
hasteMapModulePath?: string;
id: string;
ignorePattern?: HasteRegExp;
maxWorkers: number;
mocksPattern?: string;
platforms: Array<string>;
resetCache?: boolean;
retainAllFiles: boolean;
rootDir: string;
roots: Array<string>;
skipPackageJson?: boolean;
throwOnModuleCollision?: boolean;
useWatchman?: boolean;
watch?: boolean;
}; |
1,420 | function expectationResultFactory(
options: Options,
initError?: Error,
): FailedAssertion {
const message = messageFormatter(options);
const stack = stackFormatter(options, initError, message);
if (options.passed) {
return {
error: options.error,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
}
return {
actual: options.actual,
error: options.error,
expected: options.expected,
matcherName: options.matcherName,
message,
passed: options.passed,
stack,
};
} | interface Options
extends Omit<RequiredOptions, 'compareKeys' | 'theme'> {
compareKeys: CompareKeys;
theme: Required<RequiredOptions['theme']>;
} |
1,421 | (result: SpecResult) => {
const {suppressedErrors} = jestExpect.getState();
jestExpect.setState({suppressedErrors: []});
if (suppressedErrors.length) {
result.status = 'failed';
result.failedExpectations = suppressedErrors.map(error => ({
actual: '',
// passing error for custom test reporters
error,
expected: '',
matcherName: '',
message: error.message,
passed: false,
stack: error.stack,
}));
}
} | type SpecResult = {
id: string;
description: string;
fullName: string;
duration?: number;
failedExpectations: Array<FailedAssertion>;
testPath: string;
passedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
pendingReason: string;
status: Status;
__callsite?: {
getColumnNumber: () => number;
getLineNumber: () => number;
};
}; |
1,422 | (result: SpecResult) => {
const assertionErrors = jestExpect.extractExpectedAssertionsErrors();
if (assertionErrors.length) {
const jasmineErrors = assertionErrors.map(({actual, error, expected}) => ({
actual,
expected,
message: error.stack,
passed: false,
}));
result.status = 'failed';
result.failedExpectations = result.failedExpectations.concat(jasmineErrors);
}
} | type SpecResult = {
id: string;
description: string;
fullName: string;
duration?: number;
failedExpectations: Array<FailedAssertion>;
testPath: string;
passedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
pendingReason: string;
status: Status;
__callsite?: {
getColumnNumber: () => number;
getLineNumber: () => number;
};
}; |
1,423 | constructor(attr: Attributes) {
const resultCallback = attr.resultCallback;
attr.resultCallback = function (result: SpecResult) {
addSuppressedErrors(result);
addAssertionErrors(result);
resultCallback.call(attr, result);
};
const onStart = attr.onStart;
attr.onStart = (context: JasmineSpec) => {
jestExpect.setState({currentTestName: context.getFullName()});
onStart && onStart.call(attr, context);
};
super(attr);
} | type Attributes = {
id: string;
parentSuite?: Suite;
description: Circus.TestNameLike;
throwOnExpectationFailure?: boolean;
getTestPath: () => string;
}; |
1,424 | constructor(attr: Attributes) {
const resultCallback = attr.resultCallback;
attr.resultCallback = function (result: SpecResult) {
addSuppressedErrors(result);
addAssertionErrors(result);
resultCallback.call(attr, result);
};
const onStart = attr.onStart;
attr.onStart = (context: JasmineSpec) => {
jestExpect.setState({currentTestName: context.getFullName()});
onStart && onStart.call(attr, context);
};
super(attr);
} | type Attributes = {
id: string;
resultCallback: (result: Spec['result']) => void;
description: Circus.TestNameLike;
throwOnExpectationFailure: unknown;
getTestPath: () => string;
queueableFn: QueueableFn;
beforeAndAfterFns: () => {
befores: Array<QueueableFn>;
afters: Array<QueueableFn>;
};
userContext: () => unknown;
onStart: (context: Spec) => void;
getSpecName: (spec: Spec) => string;
queueRunnerFactory: typeof queueRunner;
}; |
1,425 | function (result: SpecResult) {
addSuppressedErrors(result);
addAssertionErrors(result);
resultCallback.call(attr, result);
} | type SpecResult = {
id: string;
description: string;
fullName: string;
duration?: number;
failedExpectations: Array<FailedAssertion>;
testPath: string;
passedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
pendingReason: string;
status: Status;
__callsite?: {
getColumnNumber: () => number;
getLineNumber: () => number;
};
}; |
1,426 | async function setupJestGlobals({
config,
globalConfig,
localRequire,
testPath,
}: SetupOptions): Promise<SnapshotState> {
// 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 {prettierPath, rootDir, snapshotFormat} = config;
const snapshotResolver = await buildSnapshotResolver(config, localRequire);
const snapshotPath = snapshotResolver.resolveSnapshotPath(testPath);
const snapshotState = new SnapshotState(snapshotPath, {
expand,
prettierPath,
rootDir,
snapshotFormat,
updateSnapshot,
});
jestExpect.setState({snapshotState, testPath});
// Return it back to the outer scope (test runner outside the VM).
return snapshotState;
} | type SetupOptions = {
config: Config.ProjectConfig;
globalConfig: Config.GlobalConfig;
localRequire: (moduleName: string) => Plugin;
testPath: string;
}; |
1,427 | function each(environment: JestEnvironment): void {
environment.global.it.each = bindEach(environment.global.it);
environment.global.fit.each = bindEach(environment.global.fit);
environment.global.xit.each = bindEach(environment.global.xit);
environment.global.describe.each = bindEach(
environment.global.describe,
false,
);
environment.global.xdescribe.each = bindEach(
environment.global.xdescribe,
false,
);
environment.global.fdescribe.each = bindEach(
environment.global.fdescribe,
false,
);
environment.global.it.concurrent.each = bindEach(
environment.global.it.concurrent,
false,
);
environment.global.it.concurrent.only.each = bindEach(
environment.global.it.concurrent.only,
false,
);
environment.global.it.concurrent.skip.each = bindEach(
environment.global.it.concurrent.skip,
false,
);
} | class JestEnvironment<Timer = unknown> {
constructor(config: JestEnvironmentConfig, context: EnvironmentContext);
global: Global.Global;
fakeTimers: LegacyFakeTimers<Timer> | null;
fakeTimersModern: ModernFakeTimers | null;
moduleMocker: ModuleMocker | null;
getVmContext(): Context | null;
setup(): Promise<void>;
teardown(): Promise<void>;
handleTestEvent?: Circus.EventHandler;
exportConditions?: () => Array<string>;
} |
1,428 | (suite: TreeNode) => void | type TreeNode = {
afterAllFns: Array<unknown>;
beforeAllFns: Array<unknown>;
disabled?: boolean;
execute: (onComplete: () => void, enabled: boolean) => void;
id: string;
onException: (error: Error) => void;
sharedUserContext: () => unknown;
children?: Array<TreeNode>;
} & Pick<Suite, 'getResult' | 'parentSuite' | 'result' | 'markedPending'>; |
1,429 | function treeProcessor(options: Options): void {
const {nodeComplete, nodeStart, queueRunnerFactory, runnableIds, tree} =
options;
function isEnabled(node: TreeNode, parentEnabled: boolean) {
return parentEnabled || runnableIds.indexOf(node.id) !== -1;
}
function getNodeHandler(node: TreeNode, parentEnabled: boolean) {
const enabled = isEnabled(node, parentEnabled);
return node.children
? getNodeWithChildrenHandler(node, enabled)
: getNodeWithoutChildrenHandler(node, enabled);
}
function getNodeWithoutChildrenHandler(node: TreeNode, enabled: boolean) {
return function fn(done: (error?: unknown) => void = noop) {
node.execute(done, enabled);
};
}
function getNodeWithChildrenHandler(node: TreeNode, enabled: boolean) {
return async function fn(done: (error?: unknown) => void = noop) {
nodeStart(node);
await queueRunnerFactory({
onException: (error: Error) => node.onException(error),
queueableFns: wrapChildren(node, enabled),
userContext: node.sharedUserContext(),
});
nodeComplete(node);
done();
};
}
function hasNoEnabledTest(node: TreeNode): boolean {
return (
node.disabled ||
node.markedPending ||
(node.children?.every(hasNoEnabledTest) ?? false)
);
}
function wrapChildren(node: TreeNode, enabled: boolean) {
if (!node.children) {
throw new Error('`node.children` is not defined.');
}
const children = node.children.map(child => ({
fn: getNodeHandler(child, enabled),
}));
if (hasNoEnabledTest(node)) {
return children;
}
return node.beforeAllFns.concat(children).concat(node.afterAllFns);
}
const treeHandler = getNodeHandler(tree, false);
return treeHandler();
} | interface Options
extends ShouldInstrumentOptions,
CallerTransformOptions {
isInternalModule?: boolean;
} |
1,430 | function treeProcessor(options: Options): void {
const {nodeComplete, nodeStart, queueRunnerFactory, runnableIds, tree} =
options;
function isEnabled(node: TreeNode, parentEnabled: boolean) {
return parentEnabled || runnableIds.indexOf(node.id) !== -1;
}
function getNodeHandler(node: TreeNode, parentEnabled: boolean) {
const enabled = isEnabled(node, parentEnabled);
return node.children
? getNodeWithChildrenHandler(node, enabled)
: getNodeWithoutChildrenHandler(node, enabled);
}
function getNodeWithoutChildrenHandler(node: TreeNode, enabled: boolean) {
return function fn(done: (error?: unknown) => void = noop) {
node.execute(done, enabled);
};
}
function getNodeWithChildrenHandler(node: TreeNode, enabled: boolean) {
return async function fn(done: (error?: unknown) => void = noop) {
nodeStart(node);
await queueRunnerFactory({
onException: (error: Error) => node.onException(error),
queueableFns: wrapChildren(node, enabled),
userContext: node.sharedUserContext(),
});
nodeComplete(node);
done();
};
}
function hasNoEnabledTest(node: TreeNode): boolean {
return (
node.disabled ||
node.markedPending ||
(node.children?.every(hasNoEnabledTest) ?? false)
);
}
function wrapChildren(node: TreeNode, enabled: boolean) {
if (!node.children) {
throw new Error('`node.children` is not defined.');
}
const children = node.children.map(child => ({
fn: getNodeHandler(child, enabled),
}));
if (hasNoEnabledTest(node)) {
return children;
}
return node.beforeAllFns.concat(children).concat(node.afterAllFns);
}
const treeHandler = getNodeHandler(tree, false);
return treeHandler();
} | type Options = {
clearTimeout: (typeof globalThis)['clearTimeout'];
fail: (error: Error) => void;
onException: (error: Error) => void;
queueableFns: Array<QueueableFn>;
setTimeout: (typeof globalThis)['setTimeout'];
userContext: unknown;
}; |
1,431 | function treeProcessor(options: Options): void {
const {nodeComplete, nodeStart, queueRunnerFactory, runnableIds, tree} =
options;
function isEnabled(node: TreeNode, parentEnabled: boolean) {
return parentEnabled || runnableIds.indexOf(node.id) !== -1;
}
function getNodeHandler(node: TreeNode, parentEnabled: boolean) {
const enabled = isEnabled(node, parentEnabled);
return node.children
? getNodeWithChildrenHandler(node, enabled)
: getNodeWithoutChildrenHandler(node, enabled);
}
function getNodeWithoutChildrenHandler(node: TreeNode, enabled: boolean) {
return function fn(done: (error?: unknown) => void = noop) {
node.execute(done, enabled);
};
}
function getNodeWithChildrenHandler(node: TreeNode, enabled: boolean) {
return async function fn(done: (error?: unknown) => void = noop) {
nodeStart(node);
await queueRunnerFactory({
onException: (error: Error) => node.onException(error),
queueableFns: wrapChildren(node, enabled),
userContext: node.sharedUserContext(),
});
nodeComplete(node);
done();
};
}
function hasNoEnabledTest(node: TreeNode): boolean {
return (
node.disabled ||
node.markedPending ||
(node.children?.every(hasNoEnabledTest) ?? false)
);
}
function wrapChildren(node: TreeNode, enabled: boolean) {
if (!node.children) {
throw new Error('`node.children` is not defined.');
}
const children = node.children.map(child => ({
fn: getNodeHandler(child, enabled),
}));
if (hasNoEnabledTest(node)) {
return children;
}
return node.beforeAllFns.concat(children).concat(node.afterAllFns);
}
const treeHandler = getNodeHandler(tree, false);
return treeHandler();
} | type Options = {
matcherName: string;
passed: boolean;
actual?: any;
error?: any;
expected?: any;
message?: string | null;
}; |
1,432 | function treeProcessor(options: Options): void {
const {nodeComplete, nodeStart, queueRunnerFactory, runnableIds, tree} =
options;
function isEnabled(node: TreeNode, parentEnabled: boolean) {
return parentEnabled || runnableIds.indexOf(node.id) !== -1;
}
function getNodeHandler(node: TreeNode, parentEnabled: boolean) {
const enabled = isEnabled(node, parentEnabled);
return node.children
? getNodeWithChildrenHandler(node, enabled)
: getNodeWithoutChildrenHandler(node, enabled);
}
function getNodeWithoutChildrenHandler(node: TreeNode, enabled: boolean) {
return function fn(done: (error?: unknown) => void = noop) {
node.execute(done, enabled);
};
}
function getNodeWithChildrenHandler(node: TreeNode, enabled: boolean) {
return async function fn(done: (error?: unknown) => void = noop) {
nodeStart(node);
await queueRunnerFactory({
onException: (error: Error) => node.onException(error),
queueableFns: wrapChildren(node, enabled),
userContext: node.sharedUserContext(),
});
nodeComplete(node);
done();
};
}
function hasNoEnabledTest(node: TreeNode): boolean {
return (
node.disabled ||
node.markedPending ||
(node.children?.every(hasNoEnabledTest) ?? false)
);
}
function wrapChildren(node: TreeNode, enabled: boolean) {
if (!node.children) {
throw new Error('`node.children` is not defined.');
}
const children = node.children.map(child => ({
fn: getNodeHandler(child, enabled),
}));
if (hasNoEnabledTest(node)) {
return children;
}
return node.beforeAllFns.concat(children).concat(node.afterAllFns);
}
const treeHandler = getNodeHandler(tree, false);
return treeHandler();
} | type Options = {
nodeComplete: (suite: TreeNode) => void;
nodeStart: (suite: TreeNode) => void;
queueRunnerFactory: any;
runnableIds: Array<string>;
tree: TreeNode;
}; |
1,433 | function treeProcessor(options: Options): void {
const {nodeComplete, nodeStart, queueRunnerFactory, runnableIds, tree} =
options;
function isEnabled(node: TreeNode, parentEnabled: boolean) {
return parentEnabled || runnableIds.indexOf(node.id) !== -1;
}
function getNodeHandler(node: TreeNode, parentEnabled: boolean) {
const enabled = isEnabled(node, parentEnabled);
return node.children
? getNodeWithChildrenHandler(node, enabled)
: getNodeWithoutChildrenHandler(node, enabled);
}
function getNodeWithoutChildrenHandler(node: TreeNode, enabled: boolean) {
return function fn(done: (error?: unknown) => void = noop) {
node.execute(done, enabled);
};
}
function getNodeWithChildrenHandler(node: TreeNode, enabled: boolean) {
return async function fn(done: (error?: unknown) => void = noop) {
nodeStart(node);
await queueRunnerFactory({
onException: (error: Error) => node.onException(error),
queueableFns: wrapChildren(node, enabled),
userContext: node.sharedUserContext(),
});
nodeComplete(node);
done();
};
}
function hasNoEnabledTest(node: TreeNode): boolean {
return (
node.disabled ||
node.markedPending ||
(node.children?.every(hasNoEnabledTest) ?? false)
);
}
function wrapChildren(node: TreeNode, enabled: boolean) {
if (!node.children) {
throw new Error('`node.children` is not defined.');
}
const children = node.children.map(child => ({
fn: getNodeHandler(child, enabled),
}));
if (hasNoEnabledTest(node)) {
return children;
}
return node.beforeAllFns.concat(children).concat(node.afterAllFns);
}
const treeHandler = getNodeHandler(tree, false);
return treeHandler();
} | type Options = {
lastCommit?: boolean;
withAncestor?: boolean;
changedSince?: string;
includePaths?: Array<string>;
}; |
1,434 | function treeProcessor(options: Options): void {
const {nodeComplete, nodeStart, queueRunnerFactory, runnableIds, tree} =
options;
function isEnabled(node: TreeNode, parentEnabled: boolean) {
return parentEnabled || runnableIds.indexOf(node.id) !== -1;
}
function getNodeHandler(node: TreeNode, parentEnabled: boolean) {
const enabled = isEnabled(node, parentEnabled);
return node.children
? getNodeWithChildrenHandler(node, enabled)
: getNodeWithoutChildrenHandler(node, enabled);
}
function getNodeWithoutChildrenHandler(node: TreeNode, enabled: boolean) {
return function fn(done: (error?: unknown) => void = noop) {
node.execute(done, enabled);
};
}
function getNodeWithChildrenHandler(node: TreeNode, enabled: boolean) {
return async function fn(done: (error?: unknown) => void = noop) {
nodeStart(node);
await queueRunnerFactory({
onException: (error: Error) => node.onException(error),
queueableFns: wrapChildren(node, enabled),
userContext: node.sharedUserContext(),
});
nodeComplete(node);
done();
};
}
function hasNoEnabledTest(node: TreeNode): boolean {
return (
node.disabled ||
node.markedPending ||
(node.children?.every(hasNoEnabledTest) ?? false)
);
}
function wrapChildren(node: TreeNode, enabled: boolean) {
if (!node.children) {
throw new Error('`node.children` is not defined.');
}
const children = node.children.map(child => ({
fn: getNodeHandler(child, enabled),
}));
if (hasNoEnabledTest(node)) {
return children;
}
return node.beforeAllFns.concat(children).concat(node.afterAllFns);
}
const treeHandler = getNodeHandler(tree, false);
return treeHandler();
} | type Options = {
cacheDirectory?: string;
computeDependencies?: boolean;
computeSha1?: boolean;
console?: Console;
dependencyExtractor?: string | null;
enableSymlinks?: boolean;
extensions: Array<string>;
forceNodeFilesystemAPI?: boolean;
hasteImplModulePath?: string;
hasteMapModulePath?: string;
id: string;
ignorePattern?: HasteRegExp;
maxWorkers: number;
mocksPattern?: string;
platforms: Array<string>;
resetCache?: boolean;
retainAllFiles: boolean;
rootDir: string;
roots: Array<string>;
skipPackageJson?: boolean;
throwOnModuleCollision?: boolean;
useWatchman?: boolean;
watch?: boolean;
}; |
1,435 | function treeProcessor(options: Options): void {
const {nodeComplete, nodeStart, queueRunnerFactory, runnableIds, tree} =
options;
function isEnabled(node: TreeNode, parentEnabled: boolean) {
return parentEnabled || runnableIds.indexOf(node.id) !== -1;
}
function getNodeHandler(node: TreeNode, parentEnabled: boolean) {
const enabled = isEnabled(node, parentEnabled);
return node.children
? getNodeWithChildrenHandler(node, enabled)
: getNodeWithoutChildrenHandler(node, enabled);
}
function getNodeWithoutChildrenHandler(node: TreeNode, enabled: boolean) {
return function fn(done: (error?: unknown) => void = noop) {
node.execute(done, enabled);
};
}
function getNodeWithChildrenHandler(node: TreeNode, enabled: boolean) {
return async function fn(done: (error?: unknown) => void = noop) {
nodeStart(node);
await queueRunnerFactory({
onException: (error: Error) => node.onException(error),
queueableFns: wrapChildren(node, enabled),
userContext: node.sharedUserContext(),
});
nodeComplete(node);
done();
};
}
function hasNoEnabledTest(node: TreeNode): boolean {
return (
node.disabled ||
node.markedPending ||
(node.children?.every(hasNoEnabledTest) ?? false)
);
}
function wrapChildren(node: TreeNode, enabled: boolean) {
if (!node.children) {
throw new Error('`node.children` is not defined.');
}
const children = node.children.map(child => ({
fn: getNodeHandler(child, enabled),
}));
if (hasNoEnabledTest(node)) {
return children;
}
return node.beforeAllFns.concat(children).concat(node.afterAllFns);
}
const treeHandler = getNodeHandler(tree, false);
return treeHandler();
} | interface Options
extends Omit<RequiredOptions, 'compareKeys' | 'theme'> {
compareKeys: CompareKeys;
theme: Required<RequiredOptions['theme']>;
} |
1,436 | function isEnabled(node: TreeNode, parentEnabled: boolean) {
return parentEnabled || runnableIds.indexOf(node.id) !== -1;
} | type TreeNode = {
afterAllFns: Array<unknown>;
beforeAllFns: Array<unknown>;
disabled?: boolean;
execute: (onComplete: () => void, enabled: boolean) => void;
id: string;
onException: (error: Error) => void;
sharedUserContext: () => unknown;
children?: Array<TreeNode>;
} & Pick<Suite, 'getResult' | 'parentSuite' | 'result' | 'markedPending'>; |
1,437 | function getNodeHandler(node: TreeNode, parentEnabled: boolean) {
const enabled = isEnabled(node, parentEnabled);
return node.children
? getNodeWithChildrenHandler(node, enabled)
: getNodeWithoutChildrenHandler(node, enabled);
} | type TreeNode = {
afterAllFns: Array<unknown>;
beforeAllFns: Array<unknown>;
disabled?: boolean;
execute: (onComplete: () => void, enabled: boolean) => void;
id: string;
onException: (error: Error) => void;
sharedUserContext: () => unknown;
children?: Array<TreeNode>;
} & Pick<Suite, 'getResult' | 'parentSuite' | 'result' | 'markedPending'>; |
1,438 | function getNodeWithoutChildrenHandler(node: TreeNode, enabled: boolean) {
return function fn(done: (error?: unknown) => void = noop) {
node.execute(done, enabled);
};
} | type TreeNode = {
afterAllFns: Array<unknown>;
beforeAllFns: Array<unknown>;
disabled?: boolean;
execute: (onComplete: () => void, enabled: boolean) => void;
id: string;
onException: (error: Error) => void;
sharedUserContext: () => unknown;
children?: Array<TreeNode>;
} & Pick<Suite, 'getResult' | 'parentSuite' | 'result' | 'markedPending'>; |
1,439 | function getNodeWithChildrenHandler(node: TreeNode, enabled: boolean) {
return async function fn(done: (error?: unknown) => void = noop) {
nodeStart(node);
await queueRunnerFactory({
onException: (error: Error) => node.onException(error),
queueableFns: wrapChildren(node, enabled),
userContext: node.sharedUserContext(),
});
nodeComplete(node);
done();
};
} | type TreeNode = {
afterAllFns: Array<unknown>;
beforeAllFns: Array<unknown>;
disabled?: boolean;
execute: (onComplete: () => void, enabled: boolean) => void;
id: string;
onException: (error: Error) => void;
sharedUserContext: () => unknown;
children?: Array<TreeNode>;
} & Pick<Suite, 'getResult' | 'parentSuite' | 'result' | 'markedPending'>; |
1,440 | function hasNoEnabledTest(node: TreeNode): boolean {
return (
node.disabled ||
node.markedPending ||
(node.children?.every(hasNoEnabledTest) ?? false)
);
} | type TreeNode = {
afterAllFns: Array<unknown>;
beforeAllFns: Array<unknown>;
disabled?: boolean;
execute: (onComplete: () => void, enabled: boolean) => void;
id: string;
onException: (error: Error) => void;
sharedUserContext: () => unknown;
children?: Array<TreeNode>;
} & Pick<Suite, 'getResult' | 'parentSuite' | 'result' | 'markedPending'>; |
1,441 | function wrapChildren(node: TreeNode, enabled: boolean) {
if (!node.children) {
throw new Error('`node.children` is not defined.');
}
const children = node.children.map(child => ({
fn: getNodeHandler(child, enabled),
}));
if (hasNoEnabledTest(node)) {
return children;
}
return node.beforeAllFns.concat(children).concat(node.afterAllFns);
} | type TreeNode = {
afterAllFns: Array<unknown>;
beforeAllFns: Array<unknown>;
disabled?: boolean;
execute: (onComplete: () => void, enabled: boolean) => void;
id: string;
onException: (error: Error) => void;
sharedUserContext: () => unknown;
children?: Array<TreeNode>;
} & Pick<Suite, 'getResult' | 'parentSuite' | 'result' | 'markedPending'>; |
1,442 | (done: DoneFn) => void | PromiseLike<T> | interface DoneFn {
(error?: any): void;
fail: (error: Error) => void;
} |
1,443 | (done: DoneFn) => void | PromiseLike<T> | type DoneFn = (reason?: string | Error) => void; |
1,444 | (done: DoneFn) => void | PromiseLike<T> | type DoneFn = Global.DoneFn; |
1,445 | function (done: DoneFn) {
const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn;
// @ts-expect-error: TS thinks `wrappedFn` is a generator function
const returnValue = wrappedFn.call({}, doneFnNoop);
if (isPromise(returnValue)) {
returnValue.then(done.bind(null, null), (error: Error) => {
const {isError: checkIsError, message} = isError(error);
if (message) {
extraError.message = message;
}
done.fail(checkIsError ? error : extraError);
});
} else {
done();
}
} | interface DoneFn {
(error?: any): void;
fail: (error: Error) => void;
} |
1,446 | function (done: DoneFn) {
const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn;
// @ts-expect-error: TS thinks `wrappedFn` is a generator function
const returnValue = wrappedFn.call({}, doneFnNoop);
if (isPromise(returnValue)) {
returnValue.then(done.bind(null, null), (error: Error) => {
const {isError: checkIsError, message} = isError(error);
if (message) {
extraError.message = message;
}
done.fail(checkIsError ? error : extraError);
});
} else {
done();
}
} | type DoneFn = (reason?: string | Error) => void; |
1,447 | function (done: DoneFn) {
const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn;
// @ts-expect-error: TS thinks `wrappedFn` is a generator function
const returnValue = wrappedFn.call({}, doneFnNoop);
if (isPromise(returnValue)) {
returnValue.then(done.bind(null, null), (error: Error) => {
const {isError: checkIsError, message} = isError(error);
if (message) {
extraError.message = message;
}
done.fail(checkIsError ? error : extraError);
});
} else {
done();
}
} | type DoneFn = Global.DoneFn; |
1,448 | (done: DoneFn) => void | PromiseLike<void> | interface DoneFn {
(error?: any): void;
fail: (error: Error) => void;
} |
1,449 | (done: DoneFn) => void | PromiseLike<void> | type DoneFn = (reason?: string | Error) => void; |
1,450 | (done: DoneFn) => void | PromiseLike<void> | type DoneFn = Global.DoneFn; |
1,451 | function (done: DoneFn) {
const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn;
const returnValue = wrappedFn.call({}, doneFnNoop);
if (isPromise(returnValue)) {
returnValue.then(done.bind(null, null), (error: Error) => {
const {isError: checkIsError, message} = isError(error);
if (message) {
extraError.message = message;
}
if (jasmine.Spec.isPendingSpecException(error)) {
env.pending(message!);
done();
} else {
done.fail(checkIsError ? error : extraError);
}
});
} else if (returnValue === undefined) {
done();
} else {
done.fail(
new Error(
'Jest: `it` and `test` must return either a Promise or undefined.',
),
);
}
} | interface DoneFn {
(error?: any): void;
fail: (error: Error) => void;
} |
1,452 | function (done: DoneFn) {
const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn;
const returnValue = wrappedFn.call({}, doneFnNoop);
if (isPromise(returnValue)) {
returnValue.then(done.bind(null, null), (error: Error) => {
const {isError: checkIsError, message} = isError(error);
if (message) {
extraError.message = message;
}
if (jasmine.Spec.isPendingSpecException(error)) {
env.pending(message!);
done();
} else {
done.fail(checkIsError ? error : extraError);
}
});
} else if (returnValue === undefined) {
done();
} else {
done.fail(
new Error(
'Jest: `it` and `test` must return either a Promise or undefined.',
),
);
}
} | type DoneFn = (reason?: string | Error) => void; |
1,453 | function (done: DoneFn) {
const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn;
const returnValue = wrappedFn.call({}, doneFnNoop);
if (isPromise(returnValue)) {
returnValue.then(done.bind(null, null), (error: Error) => {
const {isError: checkIsError, message} = isError(error);
if (message) {
extraError.message = message;
}
if (jasmine.Spec.isPendingSpecException(error)) {
env.pending(message!);
done();
} else {
done.fail(checkIsError ? error : extraError);
}
});
} else if (returnValue === undefined) {
done();
} else {
done.fail(
new Error(
'Jest: `it` and `test` must return either a Promise or undefined.',
),
);
}
} | type DoneFn = Global.DoneFn; |
1,454 | jasmineStarted(_runDetails: RunDetails): void {} | type RunDetails = {
totalSpecsDefined?: number;
failedExpectations?: SuiteResult['failedExpectations'];
}; |
1,455 | specStarted(spec: SpecResult): void {
this._startTimes.set(spec.id, Date.now());
} | type SpecResult = {
id: string;
description: string;
fullName: string;
duration?: number;
failedExpectations: Array<FailedAssertion>;
testPath: string;
passedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
pendingReason: string;
status: Status;
__callsite?: {
getColumnNumber: () => number;
getLineNumber: () => number;
};
}; |
1,456 | specDone(result: SpecResult): void {
this._testResults.push(
this._extractSpecResults(result, this._currentSuites.slice(0)),
);
} | type SpecResult = {
id: string;
description: string;
fullName: string;
duration?: number;
failedExpectations: Array<FailedAssertion>;
testPath: string;
passedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
pendingReason: string;
status: Status;
__callsite?: {
getColumnNumber: () => number;
getLineNumber: () => number;
};
}; |
1,457 | suiteStarted(suite: SuiteResult): void {
this._currentSuites.push(suite.description);
} | type SuiteResult = {
id: string;
description: string;
fullName: string;
failedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
testPath: string;
status?: string;
}; |
1,458 | suiteDone(_result: SuiteResult): void {
this._currentSuites.pop();
} | type SuiteResult = {
id: string;
description: string;
fullName: string;
failedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
testPath: string;
status?: string;
}; |
1,459 | jasmineDone(_runDetails: RunDetails): void {
let numFailingTests = 0;
let numPassingTests = 0;
let numPendingTests = 0;
let numTodoTests = 0;
const testResults = this._testResults;
testResults.forEach(testResult => {
if (testResult.status === 'failed') {
numFailingTests++;
} else if (testResult.status === 'pending') {
numPendingTests++;
} else if (testResult.status === 'todo') {
numTodoTests++;
} else {
numPassingTests++;
}
});
const testResult = {
...createEmptyTestResult(),
console: null,
failureMessage: formatResultsErrors(
testResults,
this._config,
this._globalConfig,
this._testPath,
),
numFailingTests,
numPassingTests,
numPendingTests,
numTodoTests,
snapshot: {
added: 0,
fileDeleted: false,
matched: 0,
unchecked: 0,
unmatched: 0,
updated: 0,
},
testFilePath: this._testPath,
testResults,
};
this._resolve(testResult);
} | type RunDetails = {
totalSpecsDefined?: number;
failedExpectations?: SuiteResult['failedExpectations'];
}; |
1,460 | private _extractSpecResults(
specResult: SpecResult,
ancestorTitles: Array<string>,
): AssertionResult {
const status =
specResult.status === 'disabled' ? 'pending' : specResult.status;
const start = this._startTimes.get(specResult.id);
const duration =
start && !['pending', 'skipped'].includes(status)
? Date.now() - start
: null;
const location = specResult.__callsite
? {
column: specResult.__callsite.getColumnNumber(),
line: specResult.__callsite.getLineNumber(),
}
: null;
const results: AssertionResult = {
ancestorTitles,
duration,
failureDetails: [],
failureMessages: [],
fullName: specResult.fullName,
location,
numPassingAsserts: 0, // Jasmine2 only returns an array of failed asserts.
status,
title: specResult.description,
};
specResult.failedExpectations.forEach(failed => {
const message =
!failed.matcherName && typeof failed.stack === 'string'
? this._addMissingMessageToStack(failed.stack, failed.message)
: failed.message || '';
results.failureMessages.push(message);
results.failureDetails.push(failed);
});
return results;
} | type SpecResult = {
id: string;
description: string;
fullName: string;
duration?: number;
failedExpectations: Array<FailedAssertion>;
testPath: string;
passedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
pendingReason: string;
status: Status;
__callsite?: {
getColumnNumber: () => number;
getLineNumber: () => number;
};
}; |
1,461 | function assertionErrorMessage(
error: AssertionErrorWithStack,
options: DiffOptions,
): string {
const {expected, actual, generatedMessage, message, operator, stack} = error;
const diffString = diff(expected, actual, options);
const hasCustomMessage = !generatedMessage;
const operatorName = getOperatorName(operator, stack);
const trimmedStack = stack
.replace(message, '')
.replace(/AssertionError(.*)/g, '');
if (operatorName === 'doesNotThrow') {
return `${
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset('Expected the function not to throw an error.\n') +
chalk.reset('Instead, it threw:\n')
} ${printReceived(actual)}${chalk.reset(
hasCustomMessage ? `\n\nMessage:\n ${message}` : '',
)}${trimmedStack}`;
}
if (operatorName === 'throws') {
if (error.generatedMessage) {
return (
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset(error.message) +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}
return (
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset('Expected the function to throw an error.\n') +
chalk.reset("But it didn't throw anything.") +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}
if (operatorName === 'fail') {
return (
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
chalk.reset(hasCustomMessage ? `Message:\n ${message}` : '') +
trimmedStack
);
}
return `${
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
chalk.reset(`Expected value ${operatorMessage(operator)}`)
} ${printExpected(expected)}\n${chalk.reset('Received:\n')} ${printReceived(
actual,
)}${chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '')}${
diffString ? `\n\nDifference:\n\n${diffString}` : ''
}${trimmedStack}`;
} | type DiffOptions = {
aAnnotation?: string;
aColor?: DiffOptionsColor;
aIndicator?: string;
bAnnotation?: string;
bColor?: DiffOptionsColor;
bIndicator?: string;
changeColor?: DiffOptionsColor;
changeLineTrailingSpaceColor?: DiffOptionsColor;
commonColor?: DiffOptionsColor;
commonIndicator?: string;
commonLineTrailingSpaceColor?: DiffOptionsColor;
contextLines?: number;
emptyFirstOrLastLinePlaceholder?: string;
expand?: boolean;
includeChangeCounts?: boolean;
omitAnnotationLines?: boolean;
patchColor?: DiffOptionsColor;
compareKeys?: CompareKeys;
}; |
1,462 | function assertionErrorMessage(
error: AssertionErrorWithStack,
options: DiffOptions,
): string {
const {expected, actual, generatedMessage, message, operator, stack} = error;
const diffString = diff(expected, actual, options);
const hasCustomMessage = !generatedMessage;
const operatorName = getOperatorName(operator, stack);
const trimmedStack = stack
.replace(message, '')
.replace(/AssertionError(.*)/g, '');
if (operatorName === 'doesNotThrow') {
return `${
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset('Expected the function not to throw an error.\n') +
chalk.reset('Instead, it threw:\n')
} ${printReceived(actual)}${chalk.reset(
hasCustomMessage ? `\n\nMessage:\n ${message}` : '',
)}${trimmedStack}`;
}
if (operatorName === 'throws') {
if (error.generatedMessage) {
return (
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset(error.message) +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}
return (
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset('Expected the function to throw an error.\n') +
chalk.reset("But it didn't throw anything.") +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}
if (operatorName === 'fail') {
return (
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
chalk.reset(hasCustomMessage ? `Message:\n ${message}` : '') +
trimmedStack
);
}
return `${
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
chalk.reset(`Expected value ${operatorMessage(operator)}`)
} ${printExpected(expected)}\n${chalk.reset('Received:\n')} ${printReceived(
actual,
)}${chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '')}${
diffString ? `\n\nDifference:\n\n${diffString}` : ''
}${trimmedStack}`;
} | type DiffOptions = ImportDiffOptions; |
1,463 | function assertionErrorMessage(
error: AssertionErrorWithStack,
options: DiffOptions,
): string {
const {expected, actual, generatedMessage, message, operator, stack} = error;
const diffString = diff(expected, actual, options);
const hasCustomMessage = !generatedMessage;
const operatorName = getOperatorName(operator, stack);
const trimmedStack = stack
.replace(message, '')
.replace(/AssertionError(.*)/g, '');
if (operatorName === 'doesNotThrow') {
return `${
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset('Expected the function not to throw an error.\n') +
chalk.reset('Instead, it threw:\n')
} ${printReceived(actual)}${chalk.reset(
hasCustomMessage ? `\n\nMessage:\n ${message}` : '',
)}${trimmedStack}`;
}
if (operatorName === 'throws') {
if (error.generatedMessage) {
return (
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset(error.message) +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}
return (
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset('Expected the function to throw an error.\n') +
chalk.reset("But it didn't throw anything.") +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}
if (operatorName === 'fail') {
return (
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
chalk.reset(hasCustomMessage ? `Message:\n ${message}` : '') +
trimmedStack
);
}
return `${
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
chalk.reset(`Expected value ${operatorMessage(operator)}`)
} ${printExpected(expected)}\n${chalk.reset('Received:\n')} ${printReceived(
actual,
)}${chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '')}${
diffString ? `\n\nDifference:\n\n${diffString}` : ''
}${trimmedStack}`;
} | interface AssertionErrorWithStack extends AssertionError {
stack: string;
} |
1,464 | function assertionErrorMessage(
error: AssertionErrorWithStack,
options: DiffOptions,
): string {
const {expected, actual, generatedMessage, message, operator, stack} = error;
const diffString = diff(expected, actual, options);
const hasCustomMessage = !generatedMessage;
const operatorName = getOperatorName(operator, stack);
const trimmedStack = stack
.replace(message, '')
.replace(/AssertionError(.*)/g, '');
if (operatorName === 'doesNotThrow') {
return `${
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset('Expected the function not to throw an error.\n') +
chalk.reset('Instead, it threw:\n')
} ${printReceived(actual)}${chalk.reset(
hasCustomMessage ? `\n\nMessage:\n ${message}` : '',
)}${trimmedStack}`;
}
if (operatorName === 'throws') {
if (error.generatedMessage) {
return (
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset(error.message) +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}
return (
buildHintString(assertThrowingMatcherHint(operatorName)) +
chalk.reset('Expected the function to throw an error.\n') +
chalk.reset("But it didn't throw anything.") +
chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') +
trimmedStack
);
}
if (operatorName === 'fail') {
return (
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
chalk.reset(hasCustomMessage ? `Message:\n ${message}` : '') +
trimmedStack
);
}
return `${
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
chalk.reset(`Expected value ${operatorMessage(operator)}`)
} ${printExpected(expected)}\n${chalk.reset('Received:\n')} ${printReceived(
actual,
)}${chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '')}${
diffString ? `\n\nDifference:\n\n${diffString}` : ''
}${trimmedStack}`;
} | interface AssertionErrorWithStack extends AssertionError {
stack: string;
} |
1,465 | (reporter: Reporter) => void | type Reporter = {
jasmineDone: (runDetails: RunDetails) => void;
jasmineStarted: (runDetails: RunDetails) => void;
specDone: (result: SpecResult) => void;
specStarted: (spec: SpecResult) => void;
suiteDone: (result: SuiteResult) => void;
suiteStarted: (result: SuiteResult) => void;
}; |
1,466 | (reporter: Reporter) => void | interface Reporter {
readonly onTestResult?: (
test: Test,
testResult: TestResult,
aggregatedResult: AggregatedResult,
) => Promise<void> | void;
readonly onTestFileResult?: (
test: Test,
testResult: TestResult,
aggregatedResult: AggregatedResult,
) => Promise<void> | void;
readonly onTestCaseResult?: (
test: Test,
testCaseResult: TestCaseResult,
) => Promise<void> | void;
readonly onRunStart: (
results: AggregatedResult,
options: ReporterOnStartOptions,
) => Promise<void> | void;
readonly onTestStart?: (test: Test) => Promise<void> | void;
readonly onTestFileStart?: (test: Test) => Promise<void> | void;
readonly onRunComplete: (
testContexts: Set<TestContext>,
results: AggregatedResult,
) => Promise<void> | void;
readonly getLastError: () => Error | void;
} |
1,467 | (context: Context) => void | type Context = {
object: unknown;
args: Array<unknown>;
returnValue?: unknown;
}; |
1,468 | (context: Context) => void | interface Context extends MatcherContext {
snapshotState: SnapshotState;
} |
1,469 | function (context: Context) {
calls.push(context);
} | type Context = {
object: unknown;
args: Array<unknown>;
returnValue?: unknown;
}; |
1,470 | function (context: Context) {
calls.push(context);
} | interface Context extends MatcherContext {
snapshotState: SnapshotState;
} |
1,471 | function jasmineEnv(j$: Jasmine) {
return class Env {
specFilter: (spec: Spec) => boolean;
catchExceptions: (value: unknown) => boolean;
throwOnExpectationFailure: (value: unknown) => void;
catchingExceptions: () => boolean;
topSuite: () => Suite;
fail: (error: Error | AssertionErrorWithStack) => void;
pending: (message: string) => void;
afterAll: (afterAllFunction: QueueableFn['fn'], timeout?: number) => void;
fit: (
description: Circus.TestNameLike,
fn: QueueableFn['fn'],
timeout?: number,
) => Spec;
throwingExpectationFailures: () => boolean;
randomizeTests: (value: unknown) => void;
randomTests: () => boolean;
seed: (value: unknown) => unknown;
execute: (
runnablesToRun?: Array<string>,
suiteTree?: Suite,
) => Promise<void>;
fdescribe: (
description: Circus.TestNameLike,
specDefinitions: SpecDefinitionsFn,
) => Suite;
spyOn: (
obj: Record<string, Spy>,
methodName: string,
accessType?: keyof PropertyDescriptor,
) => Spy;
beforeEach: (
beforeEachFunction: QueueableFn['fn'],
timeout?: number,
) => void;
afterEach: (afterEachFunction: QueueableFn['fn'], timeout?: number) => void;
clearReporters: () => void;
addReporter: (reporterToAdd: Reporter) => void;
it: (
description: Circus.TestNameLike,
fn: QueueableFn['fn'],
timeout?: number,
) => Spec;
xdescribe: (
description: Circus.TestNameLike,
specDefinitions: SpecDefinitionsFn,
) => Suite;
xit: (
description: Circus.TestNameLike,
fn: QueueableFn['fn'],
timeout?: number,
) => Spec;
beforeAll: (beforeAllFunction: QueueableFn['fn'], timeout?: number) => void;
todo: () => Spec;
provideFallbackReporter: (reporterToAdd: Reporter) => void;
allowRespy: (allow: boolean) => void;
describe: (
description: Circus.TestNameLike,
specDefinitions: SpecDefinitionsFn,
) => Suite;
constructor() {
let totalSpecsDefined = 0;
let catchExceptions = true;
const realSetTimeout = globalThis.setTimeout;
const realClearTimeout = globalThis.clearTimeout;
const runnableResources: Record<string, {spies: Array<Spy>}> = {};
const currentlyExecutingSuites: Array<Suite> = [];
let currentSpec: Spec | null = null;
let throwOnExpectationFailure = false;
let random = false;
let seed: unknown | null = null;
let nextSpecId = 0;
let nextSuiteId = 0;
const getNextSpecId = function () {
return `spec${nextSpecId++}`;
};
const getNextSuiteId = function () {
return `suite${nextSuiteId++}`;
};
const topSuite = new j$.Suite({
id: getNextSuiteId(),
description: '',
getTestPath() {
return j$.testPath;
},
});
let currentDeclarationSuite = topSuite;
const currentSuite = function () {
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
};
const currentRunnable = function () {
return currentSpec || currentSuite();
};
const reporter = new j$.ReportDispatcher([
'jasmineStarted',
'jasmineDone',
'suiteStarted',
'suiteDone',
'specStarted',
'specDone',
]);
this.specFilter = function () {
return true;
};
const defaultResourcesForRunnable = function (
id: string,
_parentRunnableId?: string,
) {
const resources = {spies: []};
runnableResources[id] = resources;
};
const clearResourcesForRunnable = function (id: string) {
spyRegistry.clearSpies();
delete runnableResources[id];
};
const beforeAndAfterFns = function (suite: Suite) {
return function () {
let afters: Array<QueueableFn> = [];
let befores: Array<QueueableFn> = [];
while (suite) {
befores = befores.concat(suite.beforeFns);
afters = afters.concat(suite.afterFns);
suite = suite.parentSuite!;
}
return {
befores: befores.reverse(),
afters,
};
};
};
const getSpecName = function (spec: Spec, suite: Suite) {
const fullName = [spec.description];
const suiteFullName = suite.getFullName();
if (suiteFullName !== '') {
fullName.unshift(suiteFullName);
}
return fullName.join(' ');
};
this.catchExceptions = function (value) {
catchExceptions = !!value;
return catchExceptions;
};
this.catchingExceptions = function () {
return catchExceptions;
};
this.throwOnExpectationFailure = function (value) {
throwOnExpectationFailure = !!value;
};
this.throwingExpectationFailures = function () {
return throwOnExpectationFailure;
};
this.randomizeTests = function (value) {
random = !!value;
};
this.randomTests = function () {
return random;
};
this.seed = function (value) {
if (value) {
seed = value;
}
return seed;
};
const queueRunnerFactory = (options: QueueRunnerOptions) => {
options.clearTimeout = realClearTimeout;
options.fail = this.fail;
options.setTimeout = realSetTimeout;
return queueRunner(options);
};
this.topSuite = function () {
return topSuite;
};
const uncaught: NodeJS.UncaughtExceptionListener &
NodeJS.UnhandledRejectionListener = (err: any) => {
if (currentSpec) {
currentSpec.onException(err);
currentSpec.cancel();
} else {
console.error('Unhandled error');
console.error(err.stack);
}
};
let oldListenersException: Array<NodeJS.UncaughtExceptionListener>;
let oldListenersRejection: Array<NodeJS.UnhandledRejectionListener>;
const executionSetup = function () {
// Need to ensure we are the only ones handling these exceptions.
oldListenersException = process.listeners('uncaughtException').slice();
oldListenersRejection = process.listeners('unhandledRejection').slice();
j$.process.removeAllListeners('uncaughtException');
j$.process.removeAllListeners('unhandledRejection');
j$.process.on('uncaughtException', uncaught);
j$.process.on('unhandledRejection', uncaught);
};
const executionTeardown = function () {
j$.process.removeListener('uncaughtException', uncaught);
j$.process.removeListener('unhandledRejection', uncaught);
// restore previous exception handlers
oldListenersException.forEach(listener => {
j$.process.on('uncaughtException', listener);
});
oldListenersRejection.forEach(listener => {
j$.process.on('unhandledRejection', listener);
});
};
this.execute = async function (runnablesToRun, suiteTree = topSuite) {
if (!runnablesToRun) {
if (focusedRunnables.length) {
runnablesToRun = focusedRunnables;
} else {
runnablesToRun = [suiteTree.id];
}
}
if (currentlyExecutingSuites.length === 0) {
executionSetup();
}
const lastDeclarationSuite = currentDeclarationSuite;
await treeProcessor({
nodeComplete(suite) {
if (!suite.disabled) {
clearResourcesForRunnable(suite.id);
}
currentlyExecutingSuites.pop();
if (suite === topSuite) {
reporter.jasmineDone({
failedExpectations: topSuite.result.failedExpectations,
});
} else {
reporter.suiteDone(suite.getResult());
}
},
nodeStart(suite) {
currentlyExecutingSuites.push(suite as Suite);
defaultResourcesForRunnable(
suite.id,
suite.parentSuite && suite.parentSuite.id,
);
if (suite === topSuite) {
reporter.jasmineStarted({totalSpecsDefined});
} else {
reporter.suiteStarted(suite.result);
}
},
queueRunnerFactory,
runnableIds: runnablesToRun,
tree: suiteTree as TreeNode,
});
currentDeclarationSuite = lastDeclarationSuite;
if (currentlyExecutingSuites.length === 0) {
executionTeardown();
}
};
this.addReporter = function (reporterToAdd) {
reporter.addReporter(reporterToAdd);
};
this.provideFallbackReporter = function (reporterToAdd) {
reporter.provideFallbackReporter(reporterToAdd);
};
this.clearReporters = function () {
reporter.clearReporters();
};
const spyRegistry = new j$.SpyRegistry({
currentSpies() {
if (!currentRunnable()) {
throw new Error(
'Spies must be created in a before function or a spec',
);
}
return runnableResources[currentRunnable().id].spies;
},
});
this.allowRespy = function (allow) {
spyRegistry.allowRespy(allow);
};
this.spyOn = function (...args) {
return spyRegistry.spyOn.apply(spyRegistry, args);
};
const suiteFactory = function (description: Circus.TestNameLike) {
const suite = new j$.Suite({
id: getNextSuiteId(),
description,
parentSuite: currentDeclarationSuite,
throwOnExpectationFailure,
getTestPath() {
return j$.testPath;
},
});
return suite;
};
this.describe = function (
description: Circus.TestNameLike,
specDefinitions,
) {
const suite = suiteFactory(description);
if (specDefinitions === undefined) {
throw new Error(
'Missing second argument. It must be a callback function.',
);
}
if (typeof specDefinitions !== 'function') {
throw new Error(
`Invalid second argument, ${specDefinitions}. It must be a callback function.`,
);
}
if (specDefinitions.length > 0) {
throw new Error('describe does not expect any arguments');
}
if (currentDeclarationSuite.markedPending) {
suite.pend();
}
if (currentDeclarationSuite.markedTodo) {
// @ts-expect-error TODO Possible error: Suite does not have todo method
suite.todo();
}
addSpecsToSuite(suite, specDefinitions);
return suite;
};
this.xdescribe = function (description, specDefinitions) {
const suite = suiteFactory(description);
suite.pend();
addSpecsToSuite(suite, specDefinitions);
return suite;
};
const focusedRunnables: Array<string> = [];
this.fdescribe = function (description, specDefinitions) {
const suite = suiteFactory(description);
suite.isFocused = true;
focusedRunnables.push(suite.id);
unfocusAncestor();
addSpecsToSuite(suite, specDefinitions);
return suite;
};
const addSpecsToSuite = (
suite: Suite,
specDefinitions: SpecDefinitionsFn,
) => {
const parentSuite = currentDeclarationSuite;
parentSuite.addChild(suite);
currentDeclarationSuite = suite;
let declarationError: undefined | Error = undefined;
let describeReturnValue: unknown | Error;
try {
describeReturnValue = specDefinitions.call(suite);
} catch (e: any) {
declarationError = e;
}
if (isPromise(describeReturnValue)) {
declarationError = new Error(
'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.',
);
} else if (describeReturnValue !== undefined) {
declarationError = new Error(
'A "describe" callback must not return a value.',
);
}
if (declarationError) {
this.it('encountered a declaration exception', () => {
throw declarationError;
});
}
currentDeclarationSuite = parentSuite;
};
function findFocusedAncestor(suite: Suite) {
while (suite) {
if (suite.isFocused) {
return suite.id;
}
suite = suite.parentSuite!;
}
return null;
}
function unfocusAncestor() {
const focusedAncestor = findFocusedAncestor(currentDeclarationSuite);
if (focusedAncestor) {
for (let i = 0; i < focusedRunnables.length; i++) {
if (focusedRunnables[i] === focusedAncestor) {
focusedRunnables.splice(i, 1);
break;
}
}
}
}
const specFactory = (
description: Circus.TestNameLike,
fn: QueueableFn['fn'],
suite: Suite,
timeout?: number,
): Spec => {
totalSpecsDefined++;
const spec = new j$.Spec({
id: getNextSpecId(),
beforeAndAfterFns: beforeAndAfterFns(suite),
resultCallback: specResultCallback,
getSpecName(spec: Spec) {
return getSpecName(spec, suite);
},
getTestPath() {
return j$.testPath;
},
onStart: specStarted,
description,
queueRunnerFactory,
userContext() {
return suite.clonedSharedUserContext();
},
queueableFn: {
fn,
timeout() {
return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
},
},
throwOnExpectationFailure,
});
if (!this.specFilter(spec)) {
spec.disable();
}
return spec;
function specResultCallback(result: SpecResult) {
clearResourcesForRunnable(spec.id);
currentSpec = null;
reporter.specDone(result);
}
function specStarted(spec: Spec) {
currentSpec = spec;
defaultResourcesForRunnable(spec.id, suite.id);
reporter.specStarted(spec.result);
}
};
this.it = function (description, fn, timeout) {
description = convertDescriptorToString(description);
if (fn === undefined) {
throw new Error(
'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.',
);
}
if (typeof fn !== 'function') {
throw new Error(
`Invalid second argument, ${fn}. It must be a callback function.`,
);
}
const spec = specFactory(
description,
fn,
currentDeclarationSuite,
timeout,
);
if (currentDeclarationSuite.markedPending) {
spec.pend();
}
// When a test is defined inside another, jasmine will not run it.
// This check throws an error to warn the user about the edge-case.
if (currentSpec !== null) {
throw new Error(
`Tests cannot be nested. Test "${spec.description}" cannot run because it is nested within "${currentSpec.description}".`,
);
}
currentDeclarationSuite.addChild(spec);
return spec;
};
this.xit = function (...args) {
const spec = this.it.apply(this, args);
spec.pend('Temporarily disabled with xit');
return spec;
};
this.todo = function () {
const description = arguments[0];
if (arguments.length !== 1 || typeof description !== 'string') {
throw new ErrorWithStack(
'Todo must be called with only a description.',
this.todo,
);
}
const spec = specFactory(
description,
// eslint-disable-next-line @typescript-eslint/no-empty-function
() => {},
currentDeclarationSuite,
);
if (currentDeclarationSuite.markedPending) {
spec.pend();
} else {
spec.todo();
}
currentDeclarationSuite.addChild(spec);
return spec;
};
this.fit = function (description, fn, timeout) {
const spec = specFactory(
description,
fn,
currentDeclarationSuite,
timeout,
);
currentDeclarationSuite.addChild(spec);
if (currentDeclarationSuite.markedPending) {
spec.pend();
} else {
focusedRunnables.push(spec.id);
}
unfocusAncestor();
return spec;
};
this.beforeEach = function (beforeEachFunction, timeout) {
currentDeclarationSuite.beforeEach({
fn: beforeEachFunction,
timeout() {
return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
},
});
};
this.beforeAll = function (beforeAllFunction, timeout) {
currentDeclarationSuite.beforeAll({
fn: beforeAllFunction,
timeout() {
return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
},
});
};
this.afterEach = function (afterEachFunction, timeout) {
currentDeclarationSuite.afterEach({
fn: afterEachFunction,
timeout() {
return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
},
});
};
this.afterAll = function (afterAllFunction, timeout) {
currentDeclarationSuite.afterAll({
fn: afterAllFunction,
timeout() {
return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
},
});
};
this.pending = function (message) {
let fullMessage = j$.Spec.pendingSpecExceptionMessage;
if (message) {
fullMessage += message;
}
throw fullMessage;
};
this.fail = function (error) {
let checkIsError;
let message;
if (
error instanceof AssertionError ||
(error && error.name === AssertionError.name)
) {
checkIsError = false;
// @ts-expect-error TODO Possible error: j$.Spec does not have expand property
message = assertionErrorMessage(error, {expand: j$.Spec.expand});
} else {
const check = isError(error);
checkIsError = check.isError;
message = check.message;
}
const errorAsErrorObject = checkIsError ? error : new Error(message!);
const runnable = currentRunnable();
if (!runnable) {
errorAsErrorObject.message = `Caught error after test environment was torn down\n\n${errorAsErrorObject.message}`;
throw errorAsErrorObject;
}
runnable.addExpectationResult(false, {
matcherName: '',
passed: false,
expected: '',
actual: '',
message,
error: errorAsErrorObject,
});
};
}
};
} | type Jasmine = {
_DEFAULT_TIMEOUT_INTERVAL: number;
DEFAULT_TIMEOUT_INTERVAL: number;
currentEnv_: ReturnType<typeof Env>['prototype'];
getEnv: () => ReturnType<typeof Env>['prototype'];
createSpy: typeof createSpy;
Env: ReturnType<typeof Env>;
JsApiReporter: typeof JsApiReporter;
ReportDispatcher: typeof ReportDispatcher;
Spec: typeof Spec;
SpyRegistry: typeof SpyRegistry;
Suite: typeof Suite;
Timer: typeof Timer;
version: string;
testPath: string;
addMatchers: (matchers: JasmineMatchersObject) => void;
} & AsymmetricMatchers & {process: NodeJS.Process}; |
1,472 | (spec: Spec) => boolean | class Spec extends realSpec {
constructor(attr: Attributes) {
const resultCallback = attr.resultCallback;
attr.resultCallback = function (result: SpecResult) {
addSuppressedErrors(result);
addAssertionErrors(result);
resultCallback.call(attr, result);
};
const onStart = attr.onStart;
attr.onStart = (context: JasmineSpec) => {
jestExpect.setState({currentTestName: context.getFullName()});
onStart && onStart.call(attr, context);
};
super(attr);
}
} |
1,473 | (spec: Spec) => boolean | class Spec {
id: string;
description: string;
resultCallback: (result: SpecResult) => void;
queueableFn: QueueableFn;
beforeAndAfterFns: () => {
befores: Array<QueueableFn>;
afters: Array<QueueableFn>;
};
userContext: () => unknown;
onStart: (spec: Spec) => void;
getSpecName: (spec: Spec) => string;
queueRunnerFactory: typeof queueRunner;
throwOnExpectationFailure: boolean;
initError: Error;
result: SpecResult;
disabled?: boolean;
currentRun?: ReturnType<typeof queueRunner>;
markedTodo?: boolean;
markedPending?: boolean;
expand?: boolean;
static pendingSpecExceptionMessage: string;
static isPendingSpecException(e: Error) {
return !!(
e &&
e.toString &&
e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1
);
}
constructor(attrs: Attributes) {
this.resultCallback = attrs.resultCallback || function () {};
this.id = attrs.id;
this.description = convertDescriptorToString(attrs.description);
this.queueableFn = attrs.queueableFn;
this.beforeAndAfterFns =
attrs.beforeAndAfterFns ||
function () {
return {befores: [], afters: []};
};
this.userContext =
attrs.userContext ||
function () {
return {};
};
this.onStart = attrs.onStart || function () {};
this.getSpecName =
attrs.getSpecName ||
function () {
return '';
};
this.queueRunnerFactory = attrs.queueRunnerFactory || function () {};
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.initError = new Error();
this.initError.name = '';
// Without this line v8 stores references to all closures
// in the stack in the Error object. This line stringifies the stack
// property to allow garbage-collecting objects on the stack
// https://crbug.com/v8/7142
// eslint-disable-next-line no-self-assign
this.initError.stack = this.initError.stack;
this.queueableFn.initError = this.initError;
// @ts-expect-error: misses some fields added later
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
passedExpectations: [],
pendingReason: '',
testPath: attrs.getTestPath(),
};
}
addExpectationResult(
passed: boolean,
data: ExpectationResultFactoryOptions,
isError?: boolean,
) {
const expectationResult = expectationResultFactory(data, this.initError);
if (passed) {
this.result.passedExpectations.push(expectationResult);
} else {
this.result.failedExpectations.push(expectationResult);
if (this.throwOnExpectationFailure && !isError) {
throw new ExpectationFailed();
}
}
}
execute(onComplete?: () => void, enabled?: boolean) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
this.onStart(this);
if (
!this.isExecutable() ||
this.markedPending ||
this.markedTodo ||
enabled === false
) {
complete(enabled);
return;
}
const fns = this.beforeAndAfterFns();
const allFns = fns.befores.concat(this.queueableFn).concat(fns.afters);
this.currentRun = this.queueRunnerFactory({
queueableFns: allFns,
onException() {
// @ts-expect-error: wrong context
self.onException.apply(self, arguments);
},
userContext: this.userContext(),
setTimeout,
clearTimeout,
fail: () => {},
});
this.currentRun.then(() => complete(true));
function complete(enabledAgain?: boolean) {
self.result.status = self.status(enabledAgain);
self.resultCallback(self.result);
if (onComplete) {
onComplete();
}
}
}
cancel() {
if (this.currentRun) {
this.currentRun.cancel();
}
}
onException(error: ExpectationFailed | AssertionErrorWithStack) {
if (Spec.isPendingSpecException(error)) {
this.pend(extractCustomPendingMessage(error));
return;
}
if (error instanceof ExpectationFailed) {
return;
}
this.addExpectationResult(
false,
{
matcherName: '',
passed: false,
expected: '',
actual: '',
error: this.isAssertionError(error)
? assertionErrorMessage(error, {expand: this.expand})
: error,
},
true,
);
}
disable() {
this.disabled = true;
}
pend(message?: string) {
this.markedPending = true;
if (message) {
this.result.pendingReason = message;
}
}
todo() {
this.markedTodo = true;
}
getResult() {
this.result.status = this.status();
return this.result;
}
status(enabled?: boolean) {
if (this.disabled || enabled === false) {
return 'disabled';
}
if (this.markedTodo) {
return 'todo';
}
if (this.markedPending) {
return 'pending';
}
if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {
return 'passed';
}
}
isExecutable() {
return !this.disabled;
}
getFullName() {
return this.getSpecName(this);
}
isAssertionError(error: Error) {
return (
error instanceof AssertionError ||
(error && error.name === AssertionError.name)
);
}
} |
1,474 | (reporterToAdd: Reporter) => void | type Reporter = {
jasmineDone: (runDetails: RunDetails) => void;
jasmineStarted: (runDetails: RunDetails) => void;
specDone: (result: SpecResult) => void;
specStarted: (spec: SpecResult) => void;
suiteDone: (result: SuiteResult) => void;
suiteStarted: (result: SuiteResult) => void;
}; |
1,475 | (reporterToAdd: Reporter) => void | interface Reporter {
readonly onTestResult?: (
test: Test,
testResult: TestResult,
aggregatedResult: AggregatedResult,
) => Promise<void> | void;
readonly onTestFileResult?: (
test: Test,
testResult: TestResult,
aggregatedResult: AggregatedResult,
) => Promise<void> | void;
readonly onTestCaseResult?: (
test: Test,
testCaseResult: TestCaseResult,
) => Promise<void> | void;
readonly onRunStart: (
results: AggregatedResult,
options: ReporterOnStartOptions,
) => Promise<void> | void;
readonly onTestStart?: (test: Test) => Promise<void> | void;
readonly onTestFileStart?: (test: Test) => Promise<void> | void;
readonly onRunComplete: (
testContexts: Set<TestContext>,
results: AggregatedResult,
) => Promise<void> | void;
readonly getLastError: () => Error | void;
} |
1,476 | function (suite: Suite) {
return function () {
let afters: Array<QueueableFn> = [];
let befores: Array<QueueableFn> = [];
while (suite) {
befores = befores.concat(suite.beforeFns);
afters = afters.concat(suite.afterFns);
suite = suite.parentSuite!;
}
return {
befores: befores.reverse(),
afters,
};
};
} | class Suite {
id: string;
parentSuite?: Suite;
description: Circus.TestNameLike;
throwOnExpectationFailure: boolean;
beforeFns: Array<QueueableFn>;
afterFns: Array<QueueableFn>;
beforeAllFns: Array<QueueableFn>;
afterAllFns: Array<QueueableFn>;
disabled: boolean;
children: Array<Suite | Spec>;
result: SuiteResult;
sharedContext?: object;
markedPending: boolean;
markedTodo: boolean;
isFocused: boolean;
constructor(attrs: Attributes) {
this.markedPending = false;
this.markedTodo = false;
this.isFocused = false;
this.id = attrs.id;
this.parentSuite = attrs.parentSuite;
this.description = convertDescriptorToString(attrs.description);
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.beforeFns = [];
this.afterFns = [];
this.beforeAllFns = [];
this.afterAllFns = [];
this.disabled = false;
this.children = [];
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
testPath: attrs.getTestPath(),
};
}
getFullName() {
const fullName = [];
for (
// eslint-disable-next-line @typescript-eslint/no-this-alias
let parentSuite: Suite | undefined = this;
parentSuite;
parentSuite = parentSuite.parentSuite
) {
if (parentSuite.parentSuite) {
fullName.unshift(parentSuite.description);
}
}
return fullName.join(' ');
}
disable() {
this.disabled = true;
}
pend(_message?: string) {
this.markedPending = true;
}
beforeEach(fn: QueueableFn) {
this.beforeFns.unshift(fn);
}
beforeAll(fn: QueueableFn) {
this.beforeAllFns.push(fn);
}
afterEach(fn: QueueableFn) {
this.afterFns.unshift(fn);
}
afterAll(fn: QueueableFn) {
this.afterAllFns.unshift(fn);
}
addChild(child: Suite | Spec) {
this.children.push(child);
}
status() {
if (this.disabled) {
return 'disabled';
}
if (this.markedPending) {
return 'pending';
}
if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {
return 'finished';
}
}
isExecutable() {
return !this.disabled;
}
canBeReentered() {
return this.beforeAllFns.length === 0 && this.afterAllFns.length === 0;
}
getResult() {
this.result.status = this.status();
return this.result;
}
sharedUserContext() {
if (!this.sharedContext) {
this.sharedContext = {};
}
return this.sharedContext;
}
clonedSharedUserContext() {
return this.sharedUserContext();
}
onException(...args: Parameters<Spec['onException']>) {
if (args[0] instanceof ExpectationFailed) {
return;
}
if (isAfterAll(this.children)) {
const data = {
matcherName: '',
passed: false,
expected: '',
actual: '',
error: arguments[0],
};
this.result.failedExpectations.push(expectationResultFactory(data));
} else {
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
child.onException.apply(child, args);
}
}
}
addExpectationResult(...args: Parameters<Spec['addExpectationResult']>) {
if (isAfterAll(this.children) && isFailure(args)) {
const data = args[1];
this.result.failedExpectations.push(expectationResultFactory(data));
if (this.throwOnExpectationFailure) {
throw new ExpectationFailed();
}
} else {
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
try {
child.addExpectationResult.apply(child, args);
} catch {
// keep going
}
}
}
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
execute(..._args: Array<any>) {}
} |
1,477 | function (suite: Suite) {
return function () {
let afters: Array<QueueableFn> = [];
let befores: Array<QueueableFn> = [];
while (suite) {
befores = befores.concat(suite.beforeFns);
afters = afters.concat(suite.afterFns);
suite = suite.parentSuite!;
}
return {
befores: befores.reverse(),
afters,
};
};
} | type Suite = {
title: string;
suites: Array<Suite>;
tests: Array<AssertionResult>;
}; |
1,478 | function (spec: Spec, suite: Suite) {
const fullName = [spec.description];
const suiteFullName = suite.getFullName();
if (suiteFullName !== '') {
fullName.unshift(suiteFullName);
}
return fullName.join(' ');
} | class Spec extends realSpec {
constructor(attr: Attributes) {
const resultCallback = attr.resultCallback;
attr.resultCallback = function (result: SpecResult) {
addSuppressedErrors(result);
addAssertionErrors(result);
resultCallback.call(attr, result);
};
const onStart = attr.onStart;
attr.onStart = (context: JasmineSpec) => {
jestExpect.setState({currentTestName: context.getFullName()});
onStart && onStart.call(attr, context);
};
super(attr);
}
} |
1,479 | function (spec: Spec, suite: Suite) {
const fullName = [spec.description];
const suiteFullName = suite.getFullName();
if (suiteFullName !== '') {
fullName.unshift(suiteFullName);
}
return fullName.join(' ');
} | class Spec {
id: string;
description: string;
resultCallback: (result: SpecResult) => void;
queueableFn: QueueableFn;
beforeAndAfterFns: () => {
befores: Array<QueueableFn>;
afters: Array<QueueableFn>;
};
userContext: () => unknown;
onStart: (spec: Spec) => void;
getSpecName: (spec: Spec) => string;
queueRunnerFactory: typeof queueRunner;
throwOnExpectationFailure: boolean;
initError: Error;
result: SpecResult;
disabled?: boolean;
currentRun?: ReturnType<typeof queueRunner>;
markedTodo?: boolean;
markedPending?: boolean;
expand?: boolean;
static pendingSpecExceptionMessage: string;
static isPendingSpecException(e: Error) {
return !!(
e &&
e.toString &&
e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1
);
}
constructor(attrs: Attributes) {
this.resultCallback = attrs.resultCallback || function () {};
this.id = attrs.id;
this.description = convertDescriptorToString(attrs.description);
this.queueableFn = attrs.queueableFn;
this.beforeAndAfterFns =
attrs.beforeAndAfterFns ||
function () {
return {befores: [], afters: []};
};
this.userContext =
attrs.userContext ||
function () {
return {};
};
this.onStart = attrs.onStart || function () {};
this.getSpecName =
attrs.getSpecName ||
function () {
return '';
};
this.queueRunnerFactory = attrs.queueRunnerFactory || function () {};
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.initError = new Error();
this.initError.name = '';
// Without this line v8 stores references to all closures
// in the stack in the Error object. This line stringifies the stack
// property to allow garbage-collecting objects on the stack
// https://crbug.com/v8/7142
// eslint-disable-next-line no-self-assign
this.initError.stack = this.initError.stack;
this.queueableFn.initError = this.initError;
// @ts-expect-error: misses some fields added later
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
passedExpectations: [],
pendingReason: '',
testPath: attrs.getTestPath(),
};
}
addExpectationResult(
passed: boolean,
data: ExpectationResultFactoryOptions,
isError?: boolean,
) {
const expectationResult = expectationResultFactory(data, this.initError);
if (passed) {
this.result.passedExpectations.push(expectationResult);
} else {
this.result.failedExpectations.push(expectationResult);
if (this.throwOnExpectationFailure && !isError) {
throw new ExpectationFailed();
}
}
}
execute(onComplete?: () => void, enabled?: boolean) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
this.onStart(this);
if (
!this.isExecutable() ||
this.markedPending ||
this.markedTodo ||
enabled === false
) {
complete(enabled);
return;
}
const fns = this.beforeAndAfterFns();
const allFns = fns.befores.concat(this.queueableFn).concat(fns.afters);
this.currentRun = this.queueRunnerFactory({
queueableFns: allFns,
onException() {
// @ts-expect-error: wrong context
self.onException.apply(self, arguments);
},
userContext: this.userContext(),
setTimeout,
clearTimeout,
fail: () => {},
});
this.currentRun.then(() => complete(true));
function complete(enabledAgain?: boolean) {
self.result.status = self.status(enabledAgain);
self.resultCallback(self.result);
if (onComplete) {
onComplete();
}
}
}
cancel() {
if (this.currentRun) {
this.currentRun.cancel();
}
}
onException(error: ExpectationFailed | AssertionErrorWithStack) {
if (Spec.isPendingSpecException(error)) {
this.pend(extractCustomPendingMessage(error));
return;
}
if (error instanceof ExpectationFailed) {
return;
}
this.addExpectationResult(
false,
{
matcherName: '',
passed: false,
expected: '',
actual: '',
error: this.isAssertionError(error)
? assertionErrorMessage(error, {expand: this.expand})
: error,
},
true,
);
}
disable() {
this.disabled = true;
}
pend(message?: string) {
this.markedPending = true;
if (message) {
this.result.pendingReason = message;
}
}
todo() {
this.markedTodo = true;
}
getResult() {
this.result.status = this.status();
return this.result;
}
status(enabled?: boolean) {
if (this.disabled || enabled === false) {
return 'disabled';
}
if (this.markedTodo) {
return 'todo';
}
if (this.markedPending) {
return 'pending';
}
if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {
return 'passed';
}
}
isExecutable() {
return !this.disabled;
}
getFullName() {
return this.getSpecName(this);
}
isAssertionError(error: Error) {
return (
error instanceof AssertionError ||
(error && error.name === AssertionError.name)
);
}
} |
1,480 | function (spec: Spec, suite: Suite) {
const fullName = [spec.description];
const suiteFullName = suite.getFullName();
if (suiteFullName !== '') {
fullName.unshift(suiteFullName);
}
return fullName.join(' ');
} | class Suite {
id: string;
parentSuite?: Suite;
description: Circus.TestNameLike;
throwOnExpectationFailure: boolean;
beforeFns: Array<QueueableFn>;
afterFns: Array<QueueableFn>;
beforeAllFns: Array<QueueableFn>;
afterAllFns: Array<QueueableFn>;
disabled: boolean;
children: Array<Suite | Spec>;
result: SuiteResult;
sharedContext?: object;
markedPending: boolean;
markedTodo: boolean;
isFocused: boolean;
constructor(attrs: Attributes) {
this.markedPending = false;
this.markedTodo = false;
this.isFocused = false;
this.id = attrs.id;
this.parentSuite = attrs.parentSuite;
this.description = convertDescriptorToString(attrs.description);
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.beforeFns = [];
this.afterFns = [];
this.beforeAllFns = [];
this.afterAllFns = [];
this.disabled = false;
this.children = [];
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
testPath: attrs.getTestPath(),
};
}
getFullName() {
const fullName = [];
for (
// eslint-disable-next-line @typescript-eslint/no-this-alias
let parentSuite: Suite | undefined = this;
parentSuite;
parentSuite = parentSuite.parentSuite
) {
if (parentSuite.parentSuite) {
fullName.unshift(parentSuite.description);
}
}
return fullName.join(' ');
}
disable() {
this.disabled = true;
}
pend(_message?: string) {
this.markedPending = true;
}
beforeEach(fn: QueueableFn) {
this.beforeFns.unshift(fn);
}
beforeAll(fn: QueueableFn) {
this.beforeAllFns.push(fn);
}
afterEach(fn: QueueableFn) {
this.afterFns.unshift(fn);
}
afterAll(fn: QueueableFn) {
this.afterAllFns.unshift(fn);
}
addChild(child: Suite | Spec) {
this.children.push(child);
}
status() {
if (this.disabled) {
return 'disabled';
}
if (this.markedPending) {
return 'pending';
}
if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {
return 'finished';
}
}
isExecutable() {
return !this.disabled;
}
canBeReentered() {
return this.beforeAllFns.length === 0 && this.afterAllFns.length === 0;
}
getResult() {
this.result.status = this.status();
return this.result;
}
sharedUserContext() {
if (!this.sharedContext) {
this.sharedContext = {};
}
return this.sharedContext;
}
clonedSharedUserContext() {
return this.sharedUserContext();
}
onException(...args: Parameters<Spec['onException']>) {
if (args[0] instanceof ExpectationFailed) {
return;
}
if (isAfterAll(this.children)) {
const data = {
matcherName: '',
passed: false,
expected: '',
actual: '',
error: arguments[0],
};
this.result.failedExpectations.push(expectationResultFactory(data));
} else {
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
child.onException.apply(child, args);
}
}
}
addExpectationResult(...args: Parameters<Spec['addExpectationResult']>) {
if (isAfterAll(this.children) && isFailure(args)) {
const data = args[1];
this.result.failedExpectations.push(expectationResultFactory(data));
if (this.throwOnExpectationFailure) {
throw new ExpectationFailed();
}
} else {
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
try {
child.addExpectationResult.apply(child, args);
} catch {
// keep going
}
}
}
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
execute(..._args: Array<any>) {}
} |
1,481 | function (spec: Spec, suite: Suite) {
const fullName = [spec.description];
const suiteFullName = suite.getFullName();
if (suiteFullName !== '') {
fullName.unshift(suiteFullName);
}
return fullName.join(' ');
} | type Suite = {
title: string;
suites: Array<Suite>;
tests: Array<AssertionResult>;
}; |
1,482 | (
suite: Suite,
specDefinitions: SpecDefinitionsFn,
) => {
const parentSuite = currentDeclarationSuite;
parentSuite.addChild(suite);
currentDeclarationSuite = suite;
let declarationError: undefined | Error = undefined;
let describeReturnValue: unknown | Error;
try {
describeReturnValue = specDefinitions.call(suite);
} catch (e: any) {
declarationError = e;
}
if (isPromise(describeReturnValue)) {
declarationError = new Error(
'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.',
);
} else if (describeReturnValue !== undefined) {
declarationError = new Error(
'A "describe" callback must not return a value.',
);
}
if (declarationError) {
this.it('encountered a declaration exception', () => {
throw declarationError;
});
}
currentDeclarationSuite = parentSuite;
} | class Suite {
id: string;
parentSuite?: Suite;
description: Circus.TestNameLike;
throwOnExpectationFailure: boolean;
beforeFns: Array<QueueableFn>;
afterFns: Array<QueueableFn>;
beforeAllFns: Array<QueueableFn>;
afterAllFns: Array<QueueableFn>;
disabled: boolean;
children: Array<Suite | Spec>;
result: SuiteResult;
sharedContext?: object;
markedPending: boolean;
markedTodo: boolean;
isFocused: boolean;
constructor(attrs: Attributes) {
this.markedPending = false;
this.markedTodo = false;
this.isFocused = false;
this.id = attrs.id;
this.parentSuite = attrs.parentSuite;
this.description = convertDescriptorToString(attrs.description);
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.beforeFns = [];
this.afterFns = [];
this.beforeAllFns = [];
this.afterAllFns = [];
this.disabled = false;
this.children = [];
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
testPath: attrs.getTestPath(),
};
}
getFullName() {
const fullName = [];
for (
// eslint-disable-next-line @typescript-eslint/no-this-alias
let parentSuite: Suite | undefined = this;
parentSuite;
parentSuite = parentSuite.parentSuite
) {
if (parentSuite.parentSuite) {
fullName.unshift(parentSuite.description);
}
}
return fullName.join(' ');
}
disable() {
this.disabled = true;
}
pend(_message?: string) {
this.markedPending = true;
}
beforeEach(fn: QueueableFn) {
this.beforeFns.unshift(fn);
}
beforeAll(fn: QueueableFn) {
this.beforeAllFns.push(fn);
}
afterEach(fn: QueueableFn) {
this.afterFns.unshift(fn);
}
afterAll(fn: QueueableFn) {
this.afterAllFns.unshift(fn);
}
addChild(child: Suite | Spec) {
this.children.push(child);
}
status() {
if (this.disabled) {
return 'disabled';
}
if (this.markedPending) {
return 'pending';
}
if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {
return 'finished';
}
}
isExecutable() {
return !this.disabled;
}
canBeReentered() {
return this.beforeAllFns.length === 0 && this.afterAllFns.length === 0;
}
getResult() {
this.result.status = this.status();
return this.result;
}
sharedUserContext() {
if (!this.sharedContext) {
this.sharedContext = {};
}
return this.sharedContext;
}
clonedSharedUserContext() {
return this.sharedUserContext();
}
onException(...args: Parameters<Spec['onException']>) {
if (args[0] instanceof ExpectationFailed) {
return;
}
if (isAfterAll(this.children)) {
const data = {
matcherName: '',
passed: false,
expected: '',
actual: '',
error: arguments[0],
};
this.result.failedExpectations.push(expectationResultFactory(data));
} else {
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
child.onException.apply(child, args);
}
}
}
addExpectationResult(...args: Parameters<Spec['addExpectationResult']>) {
if (isAfterAll(this.children) && isFailure(args)) {
const data = args[1];
this.result.failedExpectations.push(expectationResultFactory(data));
if (this.throwOnExpectationFailure) {
throw new ExpectationFailed();
}
} else {
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
try {
child.addExpectationResult.apply(child, args);
} catch {
// keep going
}
}
}
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
execute(..._args: Array<any>) {}
} |
1,483 | (
suite: Suite,
specDefinitions: SpecDefinitionsFn,
) => {
const parentSuite = currentDeclarationSuite;
parentSuite.addChild(suite);
currentDeclarationSuite = suite;
let declarationError: undefined | Error = undefined;
let describeReturnValue: unknown | Error;
try {
describeReturnValue = specDefinitions.call(suite);
} catch (e: any) {
declarationError = e;
}
if (isPromise(describeReturnValue)) {
declarationError = new Error(
'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.',
);
} else if (describeReturnValue !== undefined) {
declarationError = new Error(
'A "describe" callback must not return a value.',
);
}
if (declarationError) {
this.it('encountered a declaration exception', () => {
throw declarationError;
});
}
currentDeclarationSuite = parentSuite;
} | type Suite = {
title: string;
suites: Array<Suite>;
tests: Array<AssertionResult>;
}; |
1,484 | (
suite: Suite,
specDefinitions: SpecDefinitionsFn,
) => {
const parentSuite = currentDeclarationSuite;
parentSuite.addChild(suite);
currentDeclarationSuite = suite;
let declarationError: undefined | Error = undefined;
let describeReturnValue: unknown | Error;
try {
describeReturnValue = specDefinitions.call(suite);
} catch (e: any) {
declarationError = e;
}
if (isPromise(describeReturnValue)) {
declarationError = new Error(
'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.',
);
} else if (describeReturnValue !== undefined) {
declarationError = new Error(
'A "describe" callback must not return a value.',
);
}
if (declarationError) {
this.it('encountered a declaration exception', () => {
throw declarationError;
});
}
currentDeclarationSuite = parentSuite;
} | type SpecDefinitionsFn = () => void; |
1,485 | function findFocusedAncestor(suite: Suite) {
while (suite) {
if (suite.isFocused) {
return suite.id;
}
suite = suite.parentSuite!;
}
return null;
} | class Suite {
id: string;
parentSuite?: Suite;
description: Circus.TestNameLike;
throwOnExpectationFailure: boolean;
beforeFns: Array<QueueableFn>;
afterFns: Array<QueueableFn>;
beforeAllFns: Array<QueueableFn>;
afterAllFns: Array<QueueableFn>;
disabled: boolean;
children: Array<Suite | Spec>;
result: SuiteResult;
sharedContext?: object;
markedPending: boolean;
markedTodo: boolean;
isFocused: boolean;
constructor(attrs: Attributes) {
this.markedPending = false;
this.markedTodo = false;
this.isFocused = false;
this.id = attrs.id;
this.parentSuite = attrs.parentSuite;
this.description = convertDescriptorToString(attrs.description);
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.beforeFns = [];
this.afterFns = [];
this.beforeAllFns = [];
this.afterAllFns = [];
this.disabled = false;
this.children = [];
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
testPath: attrs.getTestPath(),
};
}
getFullName() {
const fullName = [];
for (
// eslint-disable-next-line @typescript-eslint/no-this-alias
let parentSuite: Suite | undefined = this;
parentSuite;
parentSuite = parentSuite.parentSuite
) {
if (parentSuite.parentSuite) {
fullName.unshift(parentSuite.description);
}
}
return fullName.join(' ');
}
disable() {
this.disabled = true;
}
pend(_message?: string) {
this.markedPending = true;
}
beforeEach(fn: QueueableFn) {
this.beforeFns.unshift(fn);
}
beforeAll(fn: QueueableFn) {
this.beforeAllFns.push(fn);
}
afterEach(fn: QueueableFn) {
this.afterFns.unshift(fn);
}
afterAll(fn: QueueableFn) {
this.afterAllFns.unshift(fn);
}
addChild(child: Suite | Spec) {
this.children.push(child);
}
status() {
if (this.disabled) {
return 'disabled';
}
if (this.markedPending) {
return 'pending';
}
if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {
return 'finished';
}
}
isExecutable() {
return !this.disabled;
}
canBeReentered() {
return this.beforeAllFns.length === 0 && this.afterAllFns.length === 0;
}
getResult() {
this.result.status = this.status();
return this.result;
}
sharedUserContext() {
if (!this.sharedContext) {
this.sharedContext = {};
}
return this.sharedContext;
}
clonedSharedUserContext() {
return this.sharedUserContext();
}
onException(...args: Parameters<Spec['onException']>) {
if (args[0] instanceof ExpectationFailed) {
return;
}
if (isAfterAll(this.children)) {
const data = {
matcherName: '',
passed: false,
expected: '',
actual: '',
error: arguments[0],
};
this.result.failedExpectations.push(expectationResultFactory(data));
} else {
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
child.onException.apply(child, args);
}
}
}
addExpectationResult(...args: Parameters<Spec['addExpectationResult']>) {
if (isAfterAll(this.children) && isFailure(args)) {
const data = args[1];
this.result.failedExpectations.push(expectationResultFactory(data));
if (this.throwOnExpectationFailure) {
throw new ExpectationFailed();
}
} else {
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
try {
child.addExpectationResult.apply(child, args);
} catch {
// keep going
}
}
}
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
execute(..._args: Array<any>) {}
} |
1,486 | function findFocusedAncestor(suite: Suite) {
while (suite) {
if (suite.isFocused) {
return suite.id;
}
suite = suite.parentSuite!;
}
return null;
} | type Suite = {
title: string;
suites: Array<Suite>;
tests: Array<AssertionResult>;
}; |
1,487 | getSpecName(spec: Spec) {
return getSpecName(spec, suite);
} | class Spec extends realSpec {
constructor(attr: Attributes) {
const resultCallback = attr.resultCallback;
attr.resultCallback = function (result: SpecResult) {
addSuppressedErrors(result);
addAssertionErrors(result);
resultCallback.call(attr, result);
};
const onStart = attr.onStart;
attr.onStart = (context: JasmineSpec) => {
jestExpect.setState({currentTestName: context.getFullName()});
onStart && onStart.call(attr, context);
};
super(attr);
}
} |
1,488 | getSpecName(spec: Spec) {
return getSpecName(spec, suite);
} | class Spec {
id: string;
description: string;
resultCallback: (result: SpecResult) => void;
queueableFn: QueueableFn;
beforeAndAfterFns: () => {
befores: Array<QueueableFn>;
afters: Array<QueueableFn>;
};
userContext: () => unknown;
onStart: (spec: Spec) => void;
getSpecName: (spec: Spec) => string;
queueRunnerFactory: typeof queueRunner;
throwOnExpectationFailure: boolean;
initError: Error;
result: SpecResult;
disabled?: boolean;
currentRun?: ReturnType<typeof queueRunner>;
markedTodo?: boolean;
markedPending?: boolean;
expand?: boolean;
static pendingSpecExceptionMessage: string;
static isPendingSpecException(e: Error) {
return !!(
e &&
e.toString &&
e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1
);
}
constructor(attrs: Attributes) {
this.resultCallback = attrs.resultCallback || function () {};
this.id = attrs.id;
this.description = convertDescriptorToString(attrs.description);
this.queueableFn = attrs.queueableFn;
this.beforeAndAfterFns =
attrs.beforeAndAfterFns ||
function () {
return {befores: [], afters: []};
};
this.userContext =
attrs.userContext ||
function () {
return {};
};
this.onStart = attrs.onStart || function () {};
this.getSpecName =
attrs.getSpecName ||
function () {
return '';
};
this.queueRunnerFactory = attrs.queueRunnerFactory || function () {};
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.initError = new Error();
this.initError.name = '';
// Without this line v8 stores references to all closures
// in the stack in the Error object. This line stringifies the stack
// property to allow garbage-collecting objects on the stack
// https://crbug.com/v8/7142
// eslint-disable-next-line no-self-assign
this.initError.stack = this.initError.stack;
this.queueableFn.initError = this.initError;
// @ts-expect-error: misses some fields added later
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
passedExpectations: [],
pendingReason: '',
testPath: attrs.getTestPath(),
};
}
addExpectationResult(
passed: boolean,
data: ExpectationResultFactoryOptions,
isError?: boolean,
) {
const expectationResult = expectationResultFactory(data, this.initError);
if (passed) {
this.result.passedExpectations.push(expectationResult);
} else {
this.result.failedExpectations.push(expectationResult);
if (this.throwOnExpectationFailure && !isError) {
throw new ExpectationFailed();
}
}
}
execute(onComplete?: () => void, enabled?: boolean) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
this.onStart(this);
if (
!this.isExecutable() ||
this.markedPending ||
this.markedTodo ||
enabled === false
) {
complete(enabled);
return;
}
const fns = this.beforeAndAfterFns();
const allFns = fns.befores.concat(this.queueableFn).concat(fns.afters);
this.currentRun = this.queueRunnerFactory({
queueableFns: allFns,
onException() {
// @ts-expect-error: wrong context
self.onException.apply(self, arguments);
},
userContext: this.userContext(),
setTimeout,
clearTimeout,
fail: () => {},
});
this.currentRun.then(() => complete(true));
function complete(enabledAgain?: boolean) {
self.result.status = self.status(enabledAgain);
self.resultCallback(self.result);
if (onComplete) {
onComplete();
}
}
}
cancel() {
if (this.currentRun) {
this.currentRun.cancel();
}
}
onException(error: ExpectationFailed | AssertionErrorWithStack) {
if (Spec.isPendingSpecException(error)) {
this.pend(extractCustomPendingMessage(error));
return;
}
if (error instanceof ExpectationFailed) {
return;
}
this.addExpectationResult(
false,
{
matcherName: '',
passed: false,
expected: '',
actual: '',
error: this.isAssertionError(error)
? assertionErrorMessage(error, {expand: this.expand})
: error,
},
true,
);
}
disable() {
this.disabled = true;
}
pend(message?: string) {
this.markedPending = true;
if (message) {
this.result.pendingReason = message;
}
}
todo() {
this.markedTodo = true;
}
getResult() {
this.result.status = this.status();
return this.result;
}
status(enabled?: boolean) {
if (this.disabled || enabled === false) {
return 'disabled';
}
if (this.markedTodo) {
return 'todo';
}
if (this.markedPending) {
return 'pending';
}
if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {
return 'passed';
}
}
isExecutable() {
return !this.disabled;
}
getFullName() {
return this.getSpecName(this);
}
isAssertionError(error: Error) {
return (
error instanceof AssertionError ||
(error && error.name === AssertionError.name)
);
}
} |
1,489 | function specResultCallback(result: SpecResult) {
clearResourcesForRunnable(spec.id);
currentSpec = null;
reporter.specDone(result);
} | type SpecResult = {
id: string;
description: string;
fullName: string;
duration?: number;
failedExpectations: Array<FailedAssertion>;
testPath: string;
passedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
pendingReason: string;
status: Status;
__callsite?: {
getColumnNumber: () => number;
getLineNumber: () => number;
};
}; |
1,490 | function specStarted(spec: Spec) {
currentSpec = spec;
defaultResourcesForRunnable(spec.id, suite.id);
reporter.specStarted(spec.result);
} | class Spec extends realSpec {
constructor(attr: Attributes) {
const resultCallback = attr.resultCallback;
attr.resultCallback = function (result: SpecResult) {
addSuppressedErrors(result);
addAssertionErrors(result);
resultCallback.call(attr, result);
};
const onStart = attr.onStart;
attr.onStart = (context: JasmineSpec) => {
jestExpect.setState({currentTestName: context.getFullName()});
onStart && onStart.call(attr, context);
};
super(attr);
}
} |
1,491 | function specStarted(spec: Spec) {
currentSpec = spec;
defaultResourcesForRunnable(spec.id, suite.id);
reporter.specStarted(spec.result);
} | class Spec {
id: string;
description: string;
resultCallback: (result: SpecResult) => void;
queueableFn: QueueableFn;
beforeAndAfterFns: () => {
befores: Array<QueueableFn>;
afters: Array<QueueableFn>;
};
userContext: () => unknown;
onStart: (spec: Spec) => void;
getSpecName: (spec: Spec) => string;
queueRunnerFactory: typeof queueRunner;
throwOnExpectationFailure: boolean;
initError: Error;
result: SpecResult;
disabled?: boolean;
currentRun?: ReturnType<typeof queueRunner>;
markedTodo?: boolean;
markedPending?: boolean;
expand?: boolean;
static pendingSpecExceptionMessage: string;
static isPendingSpecException(e: Error) {
return !!(
e &&
e.toString &&
e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1
);
}
constructor(attrs: Attributes) {
this.resultCallback = attrs.resultCallback || function () {};
this.id = attrs.id;
this.description = convertDescriptorToString(attrs.description);
this.queueableFn = attrs.queueableFn;
this.beforeAndAfterFns =
attrs.beforeAndAfterFns ||
function () {
return {befores: [], afters: []};
};
this.userContext =
attrs.userContext ||
function () {
return {};
};
this.onStart = attrs.onStart || function () {};
this.getSpecName =
attrs.getSpecName ||
function () {
return '';
};
this.queueRunnerFactory = attrs.queueRunnerFactory || function () {};
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.initError = new Error();
this.initError.name = '';
// Without this line v8 stores references to all closures
// in the stack in the Error object. This line stringifies the stack
// property to allow garbage-collecting objects on the stack
// https://crbug.com/v8/7142
// eslint-disable-next-line no-self-assign
this.initError.stack = this.initError.stack;
this.queueableFn.initError = this.initError;
// @ts-expect-error: misses some fields added later
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
passedExpectations: [],
pendingReason: '',
testPath: attrs.getTestPath(),
};
}
addExpectationResult(
passed: boolean,
data: ExpectationResultFactoryOptions,
isError?: boolean,
) {
const expectationResult = expectationResultFactory(data, this.initError);
if (passed) {
this.result.passedExpectations.push(expectationResult);
} else {
this.result.failedExpectations.push(expectationResult);
if (this.throwOnExpectationFailure && !isError) {
throw new ExpectationFailed();
}
}
}
execute(onComplete?: () => void, enabled?: boolean) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
this.onStart(this);
if (
!this.isExecutable() ||
this.markedPending ||
this.markedTodo ||
enabled === false
) {
complete(enabled);
return;
}
const fns = this.beforeAndAfterFns();
const allFns = fns.befores.concat(this.queueableFn).concat(fns.afters);
this.currentRun = this.queueRunnerFactory({
queueableFns: allFns,
onException() {
// @ts-expect-error: wrong context
self.onException.apply(self, arguments);
},
userContext: this.userContext(),
setTimeout,
clearTimeout,
fail: () => {},
});
this.currentRun.then(() => complete(true));
function complete(enabledAgain?: boolean) {
self.result.status = self.status(enabledAgain);
self.resultCallback(self.result);
if (onComplete) {
onComplete();
}
}
}
cancel() {
if (this.currentRun) {
this.currentRun.cancel();
}
}
onException(error: ExpectationFailed | AssertionErrorWithStack) {
if (Spec.isPendingSpecException(error)) {
this.pend(extractCustomPendingMessage(error));
return;
}
if (error instanceof ExpectationFailed) {
return;
}
this.addExpectationResult(
false,
{
matcherName: '',
passed: false,
expected: '',
actual: '',
error: this.isAssertionError(error)
? assertionErrorMessage(error, {expand: this.expand})
: error,
},
true,
);
}
disable() {
this.disabled = true;
}
pend(message?: string) {
this.markedPending = true;
if (message) {
this.result.pendingReason = message;
}
}
todo() {
this.markedTodo = true;
}
getResult() {
this.result.status = this.status();
return this.result;
}
status(enabled?: boolean) {
if (this.disabled || enabled === false) {
return 'disabled';
}
if (this.markedTodo) {
return 'todo';
}
if (this.markedPending) {
return 'pending';
}
if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {
return 'passed';
}
}
isExecutable() {
return !this.disabled;
}
getFullName() {
return this.getSpecName(this);
}
isAssertionError(error: Error) {
return (
error instanceof AssertionError ||
(error && error.name === AssertionError.name)
);
}
} |
1,492 | constructor(attrs: Attributes) {
this.markedPending = false;
this.markedTodo = false;
this.isFocused = false;
this.id = attrs.id;
this.parentSuite = attrs.parentSuite;
this.description = convertDescriptorToString(attrs.description);
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.beforeFns = [];
this.afterFns = [];
this.beforeAllFns = [];
this.afterAllFns = [];
this.disabled = false;
this.children = [];
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
testPath: attrs.getTestPath(),
};
} | type Attributes = {
id: string;
parentSuite?: Suite;
description: Circus.TestNameLike;
throwOnExpectationFailure?: boolean;
getTestPath: () => string;
}; |
1,493 | constructor(attrs: Attributes) {
this.markedPending = false;
this.markedTodo = false;
this.isFocused = false;
this.id = attrs.id;
this.parentSuite = attrs.parentSuite;
this.description = convertDescriptorToString(attrs.description);
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.beforeFns = [];
this.afterFns = [];
this.beforeAllFns = [];
this.afterAllFns = [];
this.disabled = false;
this.children = [];
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
testPath: attrs.getTestPath(),
};
} | type Attributes = {
id: string;
resultCallback: (result: Spec['result']) => void;
description: Circus.TestNameLike;
throwOnExpectationFailure: unknown;
getTestPath: () => string;
queueableFn: QueueableFn;
beforeAndAfterFns: () => {
befores: Array<QueueableFn>;
afters: Array<QueueableFn>;
};
userContext: () => unknown;
onStart: (context: Spec) => void;
getSpecName: (spec: Spec) => string;
queueRunnerFactory: typeof queueRunner;
}; |
1,494 | beforeEach(fn: QueueableFn) {
this.beforeFns.unshift(fn);
} | type QueueableFn = {
fn: (done: DoneFn) => void;
timeout?: () => number;
initError?: Error;
}; |
1,495 | beforeAll(fn: QueueableFn) {
this.beforeAllFns.push(fn);
} | type QueueableFn = {
fn: (done: DoneFn) => void;
timeout?: () => number;
initError?: Error;
}; |
1,496 | afterEach(fn: QueueableFn) {
this.afterFns.unshift(fn);
} | type QueueableFn = {
fn: (done: DoneFn) => void;
timeout?: () => number;
initError?: Error;
}; |
1,497 | afterAll(fn: QueueableFn) {
this.afterAllFns.unshift(fn);
} | type QueueableFn = {
fn: (done: DoneFn) => void;
timeout?: () => number;
initError?: Error;
}; |
1,498 | function (jasmine: Jasmine, env: any) {
const jasmineInterface = {
describe(description: string, specDefinitions: SpecDefinitionsFn) {
return env.describe(description, specDefinitions);
},
xdescribe(description: string, specDefinitions: SpecDefinitionsFn) {
return env.xdescribe(description, specDefinitions);
},
fdescribe(description: string, specDefinitions: SpecDefinitionsFn) {
return env.fdescribe(description, specDefinitions);
},
it() {
return env.it.apply(env, arguments);
},
xit() {
return env.xit.apply(env, arguments);
},
fit() {
return env.fit.apply(env, arguments);
},
beforeEach() {
if (typeof arguments[0] !== 'function') {
throw new Error(
'Invalid first argument. It must be a callback function.',
);
}
return env.beforeEach.apply(env, arguments);
},
afterEach() {
if (typeof arguments[0] !== 'function') {
throw new Error(
'Invalid first argument. It must be a callback function.',
);
}
return env.afterEach.apply(env, arguments);
},
beforeAll() {
if (typeof arguments[0] !== 'function') {
throw new Error(
'Invalid first argument. It must be a callback function.',
);
}
return env.beforeAll.apply(env, arguments);
},
afterAll() {
if (typeof arguments[0] !== 'function') {
throw new Error(
'Invalid first argument. It must be a callback function.',
);
}
return env.afterAll.apply(env, arguments);
},
pending() {
return env.pending.apply(env, arguments);
},
fail() {
return env.fail.apply(env, arguments);
},
spyOn(obj: Record<string, any>, methodName: string, accessType?: string) {
return env.spyOn(obj, methodName, accessType);
},
jsApiReporter: new jasmine.JsApiReporter({
timer: new jasmine.Timer(),
}),
jasmine,
};
return jasmineInterface;
} | type Jasmine = {
_DEFAULT_TIMEOUT_INTERVAL: number;
DEFAULT_TIMEOUT_INTERVAL: number;
currentEnv_: ReturnType<typeof Env>['prototype'];
getEnv: () => ReturnType<typeof Env>['prototype'];
createSpy: typeof createSpy;
Env: ReturnType<typeof Env>;
JsApiReporter: typeof JsApiReporter;
ReportDispatcher: typeof ReportDispatcher;
Spec: typeof Spec;
SpyRegistry: typeof SpyRegistry;
Suite: typeof Suite;
Timer: typeof Timer;
version: string;
testPath: string;
addMatchers: (matchers: JasmineMatchersObject) => void;
} & AsymmetricMatchers & {process: NodeJS.Process}; |
1,499 | (context: Spec) => void | class Spec extends realSpec {
constructor(attr: Attributes) {
const resultCallback = attr.resultCallback;
attr.resultCallback = function (result: SpecResult) {
addSuppressedErrors(result);
addAssertionErrors(result);
resultCallback.call(attr, result);
};
const onStart = attr.onStart;
attr.onStart = (context: JasmineSpec) => {
jestExpect.setState({currentTestName: context.getFullName()});
onStart && onStart.call(attr, context);
};
super(attr);
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.