From 099a031cd55ee265b20bea88789ebbf1cfb0bb42 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 27 Sep 2024 20:15:29 +0000 Subject: [PATCH] chore(deps): update dependency sinon to v19 (#5028) * chore(deps): update dependency sinon to v19 * Fix sinon test based on breaking changes in fake timers. * update fake timers in jasmine --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nico Jansen --- package-lock.json | 91 +++++++++++-------- package.json | 2 +- .../child-proxy/child-process-proxy.spec.ts | 8 +- .../process/4-mutation-test-executor.spec.ts | 8 +- .../test/unit/jasmine-test-runner.spec.ts | 8 +- packages/test-helpers/src/tick.ts | 22 ++++- 6 files changed, 87 insertions(+), 52 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9a7f8b3fc6..e19f50fe81 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "mocha": "10.7.3", "prettier": "3.3.3", "rimraf": "5.0.10", - "sinon": "18.0.1", + "sinon": "19.0.2", "sinon-chai": "4.0.0", "source-map-support": "0.5.21", "ts-node": "10.9.2", @@ -5099,39 +5099,43 @@ } }, "node_modules/@sinonjs/fake-timers": { - "version": "11.2.2", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-11.2.2.tgz", - "integrity": "sha512-G2piCSxQ7oWOxwGSAyFHfPIsyeJGXYtc6mFbnFA+kRXkiEnTl8c/8jul2S329iFBnDI9HGoeWWAZvuvOkZccgw==", + "version": "13.0.2", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-13.0.2.tgz", + "integrity": "sha512-4Bb+oqXZTSTZ1q27Izly9lv8B9dlV61CROxPiVtywwzv5SnytJqhvYe6FclHYuXml4cd1VHPo1zd5PmTeJozvA==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { - "@sinonjs/commons": "^3.0.0" + "@sinonjs/commons": "^3.0.1" } }, "node_modules/@sinonjs/samsam": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.0.tgz", - "integrity": "sha512-Bp8KUVlLp8ibJZrnvq2foVhP0IVX2CIprMJPK0vqGqgrDa0OHVKeZyBykqskkrdxV6yKBPmGasO8LVjAKR3Gew==", + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.2.tgz", + "integrity": "sha512-v46t/fwnhejRSFTGqbpn9u+LQ9xJDse10gNnPgAcxgdoCDMXj/G2asWAC/8Qs+BAZDicX+MNZouXT1A7c83kVw==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { - "@sinonjs/commons": "^2.0.0", + "@sinonjs/commons": "^3.0.1", "lodash.get": "^4.4.2", - "type-detect": "^4.0.8" + "type-detect": "^4.1.0" } }, - "node_modules/@sinonjs/samsam/node_modules/@sinonjs/commons": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", - "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "node_modules/@sinonjs/samsam/node_modules/type-detect": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.1.0.tgz", + "integrity": "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==", "dev": true, - "dependencies": { - "type-detect": "4.0.8" + "license": "MIT", + "engines": { + "node": ">=4" } }, "node_modules/@sinonjs/text-encoding": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz", - "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", - "dev": true + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.3.tgz", + "integrity": "sha512-DE427ROAphMQzU4ENbliGYrBSYPXF+TtLg9S8vzeA+OF4ZKzoDdzfL8sxuMUGS/lgRhM6j1URSk9ghf7Xo1tyA==", + "dev": true, + "license": "(Unlicense OR Apache-2.0)" }, "node_modules/@socket.io/component-emitter": { "version": "3.1.2", @@ -16912,16 +16916,27 @@ "dev": true }, "node_modules/nise": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/nise/-/nise-6.0.0.tgz", - "integrity": "sha512-K8ePqo9BFvN31HXwEtTNGzgrPpmvgciDsFz8aztFjt4LqKO/JeFD8tBOeuDiCMXrIl/m1YvfH8auSpxfaD09wg==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/nise/-/nise-6.1.1.tgz", + "integrity": "sha512-aMSAzLVY7LyeM60gvBS423nBmIPP+Wy7St7hsb+8/fc1HmeoHJfLO8CKse4u3BtOZvQLJghYPI2i/1WZrEj5/g==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { - "@sinonjs/commons": "^3.0.0", - "@sinonjs/fake-timers": "^11.2.2", - "@sinonjs/text-encoding": "^0.7.2", + "@sinonjs/commons": "^3.0.1", + "@sinonjs/fake-timers": "^13.0.1", + "@sinonjs/text-encoding": "^0.7.3", "just-extend": "^6.2.0", - "path-to-regexp": "^6.2.1" + "path-to-regexp": "^8.1.0" + } + }, + "node_modules/nise/node_modules/path-to-regexp": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", + "integrity": "sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=16" } }, "node_modules/no-case": { @@ -19556,18 +19571,18 @@ } }, "node_modules/sinon": { - "version": "18.0.1", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-18.0.1.tgz", - "integrity": "sha512-a2N2TDY1uGviajJ6r4D1CyRAkzE9NNVlYOV1wX5xQDuAk0ONgzgRl0EjCQuRCPxOwp13ghsMwt9Gdldujs39qw==", + "version": "19.0.2", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-19.0.2.tgz", + "integrity": "sha512-euuToqM+PjO4UgXeLETsfQiuoyPXlqFezr6YZDFwHR3t4qaX0fZUe1MfPMznTL5f8BWrVS89KduLdMUsxFCO6g==", "dev": true, "license": "BSD-3-Clause", "dependencies": { "@sinonjs/commons": "^3.0.1", - "@sinonjs/fake-timers": "11.2.2", - "@sinonjs/samsam": "^8.0.0", - "diff": "^5.2.0", - "nise": "^6.0.0", - "supports-color": "^7" + "@sinonjs/fake-timers": "^13.0.2", + "@sinonjs/samsam": "^8.0.1", + "diff": "^7.0.0", + "nise": "^6.1.1", + "supports-color": "^7.2.0" }, "funding": { "type": "opencollective", @@ -19585,9 +19600,9 @@ } }, "node_modules/sinon/node_modules/diff": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", - "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-7.0.0.tgz", + "integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==", "dev": true, "license": "BSD-3-Clause", "engines": { diff --git a/package.json b/package.json index 793a3164b8..1ac9c22cfb 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "mocha": "10.7.3", "prettier": "3.3.3", "rimraf": "5.0.10", - "sinon": "18.0.1", + "sinon": "19.0.2", "sinon-chai": "4.0.0", "source-map-support": "0.5.21", "ts-node": "10.9.2", diff --git a/packages/core/test/unit/child-proxy/child-process-proxy.spec.ts b/packages/core/test/unit/child-proxy/child-process-proxy.spec.ts index 4340c720b3..12f3141fa3 100644 --- a/packages/core/test/unit/child-proxy/child-process-proxy.spec.ts +++ b/packages/core/test/unit/child-proxy/child-process-proxy.spec.ts @@ -50,11 +50,9 @@ describe(ChildProcessProxy.name, () => { let childProcessMock: ChildProcessMock; let killStub: sinon.SinonStub; let logMock: Mock; - let clock: sinon.SinonFakeTimers; const workerId = 5; beforeEach(() => { - clock = sinon.useFakeTimers(); childProcessMock = new ChildProcessMock(); forkStub = sinon.stub(childProcess, 'fork'); killStub = sinon.stub(objectUtils, 'kill'); @@ -263,6 +261,7 @@ describe(ChildProcessProxy.name, () => { it('should proxy the message', async () => { // Arrange + const clock = sinon.useFakeTimers(); receiveMessage({ kind: ParentMessageKind.Initialized }); const workerResponse: ParentMessage = { correlationId: 0, @@ -289,6 +288,7 @@ describe(ChildProcessProxy.name, () => { it('should use a unique correlation id for each call', async () => { // Arrange + const clock = sinon.useFakeTimers(); receiveMessage({ kind: ParentMessageKind.Initialized }); // Act @@ -317,6 +317,7 @@ describe(ChildProcessProxy.name, () => { it('should resolve correct promises when receiving responses', async () => { // Arrange + const clock = sinon.useFakeTimers(); receiveMessage({ kind: ParentMessageKind.Initialized }); const delayedEcho = sut.proxy.say('echo'); const delayedHello = sut.proxy.sayHello(); @@ -334,6 +335,7 @@ describe(ChildProcessProxy.name, () => { it('should resolve correct promises when receiving responses out-of-order', async () => { // Arrange + const clock = sinon.useFakeTimers(); receiveMessage({ kind: ParentMessageKind.Initialized }); const delayedEcho = sut.proxy.say('echo'); const delayedHello = sut.proxy.sayHello(); @@ -368,8 +370,10 @@ describe(ChildProcessProxy.name, () => { }); describe('dispose', () => { + let clock: sinon.SinonFakeTimers; beforeEach(() => { sut = createSut(); + clock = sinon.useFakeTimers(); receiveMessage({ kind: ParentMessageKind.Ready }); }); diff --git a/packages/core/test/unit/process/4-mutation-test-executor.spec.ts b/packages/core/test/unit/process/4-mutation-test-executor.spec.ts index a3d481df4a..d72230d690 100644 --- a/packages/core/test/unit/process/4-mutation-test-executor.spec.ts +++ b/packages/core/test/unit/process/4-mutation-test-executor.spec.ts @@ -1,6 +1,6 @@ import sinon from 'sinon'; import { expect } from 'chai'; -import { testInjector, factory, tick } from '@stryker-mutator/test-helpers'; +import { testInjector, factory, tick, createFakeTick } from '@stryker-mutator/test-helpers'; import { Reporter } from '@stryker-mutator/api/report'; import { TestRunner, MutantRunOptions, MutantRunResult, MutantRunStatus, CompleteDryRunResult, TestResult } from '@stryker-mutator/api/test-runner'; import { CheckResult, CheckStatus } from '@stryker-mutator/api/check'; @@ -187,6 +187,7 @@ describe(MutationTestExecutor.name, () => { it('should group mutants buffered by time', async () => { // Arrange const clock = sinon.useFakeTimers(); + const fakeTick = createFakeTick(clock); const plan = mutantRunPlan({ id: '1' }); const plan2 = mutantRunPlan({ id: '2' }); arrangeMutationTestReportHelper(); @@ -217,7 +218,8 @@ describe(MutationTestExecutor.name, () => { const onGoingAct = sut.execute(); // Assert - await tick(); + await fakeTick(); + // Assert that checker is called for the first 2 groups expect(checker.group).calledOnce; expect(checker.check).calledTwice; @@ -226,7 +228,7 @@ describe(MutationTestExecutor.name, () => { // Assert first check resolved, now tick the clock 10s in the future clock.tick(10_001); - await tick(); + await fakeTick(); // Now the second grouping should have happened expect(checker.group).calledTwice; expect(checker.check).calledThrice; diff --git a/packages/jasmine-runner/test/unit/jasmine-test-runner.spec.ts b/packages/jasmine-runner/test/unit/jasmine-test-runner.spec.ts index b5db52d215..1cba94c6b5 100644 --- a/packages/jasmine-runner/test/unit/jasmine-test-runner.spec.ts +++ b/packages/jasmine-runner/test/unit/jasmine-test-runner.spec.ts @@ -1,6 +1,6 @@ import sinon from 'sinon'; import { expect } from 'chai'; -import { factory, assertions, testInjector, tick } from '@stryker-mutator/test-helpers'; +import { factory, assertions, testInjector, createFakeTick } from '@stryker-mutator/test-helpers'; import { TestStatus, CompleteDryRunResult, DryRunStatus, TestRunnerCapabilities } from '@stryker-mutator/api/test-runner'; import jasmine from 'jasmine'; import { MutantCoverage } from '@stryker-mutator/api/core'; @@ -18,6 +18,7 @@ describe(JasmineTestRunner.name, () => { let jasmineEnvStub: sinon.SinonStubbedInstance; let sut: JasmineTestRunner; let clock: sinon.SinonFakeTimers; + let fakeTick: ReturnType; beforeEach(() => { jasmineStub = sinon.createStubInstance(jasmine); @@ -25,6 +26,7 @@ describe(JasmineTestRunner.name, () => { jasmineStub.env = jasmineEnvStub as unknown as jasmine.Env; sinon.stub(helpers, 'createJasmine').returns(jasmineStub); clock = sinon.useFakeTimers(); + fakeTick = createFakeTick(clock); jasmineEnvStub.addReporter.callsFake((rep: jasmine.CustomReporter) => (reporter = rep)); testInjector.options.jasmineConfigFile = 'jasmineConfFile'; sut = testInjector.injector.provideValue(pluginTokens.globalNamespace, '__stryker2__' as const).injectClass(JasmineTestRunner); @@ -95,7 +97,7 @@ describe(JasmineTestRunner.name, () => { // Act const onGoingAct = sut.mutantRun(factory.mutantRunOptions({ activeMutant: factory.mutant({ id: '23' }), mutantActivation: 'static' })); - await tick(); + await fakeTick(); // Assert expect(global.__stryker2__?.activeMutant).eq('23'); @@ -119,7 +121,7 @@ describe(JasmineTestRunner.name, () => { // Act const onGoingAct = sut.mutantRun(factory.mutantRunOptions({ activeMutant: factory.mutant({ id: '23' }), mutantActivation: 'runtime' })); - await tick(); + await fakeTick(); // Assert expect(global.__stryker2__?.activeMutant).undefined; diff --git a/packages/test-helpers/src/tick.ts b/packages/test-helpers/src/tick.ts index 7067fbb2d8..059771cc45 100644 --- a/packages/test-helpers/src/tick.ts +++ b/packages/test-helpers/src/tick.ts @@ -1,13 +1,25 @@ -import { promisify } from 'util'; +import type Sinon from 'sinon'; /** * Wait `n` ticks. This allows async tasks to progress. * @param n The number of ticks to wait */ export async function tick(n = 1): Promise { - const nextTickAsPromised = promisify(process.nextTick); - - for await (const _ of Array.from({ length: n })) { - await nextTickAsPromised(); + for (let i = 0; i < n; i++) { + await nextTick(); } } + +export function createFakeTick(clock: Sinon.SinonFakeTimers) { + return async function fakeTick(n = 1) { + const onGoingTick = tick(n); + clock.tick(n); + await onGoingTick; + }; +} + +function nextTick() { + return new Promise((resolve) => { + process.nextTick(() => resolve()); + }); +}