Skip to content

Commit 0ad376f

Browse files
committed
Migrate workspace tests to Vitest
Update the test suite to use Vitest imports and async patterns, add the core test setup needed to shield jsdom tests from Node 25's broken global localStorage, and keep the typed-array normalization fix that the migrated Utils tests now exercise for BigInt views.
1 parent fea5e65 commit 0ad376f

15 files changed

+128
-84
lines changed

packages/browser/test/plugins/BrowserErrorPlugin.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { beforeEach, describe, test } from "@jest/globals";
2-
import { expect } from "expect";
1+
import { beforeEach, describe, expect, test } from "vitest";
32

43
import { ErrorInfo, Event, EventContext, EventPluginContext, ExceptionlessClient, KnownEventDataKeys } from "@exceptionless/core";
54

packages/browser/test/plugins/BrowserIgnoreExtensionErrorsPlugin.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { beforeEach, describe, test } from "@jest/globals";
2-
import { expect } from "expect";
1+
import { beforeEach, describe, expect, test } from "vitest";
32

43
import { EventContext, EventPluginContext, ExceptionlessClient } from "@exceptionless/core";
54

packages/core/src/Utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,9 @@ export function prune(value: unknown, depth: number = 10): unknown {
265265
return Array.from(value);
266266
}
267267

268-
// Check for typed arrays
269-
const TypedArray = Object.getPrototypeOf(Uint8Array);
270-
if (value instanceof TypedArray) {
271-
return Array.from(value as Iterable<unknown>);
268+
// Handle all TypedArray variants, including BigInt typed arrays.
269+
if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
270+
return Array.from(value as unknown as ArrayLike<unknown>);
272271
}
273272

274273
if (hasToJSONFunction(value)) {

packages/core/test/ExceptionlessClient.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { describe, test } from "@jest/globals";
2-
import { expect } from "expect";
1+
import { describe, expect, test } from "vitest";
32

43
import { ExceptionlessClient } from "#/ExceptionlessClient.js";
54
import { KnownEventDataKeys } from "#/models/Event.js";

packages/core/test/Utils.test.ts

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { describe, test } from "@jest/globals";
2-
import { expect } from "expect";
1+
import { describe, expect, test } from "vitest";
32

43
import { endsWith, isEmpty, isMatch, parseVersion, prune, startsWith, stringify, toBoolean } from "#/Utils.js";
54

@@ -94,13 +93,9 @@ describe("Utils", () => {
9493
Object.entries(typedArrayValues).forEach(([key, value]) => {
9594
test(`for ${key}`, () => {
9695
const actual = prune(value, 1);
97-
98-
if (Array.isArray(actual)) {
99-
expect(actual.length).toBe(1);
100-
expect(actual).toContain(1);
101-
} else {
102-
throw new Error("actual is not an array");
103-
}
96+
expect(Array.isArray(actual)).toBe(true);
97+
expect(actual).toHaveLength(1);
98+
expect(actual).toContain(1);
10499
});
105100
});
106101

@@ -112,13 +107,9 @@ describe("Utils", () => {
112107
Object.entries(bigIntTypedArrayValues).forEach(([key, value]) => {
113108
test(`for ${key}`, () => {
114109
const actual = prune(value, 1);
115-
116-
if (Array.isArray(actual)) {
117-
expect(actual.length).toBe(1);
118-
expect(actual).toContain("1n");
119-
} else {
120-
throw new Error("actual is not an array");
121-
}
110+
expect(Array.isArray(actual)).toBe(true);
111+
expect(actual).toHaveLength(1);
112+
expect(actual).toContain("1n");
122113
});
123114
});
124115

@@ -166,15 +157,10 @@ describe("Utils", () => {
166157
});
167158

168159
test("for Error", () => {
169-
try {
170-
throw new Error("error");
171-
} catch (error) {
172-
if (error instanceof Error) {
173-
const expected = { message: error.message, stack: error.stack };
174-
const actual = prune(error, 1);
175-
expect(actual).toStrictEqual(expected);
176-
}
177-
}
160+
const error = new Error("error");
161+
const expected = { message: error.message, stack: error.stack };
162+
const actual = prune(error, 1);
163+
expect(actual).toStrictEqual(expected);
178164
});
179165

180166
test("for Map", () => {
@@ -450,15 +436,10 @@ describe("Utils", () => {
450436
});
451437

452438
test("for Error", () => {
453-
try {
454-
throw new Error("error");
455-
} catch (error) {
456-
if (error instanceof Error) {
457-
const expected = JSON.stringify({ stack: error.stack, message: error.message });
458-
const actual = stringify(error, [], 1);
459-
expect(actual).toStrictEqual(expected);
460-
}
461-
}
439+
const error = new Error("error");
440+
const expected = JSON.stringify({ stack: error.stack, message: error.message });
441+
const actual = stringify(error, [], 1);
442+
expect(actual).toStrictEqual(expected);
462443
});
463444

464445
test("for Map", () => {
@@ -619,11 +600,11 @@ describe("Utils", () => {
619600
});
620601

621602
test("*password*", () => {
622-
JSON.stringify(expect(stringify(user, ["*password*"])).toBe(JSON.stringify({ id: 1, name: "Blake", customValue: "Password", value: {} })));
603+
expect(stringify(user, ["*password*"])).toBe(JSON.stringify({ id: 1, name: "Blake", customValue: "Password", value: {} }));
623604
});
624605

625606
test("*Password*", () => {
626-
JSON.stringify(expect(stringify(user, ["*Password*"])).toBe(JSON.stringify({ id: 1, name: "Blake", customValue: "Password", value: {} })));
607+
expect(stringify(user, ["*Password*"])).toBe(JSON.stringify({ id: 1, name: "Blake", customValue: "Password", value: {} }));
627608
});
628609

629610
test("*Address", () => {

packages/core/test/configuration/Configuration.test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { describe, test } from "@jest/globals";
2-
import { expect } from "expect";
1+
import { describe, expect, test } from "vitest";
32

43
import { Configuration } from "#/configuration/Configuration.js";
54

@@ -85,16 +84,18 @@ describe("Configuration", () => {
8584
expect(config.plugins[2].priority).toBe(3);
8685
});
8786

88-
test("should call subscribe handler", (done) => {
89-
const config = new Configuration();
90-
expect(config.settings.someValue).toBeUndefined();
87+
test("should call subscribe handler", () => {
88+
return new Promise<void>((resolve) => {
89+
const config = new Configuration();
90+
expect(config.settings.someValue).toBeUndefined();
9191

92-
config.subscribeServerSettingsChange((c: Configuration) => {
93-
expect(c.settings.someValue).toBe("UNIT_TEST_API_KEY");
94-
expect(config.settings.someValue).toBe("UNIT_TEST_API_KEY");
95-
done();
96-
});
92+
config.subscribeServerSettingsChange((c: Configuration) => {
93+
expect(c.settings.someValue).toBe("UNIT_TEST_API_KEY");
94+
expect(config.settings.someValue).toBe("UNIT_TEST_API_KEY");
95+
resolve();
96+
});
9797

98-
config.applyServerSettings({ settings: { someValue: "UNIT_TEST_API_KEY" }, version: 2 });
98+
config.applyServerSettings({ settings: { someValue: "UNIT_TEST_API_KEY" }, version: 2 });
99+
});
99100
});
100101
});

packages/core/test/plugins/EventPluginManager.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { describe, test } from "@jest/globals";
2-
import { expect } from "expect";
1+
import { describe, expect, test } from "vitest";
32

43
import { EventContext } from "#/models/EventContext.js";
54
import { ExceptionlessClient } from "#/ExceptionlessClient.js";

packages/core/test/plugins/default/ConfigurationDefaultsPlugin.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { describe, test } from "@jest/globals";
2-
import { expect } from "expect";
1+
import { describe, expect, test } from "vitest";
32

43
import { ExceptionlessClient } from "#/ExceptionlessClient.js";
54
import { Event } from "#/models/Event.js";

packages/core/test/plugins/default/DuplicateCheckerPlugin.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { beforeEach, describe, test } from "@jest/globals";
2-
import { expect } from "expect";
1+
import { beforeEach, describe, expect, test } from "vitest";
32

43
import { DuplicateCheckerPlugin } from "#/plugins/default/DuplicateCheckerPlugin.js";
54
import { ExceptionlessClient } from "#/ExceptionlessClient.js";

packages/core/test/plugins/default/EventExclusionPlugin.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { describe, test } from "@jest/globals";
2-
import { expect } from "expect";
1+
import { describe, expect, test } from "vitest";
32

43
import { ExceptionlessClient } from "#/ExceptionlessClient.js";
54
import { Event, EventType, KnownEventDataKeys, LogLevel } from "#/models/Event.js";

0 commit comments

Comments
 (0)