Skip to content

Commit 70ae316

Browse files
committed
fix: remove version dependency from snapshot tests
1 parent c53b43b commit 70ae316

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
lines changed

packages/benchmark.js-plugin/tests/__snapshots__/unit.test.ts.snap

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ exports[`Benchmark check console output(instrumented=false) 1`] = `
1414
exports[`Benchmark check console output(instrumented=true) 1`] = `
1515
{
1616
"log": [
17-
[
18-
"[CodSpeed] running with @codspeed/benchmark.js v1.0.1",
19-
],
2017
[
2118
" ✔ Measured packages/benchmark.js-plugin/tests/unit.test.ts::RegExpSingle",
2219
],
@@ -42,9 +39,6 @@ exports[`Benchmark.Suite check console output(instrumented=false) 1`] = `
4239
exports[`Benchmark.Suite check console output(instrumented=true) 1`] = `
4340
{
4441
"log": [
45-
[
46-
"[CodSpeed] running with @codspeed/benchmark.js v1.0.1",
47-
],
4842
[
4943
" ✔ Measured packages/benchmark.js-plugin/tests/unit.test.ts::thesuite::RegExp",
5044
],

packages/benchmark.js-plugin/tests/unit.test.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,22 @@ describe("Benchmark", () => {
8787
benchOptions
8888
)
8989
).run();
90-
expect({
91-
log: logSpy.mock.calls,
92-
warn: warnSpy.mock.calls,
93-
}).toMatchSnapshot();
90+
if (instrumented) {
91+
expect(logSpy).toHaveBeenCalledWith(
92+
expect.stringContaining(
93+
"[CodSpeed] running with @codspeed/benchmark.js v"
94+
)
95+
);
96+
expect({
97+
log: logSpy.mock.calls.slice(1),
98+
warn: warnSpy.mock.calls,
99+
}).toMatchSnapshot();
100+
} else {
101+
expect({
102+
log: logSpy.mock.calls.slice(1),
103+
warn: warnSpy.mock.calls,
104+
}).toMatchSnapshot();
105+
}
94106
}
95107
);
96108
});
@@ -179,10 +191,22 @@ describe("Benchmark.Suite", () => {
179191
/o/.test("Hello World!");
180192
}, benchOptions)
181193
.run();
182-
expect({
183-
log: logSpy.mock.calls,
184-
warn: warnSpy.mock.calls,
185-
}).toMatchSnapshot();
194+
if (instrumented) {
195+
expect(logSpy).toHaveBeenCalledWith(
196+
expect.stringContaining(
197+
"[CodSpeed] running with @codspeed/benchmark.js v"
198+
)
199+
);
200+
expect({
201+
log: logSpy.mock.calls.slice(1),
202+
warn: warnSpy.mock.calls,
203+
}).toMatchSnapshot();
204+
} else {
205+
expect({
206+
log: logSpy.mock.calls.slice(1),
207+
warn: warnSpy.mock.calls,
208+
}).toMatchSnapshot();
209+
}
186210
}
187211
);
188212
});

packages/tinybench-plugin/tests/__snapshots__/unit.test.ts.snap

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ exports[`Benchmark.Suite check console output(instrumented=false) 1`] = `
1414
exports[`Benchmark.Suite check console output(instrumented=true) 1`] = `
1515
{
1616
"log": [
17-
[
18-
"[CodSpeed] running with @codspeed/tinybench v1.0.1",
19-
],
2017
[
2118
" ✔ Measured packages/tinybench-plugin/tests/unit.test.ts::RegExp",
2219
],

packages/tinybench-plugin/tests/unit.test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,23 @@ describe("Benchmark.Suite", () => {
8181
/o/.test("Hello World!");
8282
})
8383
.run();
84-
expect({
85-
log: logSpy.mock.calls,
86-
warn: warnSpy.mock.calls,
87-
}).toMatchSnapshot();
84+
// Check that the first log contains "[CodSpeed] running with @codspeed/tinybench v"
85+
if (instrumented) {
86+
expect(logSpy).toHaveBeenCalledWith(
87+
expect.stringContaining(
88+
"[CodSpeed] running with @codspeed/tinybench v"
89+
)
90+
);
91+
expect({
92+
log: logSpy.mock.calls.slice(1),
93+
warn: warnSpy.mock.calls,
94+
}).toMatchSnapshot();
95+
} else {
96+
expect({
97+
log: logSpy.mock.calls,
98+
warn: warnSpy.mock.calls,
99+
}).toMatchSnapshot();
100+
}
88101
}
89102
);
90103
});

0 commit comments

Comments
 (0)