From a091a4ac8bb368f23b53148c7f94db377e053be8 Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Sat, 24 Aug 2024 18:17:43 +0100 Subject: [PATCH 1/2] Fix a mistake in release doc --- RELEASE.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 1cead854..a1a7461e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -8,13 +8,7 @@ You'll need a working installation of [git-extras](https://github.com/tj/git-ext $ npm version x.y.z # or npm version [patch|minor|major] ``` -Runs the tests, builds a changelog and the authors file, updates package.json, creates a new tag and pushes the tag and its commits to the sinon repo. - -## Publish to NPM - -``` -$ npm publish -``` +Runs the tests, builds a changelog and the authors file, updates package.json, creates a new tag and pushes the tag and its commits to the sinon repo, as well as publishing. ## Create a GitHub release From 471e275771b987e5012a075a863b7f1182f8cbdc Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Sat, 24 Aug 2024 18:49:21 +0100 Subject: [PATCH 2/2] fix: Support performance.measure+mark fixes #493 --- src/fake-timers-src.js | 24 ++++++++++++++++++++++++ test/fake-timers-test.js | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/fake-timers-src.js b/src/fake-timers-src.js index 31195076..b7cb1b15 100644 --- a/src/fake-timers-src.js +++ b/src/fake-timers-src.js @@ -217,6 +217,25 @@ function withGlobal(_global) { } isPresent.Date = true; + /** + * The PerformanceEntry object encapsulates a single performance metric + * that is part of the browser's performance timeline. + * + * This is an object returned by the `mark` and `measure` methods on the Performance prototype + */ + class FakePerformanceEntry { + constructor(name, entryType, startTime, duration) { + this.name = name; + this.entryType = entryType; + this.startTime = startTime; + this.duration = duration; + } + + toJSON() { + return JSON.stringify({ ...this }); + } + } + /** * @param {number} num * @returns {boolean} @@ -1794,6 +1813,11 @@ function withGlobal(_global) { : NOOP; } }); + // ensure `mark` returns a value that is valid + clock.performance.mark = (name) => + new FakePerformanceEntry(name, "mark", 0, 0); + clock.performance.measure = (name) => + new FakePerformanceEntry(name, "measure", 0, 100); } else if ((config.toFake || []).includes("performance")) { return handleMissingTimer("performance"); } diff --git a/test/fake-timers-test.js b/test/fake-timers-test.js index 42ea8fbe..80e73ebf 100644 --- a/test/fake-timers-test.js +++ b/test/fake-timers-test.js @@ -3632,6 +3632,27 @@ describe("FakeTimers", function () { this.clock.uninstall(); }); + it("should create fake versions of `mark` and `measure` that return PerformanceEntry objects", function () { + if (typeof Performance === "undefined") { + return this.skip(); + } + + function testEntry(performanceEntry) { + assert.keys(performanceEntry, [ + "startTime", + "duration", + "name", + "entryType", + ]); + + assert(typeof performanceEntry.toJSON() === "string"); + } + + this.clock = FakeTimers.install(); + testEntry(performance.mark("foo")); + testEntry(performance.measure("bar", "s", "t")); + }); + it("should replace the getEntries, getEntriesByX methods with noops that return []", function () { if (typeof Performance === "undefined") { return this.skip();