* Bump the npm group with 12 updates Bumps the npm group with 12 updates: | Package | From | To | | --- | --- | --- | | [@octokit/types](https://github.com/octokit/types.ts) | `12.1.1` | `12.3.0` | | [@types/uuid](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/uuid) | `9.0.6` | `9.0.7` | | [@types/adm-zip](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/adm-zip) | `0.5.3` | `0.5.4` | | [@types/js-yaml](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/js-yaml) | `4.0.8` | `4.0.9` | | [@types/semver](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/semver) | `7.5.4` | `7.5.5` | | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) | `6.9.1` | `6.12.0` | | [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) | `6.9.1` | `6.12.0` | | [eslint](https://github.com/eslint/eslint) | `8.52.0` | `8.54.0` | | [nock](https://github.com/nock/nock) | `13.3.7` | `13.3.8` | | [sinon](https://github.com/sinonjs/sinon) | `17.0.0` | `17.0.1` | | [@types/sinon](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/sinon) | `10.0.20` | `17.0.1` | | [typescript](https://github.com/Microsoft/TypeScript) | `5.2.2` | `5.3.2` | Updates `@octokit/types` from 12.1.1 to 12.3.0 - [Release notes](https://github.com/octokit/types.ts/releases) - [Commits](https://github.com/octokit/types.ts/compare/v12.1.1...v12.3.0) Updates `@types/uuid` from 9.0.6 to 9.0.7 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/uuid) Updates `@types/adm-zip` from 0.5.3 to 0.5.4 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/adm-zip) Updates `@types/js-yaml` from 4.0.8 to 4.0.9 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/js-yaml) Updates `@types/semver` from 7.5.4 to 7.5.5 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/semver) Updates `@typescript-eslint/eslint-plugin` from 6.9.1 to 6.12.0 - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.12.0/packages/eslint-plugin) Updates `@typescript-eslint/parser` from 6.9.1 to 6.12.0 - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.12.0/packages/parser) Updates `eslint` from 8.52.0 to 8.54.0 - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v8.52.0...v8.54.0) Updates `nock` from 13.3.7 to 13.3.8 - [Release notes](https://github.com/nock/nock/releases) - [Changelog](https://github.com/nock/nock/blob/main/CHANGELOG.md) - [Commits](https://github.com/nock/nock/compare/v13.3.7...v13.3.8) Updates `sinon` from 17.0.0 to 17.0.1 - [Release notes](https://github.com/sinonjs/sinon/releases) - [Changelog](https://github.com/sinonjs/sinon/blob/main/docs/changelog.md) - [Commits](https://github.com/sinonjs/sinon/compare/v17.0.0...v17.0.1) Updates `@types/sinon` from 10.0.20 to 17.0.1 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/sinon) Updates `typescript` from 5.2.2 to 5.3.2 - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/commits) --- updated-dependencies: - dependency-name: "@octokit/types" dependency-type: direct:production update-type: version-update:semver-minor dependency-group: npm - dependency-name: "@types/uuid" dependency-type: direct:production update-type: version-update:semver-patch dependency-group: npm - dependency-name: "@types/adm-zip" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: npm - dependency-name: "@types/js-yaml" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: npm - dependency-name: "@types/semver" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: npm - dependency-name: "@typescript-eslint/eslint-plugin" dependency-type: direct:development update-type: version-update:semver-minor dependency-group: npm - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-minor dependency-group: npm - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-minor dependency-group: npm - dependency-name: nock dependency-type: direct:development update-type: version-update:semver-patch dependency-group: npm - dependency-name: sinon dependency-type: direct:development update-type: version-update:semver-patch dependency-group: npm - dependency-name: "@types/sinon" dependency-type: direct:development update-type: version-update:semver-major dependency-group: npm - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-minor dependency-group: npm ... Signed-off-by: dependabot[bot] <support@github.com> * Update checked-in dependencies * Rebuild --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
336 lines
10 KiB
JavaScript
336 lines
10 KiB
JavaScript
"use strict";
|
|
/** @module */
|
|
|
|
const arrayProto = require("@sinonjs/commons").prototypes.array;
|
|
const calledInOrder = require("@sinonjs/commons").calledInOrder;
|
|
const createMatcher = require("@sinonjs/samsam").createMatcher;
|
|
const orderByFirstCall = require("@sinonjs/commons").orderByFirstCall;
|
|
const timesInWords = require("./util/core/times-in-words");
|
|
const inspect = require("util").inspect;
|
|
const stringSlice = require("@sinonjs/commons").prototypes.string.slice;
|
|
const globalObject = require("@sinonjs/commons").global;
|
|
|
|
const arraySlice = arrayProto.slice;
|
|
const concat = arrayProto.concat;
|
|
const forEach = arrayProto.forEach;
|
|
const join = arrayProto.join;
|
|
const splice = arrayProto.splice;
|
|
|
|
function applyDefaults(obj, defaults) {
|
|
for (const key of Object.keys(defaults)) {
|
|
const val = obj[key];
|
|
if (val === null || typeof val === "undefined") {
|
|
obj[key] = defaults[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @typedef {object} CreateAssertOptions
|
|
* @global
|
|
*
|
|
* @property {boolean} [shouldLimitAssertionLogs] default is false
|
|
* @property {number} [assertionLogLimit] default is 10K
|
|
*/
|
|
|
|
/**
|
|
* Create an assertion object that exposes several methods to invoke
|
|
*
|
|
* @param {CreateAssertOptions} [opts] options bag
|
|
* @returns {object} object with multiple assertion methods
|
|
*/
|
|
function createAssertObject(opts) {
|
|
const cleanedAssertOptions = opts || {};
|
|
applyDefaults(cleanedAssertOptions, {
|
|
shouldLimitAssertionLogs: false,
|
|
assertionLogLimit: 1e4,
|
|
});
|
|
|
|
const assert = {
|
|
failException: "AssertError",
|
|
|
|
fail: function fail(message) {
|
|
let msg = message;
|
|
if (cleanedAssertOptions.shouldLimitAssertionLogs) {
|
|
msg = message.substring(
|
|
0,
|
|
cleanedAssertOptions.assertionLogLimit,
|
|
);
|
|
}
|
|
const error = new Error(msg);
|
|
error.name = this.failException || assert.failException;
|
|
|
|
throw error;
|
|
},
|
|
|
|
pass: function pass() {
|
|
return;
|
|
},
|
|
|
|
callOrder: function assertCallOrder() {
|
|
verifyIsStub.apply(null, arguments);
|
|
let expected = "";
|
|
let actual = "";
|
|
|
|
if (!calledInOrder(arguments)) {
|
|
try {
|
|
expected = join(arguments, ", ");
|
|
const calls = arraySlice(arguments);
|
|
let i = calls.length;
|
|
while (i) {
|
|
if (!calls[--i].called) {
|
|
splice(calls, i, 1);
|
|
}
|
|
}
|
|
actual = join(orderByFirstCall(calls), ", ");
|
|
} catch (e) {
|
|
// If this fails, we'll just fall back to the blank string
|
|
}
|
|
|
|
failAssertion(
|
|
this,
|
|
`expected ${expected} to be called in order but were called as ${actual}`,
|
|
);
|
|
} else {
|
|
assert.pass("callOrder");
|
|
}
|
|
},
|
|
|
|
callCount: function assertCallCount(method, count) {
|
|
verifyIsStub(method);
|
|
|
|
let msg;
|
|
if (typeof count !== "number") {
|
|
msg =
|
|
`expected ${inspect(count)} to be a number ` +
|
|
`but was of type ${typeof count}`;
|
|
failAssertion(this, msg);
|
|
} else if (method.callCount !== count) {
|
|
msg =
|
|
`expected %n to be called ${timesInWords(count)} ` +
|
|
`but was called %c%C`;
|
|
failAssertion(this, method.printf(msg));
|
|
} else {
|
|
assert.pass("callCount");
|
|
}
|
|
},
|
|
|
|
expose: function expose(target, options) {
|
|
if (!target) {
|
|
throw new TypeError("target is null or undefined");
|
|
}
|
|
|
|
const o = options || {};
|
|
const prefix =
|
|
(typeof o.prefix === "undefined" && "assert") || o.prefix;
|
|
const includeFail =
|
|
typeof o.includeFail === "undefined" || Boolean(o.includeFail);
|
|
const instance = this;
|
|
|
|
forEach(Object.keys(instance), function (method) {
|
|
if (
|
|
method !== "expose" &&
|
|
(includeFail || !/^(fail)/.test(method))
|
|
) {
|
|
target[exposedName(prefix, method)] = instance[method];
|
|
}
|
|
});
|
|
|
|
return target;
|
|
},
|
|
|
|
match: function match(actual, expectation) {
|
|
const matcher = createMatcher(expectation);
|
|
if (matcher.test(actual)) {
|
|
assert.pass("match");
|
|
} else {
|
|
const formatted = [
|
|
"expected value to match",
|
|
` expected = ${inspect(expectation)}`,
|
|
` actual = ${inspect(actual)}`,
|
|
];
|
|
|
|
failAssertion(this, join(formatted, "\n"));
|
|
}
|
|
},
|
|
};
|
|
|
|
function verifyIsStub() {
|
|
const args = arraySlice(arguments);
|
|
|
|
forEach(args, function (method) {
|
|
if (!method) {
|
|
assert.fail("fake is not a spy");
|
|
}
|
|
|
|
if (method.proxy && method.proxy.isSinonProxy) {
|
|
verifyIsStub(method.proxy);
|
|
} else {
|
|
if (typeof method !== "function") {
|
|
assert.fail(`${method} is not a function`);
|
|
}
|
|
|
|
if (typeof method.getCall !== "function") {
|
|
assert.fail(`${method} is not stubbed`);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function verifyIsValidAssertion(assertionMethod, assertionArgs) {
|
|
switch (assertionMethod) {
|
|
case "notCalled":
|
|
case "called":
|
|
case "calledOnce":
|
|
case "calledTwice":
|
|
case "calledThrice":
|
|
if (assertionArgs.length !== 0) {
|
|
assert.fail(
|
|
`${assertionMethod} takes 1 argument but was called with ${
|
|
assertionArgs.length + 1
|
|
} arguments`,
|
|
);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
function failAssertion(object, msg) {
|
|
const obj = object || globalObject;
|
|
const failMethod = obj.fail || assert.fail;
|
|
failMethod.call(obj, msg);
|
|
}
|
|
|
|
function mirrorPropAsAssertion(name, method, message) {
|
|
let msg = message;
|
|
let meth = method;
|
|
if (arguments.length === 2) {
|
|
msg = method;
|
|
meth = name;
|
|
}
|
|
|
|
assert[name] = function (fake) {
|
|
verifyIsStub(fake);
|
|
|
|
const args = arraySlice(arguments, 1);
|
|
let failed = false;
|
|
|
|
verifyIsValidAssertion(name, args);
|
|
|
|
if (typeof meth === "function") {
|
|
failed = !meth(fake);
|
|
} else {
|
|
failed =
|
|
typeof fake[meth] === "function"
|
|
? !fake[meth].apply(fake, args)
|
|
: !fake[meth];
|
|
}
|
|
|
|
if (failed) {
|
|
failAssertion(
|
|
this,
|
|
(fake.printf || fake.proxy.printf).apply(
|
|
fake,
|
|
concat([msg], args),
|
|
),
|
|
);
|
|
} else {
|
|
assert.pass(name);
|
|
}
|
|
};
|
|
}
|
|
|
|
function exposedName(prefix, prop) {
|
|
return !prefix || /^fail/.test(prop)
|
|
? prop
|
|
: prefix +
|
|
stringSlice(prop, 0, 1).toUpperCase() +
|
|
stringSlice(prop, 1);
|
|
}
|
|
|
|
mirrorPropAsAssertion(
|
|
"called",
|
|
"expected %n to have been called at least once but was never called",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"notCalled",
|
|
function (spy) {
|
|
return !spy.called;
|
|
},
|
|
"expected %n to not have been called but was called %c%C",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"calledOnce",
|
|
"expected %n to be called once but was called %c%C",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"calledTwice",
|
|
"expected %n to be called twice but was called %c%C",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"calledThrice",
|
|
"expected %n to be called thrice but was called %c%C",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"calledOn",
|
|
"expected %n to be called with %1 as this but was called with %t",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"alwaysCalledOn",
|
|
"expected %n to always be called with %1 as this but was called with %t",
|
|
);
|
|
mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new");
|
|
mirrorPropAsAssertion(
|
|
"alwaysCalledWithNew",
|
|
"expected %n to always be called with new",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"calledWith",
|
|
"expected %n to be called with arguments %D",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"calledWithMatch",
|
|
"expected %n to be called with match %D",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"alwaysCalledWith",
|
|
"expected %n to always be called with arguments %D",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"alwaysCalledWithMatch",
|
|
"expected %n to always be called with match %D",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"calledWithExactly",
|
|
"expected %n to be called with exact arguments %D",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"calledOnceWithExactly",
|
|
"expected %n to be called once and with exact arguments %D",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"calledOnceWithMatch",
|
|
"expected %n to be called once and with match %D",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"alwaysCalledWithExactly",
|
|
"expected %n to always be called with exact arguments %D",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"neverCalledWith",
|
|
"expected %n to never be called with arguments %*%C",
|
|
);
|
|
mirrorPropAsAssertion(
|
|
"neverCalledWithMatch",
|
|
"expected %n to never be called with match %*%C",
|
|
);
|
|
mirrorPropAsAssertion("threw", "%n did not throw exception%C");
|
|
mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C");
|
|
|
|
return assert;
|
|
}
|
|
|
|
module.exports = createAssertObject();
|
|
module.exports.createAssertObject = createAssertObject;
|