jest-jasmine2
Version:
1,564 lines (1,463 loc) • 77 kB
JavaScript
/*!
* /**
* * Copyright (c) Meta Platforms, Inc. and affiliates.
* *
* * This source code is licensed under the MIT license found in the
* * LICENSE file in the root directory of this source tree.
* * /
*/
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/ExpectationFailed.ts":
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = void 0;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
class ExpectationFailed extends Error {}
exports["default"] = ExpectationFailed;
/***/ }),
/***/ "./src/PCancelable.ts":
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = void 0;
var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol;
var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol;
var Promise = globalThis[Symbol.for('jest-native-promise')] || globalThis.Promise;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
class CancelError extends Error {
constructor() {
super('Promise was canceled');
this.name = 'CancelError';
}
}
class PCancelable {
_pending = true;
_canceled = false;
_promise;
_cancel;
// eslint-disable-next-line @typescript-eslint/no-empty-function
_reject = () => {};
constructor(executor) {
this._promise = new Promise((resolve, reject) => {
this._reject = reject;
return executor(fn => {
this._cancel = fn;
}, val => {
this._pending = false;
resolve(val);
}, err => {
this._pending = false;
reject(err);
});
});
}
// eslint-disable-next-line unicorn/no-thenable
then(onFulfilled, onRejected) {
return this._promise.then(onFulfilled, onRejected);
}
catch(onRejected) {
return this._promise.catch(onRejected);
}
cancel() {
if (!this._pending || this._canceled) {
return;
}
if (typeof this._cancel === 'function') {
try {
this._cancel();
} catch (error) {
this._reject(error);
}
}
this._canceled = true;
this._reject(new CancelError());
}
}
exports["default"] = PCancelable;
/***/ }),
/***/ "./src/assertionErrorMessage.ts":
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = void 0;
var _chalk = _interopRequireDefault(require("chalk"));
var _jestMatcherUtils = require("jest-matcher-utils");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const assertOperatorsMap = {
'!=': 'notEqual',
'!==': 'notStrictEqual',
'==': 'equal',
'===': 'strictEqual'
};
const humanReadableOperators = {
deepEqual: 'to deeply equal',
deepStrictEqual: 'to deeply and strictly equal',
equal: 'to be equal',
notDeepEqual: 'not to deeply equal',
notDeepStrictEqual: 'not to deeply and strictly equal',
notEqual: 'to not be equal',
notStrictEqual: 'not be strictly equal',
strictEqual: 'to strictly be equal'
};
const getOperatorName = (operator, stack) => {
if (typeof operator === 'string') {
return assertOperatorsMap[operator] || operator;
}
if (stack.match('.doesNotThrow')) {
return 'doesNotThrow';
}
if (stack.match('.throws')) {
return 'throws';
}
return '';
};
const operatorMessage = operator => {
const niceOperatorName = getOperatorName(operator, '');
const humanReadableOperator = humanReadableOperators[niceOperatorName];
return typeof operator === 'string' ? `${humanReadableOperator || niceOperatorName} to:\n` : '';
};
const assertThrowingMatcherHint = operatorName => operatorName ? _chalk.default.dim('assert') + _chalk.default.dim(`.${operatorName}(`) + _chalk.default.red('function') + _chalk.default.dim(')') : '';
const assertMatcherHint = (operator, operatorName, expected) => {
let message = '';
if (operator === '==' && expected === true) {
message = _chalk.default.dim('assert') + _chalk.default.dim('(') + _chalk.default.red('received') + _chalk.default.dim(')');
} else if (operatorName) {
message = _chalk.default.dim('assert') + _chalk.default.dim(`.${operatorName}(`) + _chalk.default.red('received') + _chalk.default.dim(', ') + _chalk.default.green('expected') + _chalk.default.dim(')');
}
return message;
};
function assertionErrorMessage(error, options) {
const {
expected,
actual,
generatedMessage,
message,
operator,
stack
} = error;
const diffString = (0, _jestMatcherUtils.diff)(expected, actual, options);
const hasCustomMessage = !generatedMessage;
const operatorName = getOperatorName(operator, stack);
const trimmedStack = stack.replace(message, '').replaceAll(/AssertionError(.*)/g, '');
if (operatorName === 'doesNotThrow') {
return `${buildHintString(assertThrowingMatcherHint(operatorName)) + _chalk.default.reset('Expected the function not to throw an error.\n') + _chalk.default.reset('Instead, it threw:\n')} ${(0, _jestMatcherUtils.printReceived)(actual)}${_chalk.default.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '')}${trimmedStack}`;
}
if (operatorName === 'throws') {
if (error.generatedMessage) {
return buildHintString(assertThrowingMatcherHint(operatorName)) + _chalk.default.reset(error.message) + _chalk.default.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') + trimmedStack;
}
return buildHintString(assertThrowingMatcherHint(operatorName)) + _chalk.default.reset('Expected the function to throw an error.\n') + _chalk.default.reset("But it didn't throw anything.") + _chalk.default.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') + trimmedStack;
}
if (operatorName === 'fail') {
return buildHintString(assertMatcherHint(operator, operatorName, expected)) + _chalk.default.reset(hasCustomMessage ? `Message:\n ${message}` : '') + trimmedStack;
}
return `${buildHintString(assertMatcherHint(operator, operatorName, expected)) + _chalk.default.reset(`Expected value ${operatorMessage(operator)}`)} ${(0, _jestMatcherUtils.printExpected)(expected)}\n${_chalk.default.reset('Received:\n')} ${(0, _jestMatcherUtils.printReceived)(actual)}${_chalk.default.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '')}${diffString ? `\n\nDifference:\n\n${diffString}` : ''}${trimmedStack}`;
}
function buildHintString(hint) {
return hint ? `${hint}\n\n` : '';
}
var _default = exports["default"] = assertionErrorMessage;
/***/ }),
/***/ "./src/expectationResultFactory.ts":
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = expectationResultFactory;
var _prettyFormat = require("pretty-format");
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
function messageFormatter({
error,
message,
passed
}) {
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: ${(0, _prettyFormat.format)(error, {
maxDepth: 3
})}`;
}
function stackFormatter(options, initError, errorMessage) {
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.trimEnd()}\n\n${initError.stack}`;
}
return new Error(errorMessage).stack;
}
function expectationResultFactory(options, initError) {
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
};
}
/***/ }),
/***/ "./src/isError.ts":
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = isError;
var _prettyFormat = require("pretty-format");
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
function isError(
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
potentialError) {
// duck-type Error, see #2549
const isError = potentialError !== null && typeof potentialError === 'object' && typeof potentialError.message === 'string' && typeof potentialError.name === 'string';
const message = isError ? null : `Failed: ${(0, _prettyFormat.format)(potentialError, {
maxDepth: 3
})}`;
return {
isError,
message
};
}
/***/ }),
/***/ "./src/jasmine/CallTracker.ts":
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = void 0;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// This file is a heavily modified fork of Jasmine. Original license:
/*
Copyright (c) 2008-2016 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
class CallTracker {
track;
any;
count;
argsFor;
all;
allArgs;
first;
mostRecent;
reset;
constructor() {
let calls = [];
this.track = function (context) {
calls.push(context);
};
this.any = function () {
return calls.length > 0;
};
this.count = function () {
return calls.length;
};
this.argsFor = function (index) {
const call = calls[index];
return call ? call.args : [];
};
this.all = function () {
return calls;
};
this.allArgs = function () {
const callArgs = [];
for (const call of calls) {
callArgs.push(call.args);
}
return callArgs;
};
this.first = function () {
return calls[0];
};
this.mostRecent = function () {
return calls.at(-1);
};
this.reset = function () {
calls = [];
};
}
}
var _default = exports["default"] = CallTracker;
/***/ }),
/***/ "./src/jasmine/Env.ts":
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = jasmineEnv;
var _assert = require("assert");
var _jestUtil = require("jest-util");
var _assertionErrorMessage = _interopRequireDefault(__webpack_require__("./src/assertionErrorMessage.ts"));
var _isError = _interopRequireDefault(__webpack_require__("./src/isError.ts"));
var _queueRunner = _interopRequireDefault(__webpack_require__("./src/queueRunner.ts"));
var _treeProcessor = _interopRequireDefault(__webpack_require__("./src/treeProcessor.ts"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// This file is a heavily modified fork of Jasmine. Original license:
/*
Copyright (c) 2008-2016 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* eslint-disable sort-keys */
function jasmineEnv(j$) {
return class Env {
specFilter;
catchExceptions;
throwOnExpectationFailure;
catchingExceptions;
topSuite;
fail;
pending;
afterAll;
fit;
throwingExpectationFailures;
randomizeTests;
randomTests;
seed;
execute;
fdescribe;
spyOn;
beforeEach;
afterEach;
clearReporters;
addReporter;
it;
xdescribe;
xit;
beforeAll;
todo;
provideFallbackReporter;
allowRespy;
describe;
constructor() {
let totalSpecsDefined = 0;
let catchExceptions = true;
const realSetTimeout = globalThis.setTimeout;
const realClearTimeout = globalThis.clearTimeout;
const runnableResources = {};
const currentlyExecutingSuites = [];
let currentSpec = null;
let throwOnExpectationFailure = false;
let random = false;
let seed = 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.at(-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, _parentRunnableId) {
const resources = {
spies: []
};
runnableResources[id] = resources;
};
const clearResourcesForRunnable = function (id) {
spyRegistry.clearSpies();
delete runnableResources[id];
};
const beforeAndAfterFns = function (suite) {
return function () {
let afters = [];
let befores = [];
while (suite) {
befores = befores.concat(suite.beforeFns);
afters = afters.concat(suite.afterFns);
suite = suite.parentSuite;
}
return {
befores: befores.reverse(),
afters
};
};
};
const getSpecName = function (spec, 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 => {
options.clearTimeout = realClearTimeout;
options.fail = this.fail;
options.setTimeout = realSetTimeout;
return (0, _queueRunner.default)(options);
};
this.topSuite = function () {
return topSuite;
};
const uncaught = err => {
if (currentSpec) {
currentSpec.onException(err);
currentSpec.cancel();
} else {
console.error('Unhandled error');
console.error(err.stack);
}
};
let oldListenersException;
let oldListenersRejection;
const executionSetup = function () {
// Need to ensure we are the only ones handling these exceptions.
oldListenersException = [...process.listeners('uncaughtException')];
oldListenersRejection = [...process.listeners('unhandledRejection')];
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
for (const listener of oldListenersException) {
j$.process.on('uncaughtException', listener);
}
for (const listener of oldListenersRejection) {
j$.process.on('unhandledRejection', listener);
}
};
this.execute = async function (runnablesToRun, suiteTree = topSuite) {
if (!runnablesToRun) {
if (focusedRunnables.length > 0) {
runnablesToRun = focusedRunnables;
} else {
runnablesToRun = [suiteTree.id];
}
}
if (currentlyExecutingSuites.length === 0) {
executionSetup();
}
const lastDeclarationSuite = currentDeclarationSuite;
await (0, _treeProcessor.default)({
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);
defaultResourcesForRunnable(suite.id, suite.parentSuite && suite.parentSuite.id);
if (suite === topSuite) {
reporter.jasmineStarted({
totalSpecsDefined
});
} else {
reporter.suiteStarted(suite.result);
}
},
queueRunnerFactory,
runnableIds: runnablesToRun,
tree: suiteTree
});
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) {
const suite = new j$.Suite({
id: getNextSuiteId(),
description,
parentSuite: currentDeclarationSuite,
throwOnExpectationFailure,
getTestPath() {
return j$.testPath;
}
});
return suite;
};
this.describe = function (description, 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 TypeError(`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 = [];
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, specDefinitions) => {
const parentSuite = currentDeclarationSuite;
parentSuite.addChild(suite);
currentDeclarationSuite = suite;
let declarationError = undefined;
let describeReturnValue;
try {
describeReturnValue = specDefinitions.call(suite);
} catch (error) {
declarationError = error;
}
if ((0, _jestUtil.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) {
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, fn, suite, timeout) => {
totalSpecsDefined++;
const spec = new j$.Spec({
id: getNextSpecId(),
beforeAndAfterFns: beforeAndAfterFns(suite),
resultCallback: specResultCallback,
getSpecName(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) {
clearResourcesForRunnable(spec.id);
currentSpec = null;
reporter.specDone(result);
}
function specStarted(spec) {
currentSpec = spec;
defaultResourcesForRunnable(spec.id, suite.id);
reporter.specStarted(spec.result);
}
};
this.it = function (description, fn, timeout) {
description = (0, _jestUtil.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 TypeError(`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 _jestUtil.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 _assert.AssertionError || error && error.name === _assert.AssertionError.name) {
checkIsError = false;
// @ts-expect-error TODO Possible error: j$.Spec does not have expand property
message = (0, _assertionErrorMessage.default)(error, {
expand: j$.Spec.expand
});
} else {
const check = (0, _isError.default)(error);
checkIsError = check.isError;
message = check.message || undefined;
}
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
});
};
}
};
}
/***/ }),
/***/ "./src/jasmine/JsApiReporter.ts":
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = void 0;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// This file is a heavily modified fork of Jasmine. Original license:
/*
Copyright (c) 2008-2016 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* eslint-disable sort-keys, @typescript-eslint/no-empty-function */
const noopTimer = {
start() {},
elapsed() {
return 0;
}
};
class JsApiReporter {
started;
finished;
runDetails;
jasmineStarted;
jasmineDone;
status;
executionTime;
suiteStarted;
suiteDone;
suiteResults;
suites;
specResults;
specDone;
specs;
specStarted;
constructor(options) {
const timer = options.timer || noopTimer;
let status = 'loaded';
this.started = false;
this.finished = false;
this.runDetails = {};
this.jasmineStarted = () => {
this.started = true;
status = 'started';
timer.start();
};
let executionTime;
function validateAfterAllExceptions({
failedExpectations
}) {
if (failedExpectations && failedExpectations.length > 0) {
throw failedExpectations[0];
}
}
this.jasmineDone = function (runDetails) {
validateAfterAllExceptions(runDetails);
this.finished = true;
this.runDetails = runDetails;
executionTime = timer.elapsed();
status = 'done';
};
this.status = function () {
return status;
};
const suites = [];
const suites_hash = {};
this.specStarted = function () {};
this.suiteStarted = function (result) {
suites_hash[result.id] = result;
};
this.suiteDone = function (result) {
storeSuite(result);
};
this.suiteResults = function (index, length) {
return suites.slice(index, index + length);
};
function storeSuite(result) {
suites.push(result);
suites_hash[result.id] = result;
}
this.suites = function () {
return suites_hash;
};
const specs = [];
this.specDone = function (result) {
specs.push(result);
};
this.specResults = function (index, length) {
return specs.slice(index, index + length);
};
this.specs = function () {
return specs;
};
this.executionTime = function () {
return executionTime;
};
}
}
exports["default"] = JsApiReporter;
/***/ }),
/***/ "./src/jasmine/ReportDispatcher.ts":
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = void 0;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// This file is a heavily modified fork of Jasmine. Original license:
/*
Copyright (c) 2008-2016 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
class ReportDispatcher {
addReporter;
provideFallbackReporter;
clearReporters;
// @ts-expect-error: confused by loop in ctor
jasmineDone;
// @ts-expect-error: confused by loop in ctor
jasmineStarted;
// @ts-expect-error: confused by loop in ctor
specDone;
// @ts-expect-error: confused by loop in ctor
specStarted;
// @ts-expect-error: confused by loop in ctor
suiteDone;
// @ts-expect-error: confused by loop in ctor
suiteStarted;
constructor(methods) {
const dispatchedMethods = methods || [];
for (const method of dispatchedMethods) {
this[method] = function (m) {
return function () {
dispatch(m, arguments);
};
}(method);
}
let reporters = [];
let fallbackReporter = null;
this.addReporter = function (reporter) {
reporters.push(reporter);
};
this.provideFallbackReporter = function (reporter) {
fallbackReporter = reporter;
};
this.clearReporters = function () {
reporters = [];
};
return this;
function dispatch(method, args) {
if (reporters.length === 0 && fallbackReporter !== null) {
reporters.push(fallbackReporter);
}
for (const reporter of reporters) {
if (reporter[method]) {
// @ts-expect-error: wrong context
reporter[method].apply(reporter, args);
}
}
}
}
}
exports["default"] = ReportDispatcher;
/***/ }),
/***/ "./src/jasmine/Spec.ts":
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = void 0;
var _assert = require("assert");
var _jestUtil = require("jest-util");
var _ExpectationFailed = _interopRequireDefault(__webpack_require__("./src/ExpectationFailed.ts"));
var _assertionErrorMessage = _interopRequireDefault(__webpack_require__("./src/assertionErrorMessage.ts"));
var _expectationResultFactory = _interopRequireDefault(__webpack_require__("./src/expectationResultFactory.ts"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// This file is a heavily modified fork of Jasmine. Original license:
/*
Copyright (c) 2008-2016 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* eslint-disable sort-keys, @typescript-eslint/no-empty-function */
class Spec {
id;
description;
resultCallback;
queueableFn;
beforeAndAfterFns;
userContext;
onStart;
getSpecName;
queueRunnerFactory;
throwOnExpectationFailure;
initError;
result;
disabled;
currentRun;
markedTodo;
markedPending;
expand;
static pendingSpecExceptionMessage;
static isPendingSpecException(e) {
return !!(e && e.toString && e.toString().includes(Spec.pendingSpecExceptionMessage));
}
constructor(attrs) {
this.resultCallback = attrs.resultCallback || function () {};
this.id = attrs.id;
this.description = (0, _jestUtil.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;
// eslint-disable-next-line unicorn/error-message
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, data, isError) {
const expectationResult = (0, _expectationResultFactory.default)(data, this.initError);
if (passed) {
this.result.passedExpectations.push(expectationResult);
} else {
this.result.failedExpectations.push(expectationResult);
if (this.throwOnExpectationFailure && !isError) {
throw new _ExpectationFailed.default();
}
}
}
execute(onComplete, enabled) {
// 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) {
self.result.status = self.status(enabledAgain);
self.resultCallback(self.result);
if (onComplete) {
onComplete();
}
}
}
cancel() {
if (this.currentRun) {
this.currentRun.cancel();
}
}
onException(error) {
if (Spec.isPendingSpecException(error)) {
this.pend(extractCustomPendingMessage(error));
return;
}
if (error instanceof _ExpectationFailed.default) {
return;
}
this.addExpectationResult(false, {
matcherName: '',
passed: false,
expected: '',
actual: '',
error: this.isAssertionError(error) ? (0, _assertionErrorMessage.default)(error, {
expand: this.expand
}) : error
}, true);
}
disable() {
this.disabled = true;
}
pend(message) {
this.markedPending = true;
if (message) {
this.result.pendingReason = message;
}
}
todo() {
this.markedTodo = true;
}
getResult() {
this.result.status = this.status();
return this.result;
}
status(enabled) {
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) {
return error instanceof _assert.AssertionError || error && error.name === _assert.AssertionError.name;
}
}
exports["default"] = Spec;
Spec.pendingSpecExceptionMessage = '=> marked Pending';
const extractCustomPendingMessage = function (e) {
const fullMessage = e.toString();
const boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage);
const boilerplateEnd = boilerplateStart + Spec.pendingSpecExceptionMessage.length;
return fullMessage.slice(boilerplateEnd);
};
/***/ }),
/***/ "./src/jasmine/SpyStrategy.ts":
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = void 0;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// This file is a heavily modified fork of Jasmine. Original license:
/*
Copyright (c) 2008-2016 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* eslint-disable @typescript-eslint/no-empty-function */
class SpyStrategy {
identity;
exec;
callThrough;
returnValue;
returnValues;
throwError;
callFake;
stub;
constructor({
name = 'unknown',
fn = function () {},
getSpy = function () {}
} = {}) {
const identity = name;
const originalFn = fn;
let plan = function () {};
this.identity = function () {
return identity;
};
this.exec = function () {
return plan.apply(this, arguments);
};
this.callThrough = function () {
plan = originalFn;
return getSpy();
};
this.returnValue = function (value) {
plan = function () {
return value;
};
return getSpy();
};
this.returnValues = function () {
const values = Array.prototype.slice.call(arguments);
plan = function () {
return values.shift();
};
return getSpy();
};
this.throwError = function (something) {
const error = something instanceof Error ? something : new Error(something);
plan = function () {
throw error;
};
return getSpy();
};
this.callFake = function (fn) {
if (typeof fn !== 'function') {
throw new TypeError(`Argument passed to callFake should be a function, got ${fn}`);
}
plan = fn;
return getSpy();
};
this.stub = function (_fn) {
plan = function () {};
return getSpy();
};
}
}
exports["default"] = SpyStrategy;
/***/ }),
/***/ "./src/jasmine/Suite.ts":
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports["default"] = void 0;
var _jestUtil = require("jest-util");
var _ExpectationFailed = _interopRequireDefault(__webpack_require__("./src/ExpectationFailed.ts"));
var _expectationResultFactory = _interopRequireDefault(__webpack_require__("./src/expectationResultFactory.ts"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// This file is a heavily modified fork of Jasmine. Original license:
/*
Copyright (c) 2008-2016 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* eslint-disable sort-keys */
class Suite {
id;
parentSuite;
description;
throwOnExpecta