Skip to content

Commit 4e3002b

Browse files
committed
feat(vitest-plugin): use global __VERSION__
1 parent f89c046 commit 4e3002b

File tree

3 files changed

+9
-36
lines changed

3 files changed

+9
-36
lines changed
Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
import { describe, expect, it, vi } from "vitest";
2+
import globalSetup from "../globalSetup";
23

34
console.log = vi.fn();
45

5-
async function importFreshGlobalSetup() {
6-
return (
7-
(await import(
8-
`../globalSetup?${Date.now()}`
9-
)) as typeof import("../globalSetup")
10-
).default;
11-
}
12-
13-
describe("globalSetup", async () => {
14-
it("with version, should log the correct message on setup and teardown, and fail when teardown is called twice", async () => {
15-
vi.stubGlobal("__VERSION__", "1.0.0");
16-
const globalSetup = await importFreshGlobalSetup();
6+
describe("globalSetup", () => {
7+
it("should log the correct message on setup and teardown, and fail when teardown is called twice", async () => {
178
const teardown = globalSetup();
189

1910
expect(console.log).toHaveBeenCalledWith(
@@ -28,22 +19,4 @@ describe("globalSetup", async () => {
2819

2920
expect(() => teardown()).toThrowError("teardown called twice");
3021
});
31-
32-
it("without version, should log the correct message on setup and teardown, and fail when teardown is called twice", async () => {
33-
vi.unstubAllGlobals();
34-
const globalSetup = await importFreshGlobalSetup();
35-
const teardown = globalSetup();
36-
37-
expect(console.log).toHaveBeenCalledWith(
38-
"[CodSpeed] @codspeed/vitest-plugin - setup"
39-
);
40-
41-
teardown();
42-
43-
expect(console.log).toHaveBeenCalledWith(
44-
"[CodSpeed] @codspeed/vitest-plugin - teardown"
45-
);
46-
47-
expect(() => teardown()).toThrowError("teardown called twice");
48-
});
4922
});
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare const __VERSION__: string | undefined;
1+
declare const __VERSION__: string;
22

33
/**
44
* @deprecated
@@ -12,15 +12,12 @@ function logCodSpeed(message: string) {
1212
let teardownHappened = false;
1313

1414
export default function () {
15-
// log the version of the plugin if the global variable is defined
16-
const VERSION = typeof __VERSION__ === "string" ? `v${__VERSION__} ` : "";
17-
18-
logCodSpeed(`@codspeed/vitest-plugin ${VERSION}- setup`);
15+
logCodSpeed(`@codspeed/vitest-plugin v${__VERSION__} - setup`);
1916

2017
return () => {
2118
if (teardownHappened) throw new Error("teardown called twice");
2219
teardownHappened = true;
2320

24-
logCodSpeed(`@codspeed/vitest-plugin ${VERSION}- teardown`);
21+
logCodSpeed(`@codspeed/vitest-plugin v${__VERSION__} - teardown`);
2522
};
2623
}

packages/vitest-plugin/vitest.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import codspeedPlugin from "./dist/index.mjs";
44
export default defineConfig({
55
// @ts-expect-error - TODO: investigate why importing from '.' wants to import only "main" field and thus fail
66
plugins: [codspeedPlugin()],
7+
define: {
8+
__VERSION__: JSON.stringify("1.0.0"),
9+
},
710
test: {
811
exclude: ["**/tests/**/*", "**/.rollup.cache/**/*"],
912
mockReset: true,

0 commit comments

Comments
 (0)