@terreno/test 57.18.0 → 57.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1681 -0
- package/README.md +6 -0
- package/dist/assertions/expectAPIError.d.ts +18 -0
- package/dist/assertions/expectAPIError.js +33 -0
- package/dist/assertions/strictResponseProperties.d.ts +14 -0
- package/dist/assertions/strictResponseProperties.js +37 -0
- package/dist/cache/mongoTestCache.js +2 -2
- package/dist/cli/collectFiles.d.ts +38 -0
- package/dist/cli/collectFiles.js +73 -0
- package/dist/cli/testHygiene.d.ts +134 -0
- package/dist/cli/testHygiene.js +357 -0
- package/dist/cli/testHygieneCli.d.ts +2 -0
- package/dist/cli/testHygieneCli.js +5 -0
- package/dist/cli/testHygieneRules.d.ts +58 -0
- package/dist/cli/testHygieneRules.js +517 -0
- package/dist/cli/testShard.d.ts +155 -0
- package/dist/cli/testShard.js +377 -0
- package/dist/cli/testShardCli.d.ts +2 -0
- package/dist/cli/testShardCli.js +5 -0
- package/dist/expo/authTokenStorage.d.ts +76 -0
- package/dist/expo/authTokenStorage.js +160 -0
- package/dist/expo/expoModuleMocks.d.ts +24 -0
- package/dist/expo/expoModuleMocks.js +456 -0
- package/dist/expo/libraryModuleMocks.d.ts +17 -0
- package/dist/expo/libraryModuleMocks.js +347 -0
- package/dist/expo/mockHelpers.d.ts +39 -0
- package/dist/expo/mockHelpers.js +45 -0
- package/dist/expo/mockModuleAliases.d.ts +50 -0
- package/dist/expo/mockModuleAliases.js +174 -0
- package/dist/expo/reactNativeMock.d.ts +39 -0
- package/dist/expo/reactNativeMock.js +421 -0
- package/dist/expo/registerExpoTestEnvironment.d.ts +69 -0
- package/dist/expo/registerExpoTestEnvironment.js +163 -0
- package/dist/expo/renderWithTerreno.d.ts +47 -0
- package/dist/expo/renderWithTerreno.js +47 -0
- package/dist/http/authWithToken.d.ts +20 -0
- package/dist/http/authWithToken.js +30 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +33 -1
- package/dist/logging/silenceLogs.js +0 -2
- package/dist/mocks/aiSdk.d.ts +77 -0
- package/dist/mocks/aiSdk.js +102 -0
- package/dist/mocks/cloudTasks.d.ts +91 -0
- package/dist/mocks/cloudTasks.js +197 -0
- package/dist/mocks/expoPush.d.ts +53 -0
- package/dist/mocks/expoPush.js +57 -0
- package/dist/mocks/gcs.d.ts +101 -0
- package/dist/mocks/gcs.js +162 -0
- package/dist/mocks/googleAuth.d.ts +69 -0
- package/dist/mocks/googleAuth.js +55 -0
- package/dist/mocks/mockGroup.d.ts +11 -0
- package/dist/mocks/mockGroup.js +21 -0
- package/dist/mocks/notifiers.d.ts +21 -0
- package/dist/mocks/notifiers.js +26 -0
- package/dist/mocks/sendgrid.d.ts +22 -0
- package/dist/mocks/sendgrid.js +32 -0
- package/dist/mocks/twilio.d.ts +72 -0
- package/dist/mocks/twilio.js +64 -0
- package/dist/preload/registerBackendPreload.js +4 -1
- package/dist/time/freezeTime.d.ts +16 -0
- package/dist/time/freezeTime.js +49 -0
- package/dist/transaction/testTransaction.d.ts +43 -6
- package/dist/transaction/testTransaction.js +371 -92
- package/dist/utils/waitUntil.d.ts +22 -0
- package/dist/utils/waitUntil.js +34 -0
- package/package.json +53 -8
- package/src/assertions/expectAPIError.ts +51 -0
- package/src/assertions/strictResponseProperties.ts +42 -0
- package/src/cache/mongoTestCache.ts +2 -2
- package/src/cli/collectFiles.ts +115 -0
- package/src/cli/testHygiene.ts +539 -0
- package/src/cli/testHygieneCli.ts +4 -0
- package/src/cli/testHygieneRules.ts +719 -0
- package/src/cli/testShard.ts +532 -0
- package/src/cli/testShardCli.ts +4 -0
- package/src/expo/authTokenStorage.ts +198 -0
- package/src/expo/expoModuleMocks.ts +503 -0
- package/src/expo/libraryModuleMocks.ts +411 -0
- package/src/expo/mockHelpers.ts +73 -0
- package/src/expo/mockModuleAliases.ts +252 -0
- package/src/expo/reactNativeMock.ts +534 -0
- package/src/expo/registerExpoTestEnvironment.ts +260 -0
- package/src/expo/renderWithTerreno.ts +79 -0
- package/src/http/authWithToken.ts +38 -0
- package/src/index.ts +82 -1
- package/src/logging/silenceLogs.ts +0 -2
- package/src/mocks/aiSdk.ts +199 -0
- package/src/mocks/cloudTasks.ts +323 -0
- package/src/mocks/expoPush.ts +134 -0
- package/src/mocks/gcs.ts +305 -0
- package/src/mocks/googleAuth.ts +136 -0
- package/src/mocks/mockGroup.ts +32 -0
- package/src/mocks/notifiers.ts +36 -0
- package/src/mocks/sendgrid.ts +57 -0
- package/src/mocks/twilio.ts +143 -0
- package/src/preload/registerBackendPreload.ts +4 -1
- package/src/time/freezeTime.ts +61 -0
- package/src/transaction/testTransaction.ts +456 -124
- package/src/utils/waitUntil.ts +47 -0
- package/biome.jsonc +0 -20
- package/bunfig.toml +0 -16
- package/src/cache/mongoTestCache.test.ts +0 -103
- package/src/env/setTerrenoTestEnv.test.ts +0 -26
- package/src/http/authAsUser.test.ts +0 -40
- package/src/http/getBaseServer.test.ts +0 -45
- package/src/logging/setupEnvironment.test.ts +0 -24
- package/src/logging/silenceLogs.test.ts +0 -52
- package/src/logging/testLogger.test.ts +0 -58
- package/src/mocks/sentryBun.test.ts +0 -230
- package/src/mongo/connection.test.ts +0 -43
- package/src/mongo/mongoServer.test.ts +0 -99
- package/src/preload/registerBackendPreload.test.ts +0 -10
- package/src/transaction/testTransaction.test.ts +0 -64
- package/src/utils/helpers.test.ts +0 -46
- package/tsconfig.json +0 -18
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface WaitUntilOptions {
|
|
2
|
+
/** Maximum time to poll before throwing. Keep it below the test's own timeout so this error wins. */
|
|
3
|
+
timeoutMs?: number;
|
|
4
|
+
/** Delay between polling attempts. */
|
|
5
|
+
intervalMs?: number;
|
|
6
|
+
/** Named in the timeout error so a failure says what never happened. */
|
|
7
|
+
label?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const delay = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Polls `predicate` until it returns (or resolves to) true, or throws after `timeoutMs`.
|
|
14
|
+
*
|
|
15
|
+
* Use it instead of a fixed sleep: it returns as soon as the condition holds and fails with the
|
|
16
|
+
* label and elapsed time when it never does. Elapsed time uses `performance.now()`, so polling
|
|
17
|
+
* still advances while `Date.now()` is frozen by `freezeTime` or `setSystemTime`.
|
|
18
|
+
*/
|
|
19
|
+
export const waitUntil = async (
|
|
20
|
+
predicate: () => boolean | Promise<boolean>,
|
|
21
|
+
{timeoutMs = 1000, intervalMs = 10, label}: WaitUntilOptions = {}
|
|
22
|
+
): Promise<void> => {
|
|
23
|
+
const start = performance.now();
|
|
24
|
+
for (;;) {
|
|
25
|
+
if (await predicate()) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const elapsed = performance.now() - start;
|
|
29
|
+
if (elapsed >= timeoutMs) {
|
|
30
|
+
const labelSuffix = label ? ` waiting for: ${label}` : "";
|
|
31
|
+
throw new Error(`waitUntil timed out after ${Math.round(elapsed)}ms${labelSuffix}`);
|
|
32
|
+
}
|
|
33
|
+
await delay(intervalMs);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Waits until a Bun `mock()` / `spyOn()` function has been called at least `callCount` times. */
|
|
38
|
+
export const waitForCalls = async (
|
|
39
|
+
mockFn: {mock: {calls: unknown[]}},
|
|
40
|
+
callCount: number,
|
|
41
|
+
options: WaitUntilOptions = {}
|
|
42
|
+
): Promise<void> => {
|
|
43
|
+
await waitUntil(() => mockFn.mock.calls.length >= callCount, {
|
|
44
|
+
label: `mock to be called ${callCount} time(s) (called ${mockFn.mock.calls.length})`,
|
|
45
|
+
...options,
|
|
46
|
+
});
|
|
47
|
+
};
|
package/biome.jsonc
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
|
|
4
|
-
"extends": ["../biome.jsonc"],
|
|
5
|
-
"files": {
|
|
6
|
-
"includes": [
|
|
7
|
-
"package.json",
|
|
8
|
-
"src/**/*.ts",
|
|
9
|
-
"src/**/*.tsx",
|
|
10
|
-
"!!**/node_modules",
|
|
11
|
-
"!!node_modules",
|
|
12
|
-
"!!**/dist",
|
|
13
|
-
"!!dist",
|
|
14
|
-
"!!**/build",
|
|
15
|
-
"!!build",
|
|
16
|
-
"!!**/coverage",
|
|
17
|
-
"!!coverage"
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
}
|
package/bunfig.toml
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
[test]
|
|
2
|
-
preload = ["./src/preload/defaultBackendPreload.ts"]
|
|
3
|
-
root = "./src"
|
|
4
|
-
coveragePathIgnorePatterns = [
|
|
5
|
-
"**/*.test.ts",
|
|
6
|
-
"**/*.isolated.ts",
|
|
7
|
-
"**/isolated/**",
|
|
8
|
-
"dist/**",
|
|
9
|
-
"**/node_modules/**",
|
|
10
|
-
"../api/**",
|
|
11
|
-
# Restart/reconnect branches need a process that can stop mongoose; the main
|
|
12
|
-
# suite keeps a shared connection, so those files are excluded from the gate.
|
|
13
|
-
"src/mongo/mongoServer.ts",
|
|
14
|
-
"src/mongo/connection.ts",
|
|
15
|
-
]
|
|
16
|
-
coverageThreshold = { line = 95, function = 95 }
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from "bun:test";
|
|
2
|
-
import {mkdirSync, mkdtempSync, utimesSync, writeFileSync} from "node:fs";
|
|
3
|
-
import {tmpdir} from "node:os";
|
|
4
|
-
import {join} from "node:path";
|
|
5
|
-
import mongoose from "mongoose";
|
|
6
|
-
|
|
7
|
-
import {createMongoTestCache} from "./mongoTestCache";
|
|
8
|
-
|
|
9
|
-
const CacheWidget =
|
|
10
|
-
mongoose.models.CacheCoverageWidget ??
|
|
11
|
-
mongoose.model(
|
|
12
|
-
"CacheCoverageWidget",
|
|
13
|
-
new mongoose.Schema({name: String}, {collection: "cache_coverage_widgets"})
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
describe("createMongoTestCache", () => {
|
|
17
|
-
it("writes, loads, and cleans a cache directory", async () => {
|
|
18
|
-
const cacheDir = mkdtempSync(join(tmpdir(), "terreno-mongo-cache-"));
|
|
19
|
-
const sourceDir = mkdtempSync(join(tmpdir(), "terreno-mongo-src-"));
|
|
20
|
-
writeFileSync(join(sourceDir, "model.ts"), "export const n = 1;\n");
|
|
21
|
-
mkdirSync(join(sourceDir, "nested"));
|
|
22
|
-
writeFileSync(join(sourceDir, "nested", "child.ts"), "export const c = 2;\n");
|
|
23
|
-
|
|
24
|
-
const cache = createMongoTestCache({
|
|
25
|
-
cacheDir,
|
|
26
|
-
createTestData: async () => {
|
|
27
|
-
await CacheWidget.deleteMany({});
|
|
28
|
-
await CacheWidget.create({name: "cached"});
|
|
29
|
-
return {
|
|
30
|
-
nested: [{id: "507f1f77bcf86cd799439011"}],
|
|
31
|
-
ok: true,
|
|
32
|
-
when: "2020-01-02T03:04:05.000Z",
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
sourceDirs: [sourceDir, join(sourceDir, "missing-dir")],
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
expect(cache.cacheFilesExist()).toBe(false);
|
|
39
|
-
await cache.setupTestCache({force: true});
|
|
40
|
-
expect(cache.cacheFilesExist()).toBe(true);
|
|
41
|
-
await CacheWidget.deleteMany({});
|
|
42
|
-
await cache.loadTestDataFromCache();
|
|
43
|
-
const restored = await CacheWidget.find({name: "cached"});
|
|
44
|
-
expect(restored.length).toBeGreaterThan(0);
|
|
45
|
-
await cache.setupTestCache();
|
|
46
|
-
cache.cleanCache();
|
|
47
|
-
expect(cache.cacheFilesExist()).toBe(false);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("treats expired cache files as missing outside CI", () => {
|
|
51
|
-
const cacheDir = mkdtempSync(join(tmpdir(), "terreno-mongo-cache-old-"));
|
|
52
|
-
writeFileSync(join(cacheDir, "cached-data.json"), "{}");
|
|
53
|
-
writeFileSync(join(cacheDir, "cached-collections.json"), "{}");
|
|
54
|
-
writeFileSync(join(cacheDir, "source-hash.txt"), "abc");
|
|
55
|
-
const old = new Date("2020-01-01T00:00:00.000Z");
|
|
56
|
-
utimesSync(join(cacheDir, "cached-data.json"), old, old);
|
|
57
|
-
const previousCi = process.env.CI;
|
|
58
|
-
delete process.env.CI;
|
|
59
|
-
try {
|
|
60
|
-
const cache = createMongoTestCache({
|
|
61
|
-
cacheDir,
|
|
62
|
-
createTestData: async () => ({}),
|
|
63
|
-
sourceDirs: [],
|
|
64
|
-
});
|
|
65
|
-
expect(cache.cacheFilesExist()).toBe(false);
|
|
66
|
-
} finally {
|
|
67
|
-
if (previousCi === undefined) {
|
|
68
|
-
delete process.env.CI;
|
|
69
|
-
} else {
|
|
70
|
-
process.env.CI = previousCi;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("rebuilds from source when the cache is missing and restores typed values", async () => {
|
|
76
|
-
const cacheDir = mkdtempSync(join(tmpdir(), "terreno-mongo-cache-load-"));
|
|
77
|
-
const sourceDir = mkdtempSync(join(tmpdir(), "terreno-mongo-src-load-"));
|
|
78
|
-
writeFileSync(join(sourceDir, "model.ts"), "export const n = 2;\n");
|
|
79
|
-
const cache = createMongoTestCache({
|
|
80
|
-
cacheDir,
|
|
81
|
-
createTestData: async () => {
|
|
82
|
-
await CacheWidget.deleteMany({});
|
|
83
|
-
const db = mongoose.connection.db;
|
|
84
|
-
if (!db) {
|
|
85
|
-
throw new Error("mongoose is not connected");
|
|
86
|
-
}
|
|
87
|
-
await db.collection("cache_coverage_widgets").insertOne({
|
|
88
|
-
flag: true,
|
|
89
|
-
name: "typed",
|
|
90
|
-
nested: [{id: "507f1f77bcf86cd799439011", n: null}],
|
|
91
|
-
tags: ["a"],
|
|
92
|
-
when: "2020-01-02T03:04:05.000Z",
|
|
93
|
-
});
|
|
94
|
-
return {ok: true};
|
|
95
|
-
},
|
|
96
|
-
sourceDirs: [sourceDir],
|
|
97
|
-
});
|
|
98
|
-
await cache.loadTestDataFromCache();
|
|
99
|
-
const restored = await CacheWidget.find({name: "typed"});
|
|
100
|
-
expect(restored.length).toBeGreaterThan(0);
|
|
101
|
-
cache.cleanCache();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {afterEach, describe, expect, it} from "bun:test";
|
|
2
|
-
|
|
3
|
-
import {setTerrenoTestEnv} from "./setTerrenoTestEnv";
|
|
4
|
-
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
setTerrenoTestEnv();
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
describe("setTerrenoTestEnv", () => {
|
|
10
|
-
it("applies extra keys and deletes undefined extra values", () => {
|
|
11
|
-
process.env.FEATURE_FLAGS_DEBUG = "true";
|
|
12
|
-
setTerrenoTestEnv({
|
|
13
|
-
extra: {FEATURE_FLAGS_DEBUG: undefined, TRACE: "1"},
|
|
14
|
-
});
|
|
15
|
-
expect(process.env.TRACE).toBe("1");
|
|
16
|
-
expect(process.env.FEATURE_FLAGS_DEBUG).toBeUndefined();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("deletes listed keys after applying defaults", () => {
|
|
20
|
-
setTerrenoTestEnv({
|
|
21
|
-
deleteKeys: ["TRACE"],
|
|
22
|
-
extra: {TRACE: "1"},
|
|
23
|
-
});
|
|
24
|
-
expect(process.env.TRACE).toBeUndefined();
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from "bun:test";
|
|
2
|
-
import express from "express";
|
|
3
|
-
|
|
4
|
-
import {authAsUser} from "./authAsUser";
|
|
5
|
-
import {getBaseServer} from "./getBaseServer";
|
|
6
|
-
|
|
7
|
-
describe("authAsUser", () => {
|
|
8
|
-
it("returns an agent with Bearer authorization after login", async () => {
|
|
9
|
-
const app = getBaseServer();
|
|
10
|
-
app.use(express.json());
|
|
11
|
-
app.post("/auth/login", (req, res) => {
|
|
12
|
-
const {email, password} = req.body as {email?: string; password?: string};
|
|
13
|
-
if (email === "user@test.com" && password === "secret") {
|
|
14
|
-
res.json({data: {token: "test-token-123"}});
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
res.status(401).json({error: "Invalid credentials"});
|
|
18
|
-
});
|
|
19
|
-
app.get("/protected", (req, res) => {
|
|
20
|
-
res.json({authorization: req.headers.authorization});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const agent = await authAsUser(app, {email: "user@test.com", password: "secret"});
|
|
24
|
-
const response = await agent.get("/protected").expect(200);
|
|
25
|
-
|
|
26
|
-
expect(response.body.authorization).toBe("Bearer test-token-123");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("throws when the login response does not include a token", async () => {
|
|
30
|
-
const app = getBaseServer();
|
|
31
|
-
app.use(express.json());
|
|
32
|
-
app.post("/auth/login", (_req, res) => {
|
|
33
|
-
res.json({data: {}});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
await expect(authAsUser(app, {email: "user@test.com", password: "secret"})).rejects.toThrow(
|
|
37
|
-
'authAsUser: expected string token at response path "data.token"'
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from "bun:test";
|
|
2
|
-
|
|
3
|
-
import {getBaseServer} from "./getBaseServer";
|
|
4
|
-
|
|
5
|
-
describe("getBaseServer", () => {
|
|
6
|
-
it("creates an express app with json parsing enabled", async () => {
|
|
7
|
-
const app = getBaseServer();
|
|
8
|
-
app.get("/ping", (req, res) => {
|
|
9
|
-
res.json({ok: true, query: req.query});
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const server = app.listen(0);
|
|
13
|
-
const address = server.address();
|
|
14
|
-
const port = typeof address === "object" && address ? address.port : 0;
|
|
15
|
-
|
|
16
|
-
const pingResponse = await fetch(`http://127.0.0.1:${port}/ping?foo=bar&arr=1&arr=2`);
|
|
17
|
-
expect(pingResponse.status).toBe(200);
|
|
18
|
-
await pingResponse.json();
|
|
19
|
-
|
|
20
|
-
const optionsResponse = await fetch(`http://127.0.0.1:${port}/ping`, {method: "OPTIONS"});
|
|
21
|
-
expect(optionsResponse.status).toBe(200);
|
|
22
|
-
|
|
23
|
-
await new Promise<void>((resolve, reject) => {
|
|
24
|
-
server.close((error) => {
|
|
25
|
-
if (error) {
|
|
26
|
-
reject(error);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
resolve();
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("skips CORS and applies an OpenAPI compat patch", () => {
|
|
35
|
-
let patched = false;
|
|
36
|
-
const app = getBaseServer({
|
|
37
|
-
enableCors: false,
|
|
38
|
-
patchOpenApiCompat: () => {
|
|
39
|
-
patched = true;
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
expect(patched).toBe(true);
|
|
43
|
-
expect(app).toBeDefined();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {afterEach, describe, expect, it} from "bun:test";
|
|
2
|
-
|
|
3
|
-
import {setTerrenoTestEnv} from "../env/setTerrenoTestEnv";
|
|
4
|
-
import {setupTestEnvironment} from "./setupEnvironment";
|
|
5
|
-
|
|
6
|
-
afterEach(() => {
|
|
7
|
-
setTerrenoTestEnv();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
describe("setupTestEnvironment", () => {
|
|
11
|
-
it("throws when required auth secrets are missing", () => {
|
|
12
|
-
Reflect.deleteProperty(process.env, "TOKEN_ISSUER");
|
|
13
|
-
expect(() => setupTestEnvironment()).toThrow(/TOKEN_ISSUER/);
|
|
14
|
-
setTerrenoTestEnv();
|
|
15
|
-
Reflect.deleteProperty(process.env, "TOKEN_SECRET");
|
|
16
|
-
expect(() => setupTestEnvironment()).toThrow(/TOKEN_SECRET/);
|
|
17
|
-
setTerrenoTestEnv();
|
|
18
|
-
Reflect.deleteProperty(process.env, "REFRESH_TOKEN_SECRET");
|
|
19
|
-
expect(() => setupTestEnvironment()).toThrow(/REFRESH_TOKEN_SECRET/);
|
|
20
|
-
setTerrenoTestEnv();
|
|
21
|
-
Reflect.deleteProperty(process.env, "SESSION_SECRET");
|
|
22
|
-
expect(() => setupTestEnvironment()).toThrow(/SESSION_SECRET/);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from "bun:test";
|
|
2
|
-
import winston from "winston";
|
|
3
|
-
|
|
4
|
-
import {createLogSilencer, registerLogSilencing} from "./silenceLogs";
|
|
5
|
-
|
|
6
|
-
describe("createLogSilencer", () => {
|
|
7
|
-
it("captures console output and restores originals", () => {
|
|
8
|
-
// biome-ignore lint/suspicious/noConsole: this test asserts console capture
|
|
9
|
-
const originalLog = console.log;
|
|
10
|
-
const silencer = createLogSilencer();
|
|
11
|
-
// biome-ignore lint/suspicious/noConsole: this test asserts console capture
|
|
12
|
-
console.log("captured-line");
|
|
13
|
-
expect(silencer.getLogs().some((line) => line.includes("captured-line"))).toBe(true);
|
|
14
|
-
silencer.clearLogs();
|
|
15
|
-
expect(silencer.getLogs()).toEqual([]);
|
|
16
|
-
silencer.restore();
|
|
17
|
-
// biome-ignore lint/suspicious/noConsole: this test asserts console capture
|
|
18
|
-
expect(console.log).toBe(originalLog);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("forwards captured winston lines when showAllLogs is true", () => {
|
|
22
|
-
const silencer = createLogSilencer({showAllLogs: true});
|
|
23
|
-
winston.info("visible-info");
|
|
24
|
-
expect(silencer.getLogs().length).toBeGreaterThan(0);
|
|
25
|
-
silencer.restore();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("silences an extra winston logger", () => {
|
|
29
|
-
const extra = winston.createLogger({
|
|
30
|
-
transports: [new winston.transports.Console()],
|
|
31
|
-
});
|
|
32
|
-
const silencer = createLogSilencer({additionalWinstonLoggers: [extra]});
|
|
33
|
-
extra.info("extra-logger");
|
|
34
|
-
expect(silencer.getLogs().some((line) => line.includes("extra-logger"))).toBe(true);
|
|
35
|
-
silencer.restore();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe("registerLogSilencing", () => {
|
|
40
|
-
let beforeCount = 0;
|
|
41
|
-
const silencer = registerLogSilencing({
|
|
42
|
-
onBeforeEach: () => {
|
|
43
|
-
beforeCount += 1;
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("registers lifecycle hooks without throwing", () => {
|
|
48
|
-
expect(typeof silencer.reapply).toBe("function");
|
|
49
|
-
expect(beforeCount).toBeGreaterThanOrEqual(0);
|
|
50
|
-
silencer.restore();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {afterEach, describe, expect, it, spyOn} from "bun:test";
|
|
2
|
-
|
|
3
|
-
import {testLogger} from "./testLogger";
|
|
4
|
-
|
|
5
|
-
const originalDebug = process.env.DEBUG_MONGO_PRELOAD;
|
|
6
|
-
const originalShow = process.env.SHOW_ALL_TEST_LOGS;
|
|
7
|
-
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
if (originalDebug === undefined) {
|
|
10
|
-
Reflect.deleteProperty(process.env, "DEBUG_MONGO_PRELOAD");
|
|
11
|
-
} else {
|
|
12
|
-
process.env.DEBUG_MONGO_PRELOAD = originalDebug;
|
|
13
|
-
}
|
|
14
|
-
if (originalShow === undefined) {
|
|
15
|
-
Reflect.deleteProperty(process.env, "SHOW_ALL_TEST_LOGS");
|
|
16
|
-
} else {
|
|
17
|
-
process.env.SHOW_ALL_TEST_LOGS = originalShow;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("testLogger", () => {
|
|
22
|
-
it("always logs info and warn", () => {
|
|
23
|
-
const info = spyOn(console, "info").mockImplementation(() => {});
|
|
24
|
-
const warn = spyOn(console, "warn").mockImplementation(() => {});
|
|
25
|
-
testLogger.info("hello");
|
|
26
|
-
testLogger.warn("careful");
|
|
27
|
-
expect(info.mock.calls.length).toBeGreaterThan(0);
|
|
28
|
-
expect(warn.mock.calls.length).toBeGreaterThan(0);
|
|
29
|
-
info.mockRestore();
|
|
30
|
-
warn.mockRestore();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("debugs only when DEBUG_MONGO_PRELOAD is true", () => {
|
|
34
|
-
const debug = spyOn(console, "debug").mockImplementation(() => {});
|
|
35
|
-
Reflect.deleteProperty(process.env, "DEBUG_MONGO_PRELOAD");
|
|
36
|
-
testLogger.debug("quiet");
|
|
37
|
-
expect(debug.mock.calls.length).toBe(0);
|
|
38
|
-
process.env.DEBUG_MONGO_PRELOAD = "true";
|
|
39
|
-
testLogger.debug("loud");
|
|
40
|
-
expect(debug.mock.calls.length).toBe(1);
|
|
41
|
-
debug.mockRestore();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("catches errors when debug or show-all logs are enabled", () => {
|
|
45
|
-
const error = spyOn(console, "error").mockImplementation(() => {});
|
|
46
|
-
Reflect.deleteProperty(process.env, "DEBUG_MONGO_PRELOAD");
|
|
47
|
-
Reflect.deleteProperty(process.env, "SHOW_ALL_TEST_LOGS");
|
|
48
|
-
testLogger.catch(new Error("silent"));
|
|
49
|
-
expect(error.mock.calls.length).toBe(0);
|
|
50
|
-
process.env.SHOW_ALL_TEST_LOGS = "true";
|
|
51
|
-
testLogger.catch(new Error("shown"));
|
|
52
|
-
expect(error.mock.calls.length).toBe(1);
|
|
53
|
-
process.env.DEBUG_MONGO_PRELOAD = "true";
|
|
54
|
-
testLogger.catch("also");
|
|
55
|
-
expect(error.mock.calls.length).toBe(2);
|
|
56
|
-
error.mockRestore();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from "bun:test";
|
|
2
|
-
|
|
3
|
-
import {registerSentryBunMock} from "./sentryBun";
|
|
4
|
-
|
|
5
|
-
interface MockFn {
|
|
6
|
-
(...args: unknown[]): unknown;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface MockClient {
|
|
10
|
-
captureException: MockFn;
|
|
11
|
-
captureMessage: MockFn;
|
|
12
|
-
close: () => Promise<unknown>;
|
|
13
|
-
flush: () => Promise<unknown>;
|
|
14
|
-
getOptions: MockFn;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface MockHub {
|
|
18
|
-
addBreadcrumb: MockFn;
|
|
19
|
-
captureException: MockFn;
|
|
20
|
-
captureMessage: MockFn;
|
|
21
|
-
configureScope: MockFn;
|
|
22
|
-
getClient: () => MockClient;
|
|
23
|
-
getScope: MockFn;
|
|
24
|
-
popScope: MockFn;
|
|
25
|
-
pushScope: MockFn;
|
|
26
|
-
setContext: MockFn;
|
|
27
|
-
setTag: MockFn;
|
|
28
|
-
setTags: MockFn;
|
|
29
|
-
setUser: MockFn;
|
|
30
|
-
withScope: MockFn;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface MockScope {
|
|
34
|
-
addBreadcrumb: MockFn;
|
|
35
|
-
clear: MockFn;
|
|
36
|
-
getSpan: MockFn;
|
|
37
|
-
setContext: MockFn;
|
|
38
|
-
setFingerprint: MockFn;
|
|
39
|
-
setLevel: MockFn;
|
|
40
|
-
setSpan: MockFn;
|
|
41
|
-
setTag: MockFn;
|
|
42
|
-
setTags: MockFn;
|
|
43
|
-
setTransactionName: MockFn;
|
|
44
|
-
setUser: MockFn;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface MockSpan {
|
|
48
|
-
finish: MockFn;
|
|
49
|
-
setData: MockFn;
|
|
50
|
-
setStatus: MockFn;
|
|
51
|
-
setTag: MockFn;
|
|
52
|
-
startChild: () => MockSpan;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
interface MockTransaction {
|
|
56
|
-
finish: MockFn;
|
|
57
|
-
setData: MockFn;
|
|
58
|
-
setName: MockFn;
|
|
59
|
-
setStatus: MockFn;
|
|
60
|
-
setTag: MockFn;
|
|
61
|
-
startChild: () => MockSpan;
|
|
62
|
-
toTraceparent: () => string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
interface MockSentryModule {
|
|
66
|
-
addBreadcrumb: MockFn;
|
|
67
|
-
captureException: MockFn;
|
|
68
|
-
captureMessage: MockFn;
|
|
69
|
-
clearScope: MockFn;
|
|
70
|
-
close: () => Promise<unknown>;
|
|
71
|
-
configureScope: MockFn;
|
|
72
|
-
default: MockSentryModule;
|
|
73
|
-
flush: () => Promise<unknown>;
|
|
74
|
-
getClient: () => MockClient;
|
|
75
|
-
getCurrentHub: () => MockHub;
|
|
76
|
-
getCurrentScope: () => MockScope;
|
|
77
|
-
Handlers: {
|
|
78
|
-
errorHandler: () => MockFn;
|
|
79
|
-
requestHandler: () => MockFn;
|
|
80
|
-
tracingHandler: () => MockFn;
|
|
81
|
-
};
|
|
82
|
-
init: MockFn;
|
|
83
|
-
isInitialized: () => boolean;
|
|
84
|
-
logger: {
|
|
85
|
-
debug: MockFn;
|
|
86
|
-
error: MockFn;
|
|
87
|
-
fatal: MockFn;
|
|
88
|
-
info: MockFn;
|
|
89
|
-
trace: MockFn;
|
|
90
|
-
warn: MockFn;
|
|
91
|
-
};
|
|
92
|
-
popScope: MockFn;
|
|
93
|
-
pushScope: MockFn;
|
|
94
|
-
setContext: MockFn;
|
|
95
|
-
setFingerprint: MockFn;
|
|
96
|
-
setLevel: MockFn;
|
|
97
|
-
setTag: MockFn;
|
|
98
|
-
setTags: MockFn;
|
|
99
|
-
setUser: MockFn;
|
|
100
|
-
setupExpressErrorHandler: MockFn;
|
|
101
|
-
Severity: {
|
|
102
|
-
Error: string;
|
|
103
|
-
Warning: string;
|
|
104
|
-
};
|
|
105
|
-
startTransaction: (opts: {name: string}) => MockTransaction;
|
|
106
|
-
withScope: (callback: (scope: MockScope) => void) => void;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
describe("registerSentryBunMock", () => {
|
|
110
|
-
it("registers a mock @sentry/bun module and exercises mock surfaces", async () => {
|
|
111
|
-
registerSentryBunMock();
|
|
112
|
-
const sentry = (await import("@sentry/bun")) as unknown as MockSentryModule;
|
|
113
|
-
expect(typeof sentry.captureException).toBe("function");
|
|
114
|
-
expect(typeof sentry.captureMessage).toBe("function");
|
|
115
|
-
expect(typeof sentry.flush).toBe("function");
|
|
116
|
-
|
|
117
|
-
sentry.captureException(new Error("boom"));
|
|
118
|
-
sentry.captureMessage("hello");
|
|
119
|
-
sentry.init({});
|
|
120
|
-
sentry.addBreadcrumb({});
|
|
121
|
-
sentry.clearScope();
|
|
122
|
-
sentry.configureScope(() => undefined);
|
|
123
|
-
sentry.setContext("ctx", {});
|
|
124
|
-
sentry.setFingerprint(["f"]);
|
|
125
|
-
sentry.setLevel("error");
|
|
126
|
-
sentry.setTag("k", "v");
|
|
127
|
-
sentry.setTags({a: "b"});
|
|
128
|
-
sentry.setUser({id: "1"});
|
|
129
|
-
sentry.setupExpressErrorHandler();
|
|
130
|
-
sentry.pushScope();
|
|
131
|
-
sentry.popScope();
|
|
132
|
-
expect(sentry.isInitialized()).toBe(true);
|
|
133
|
-
expect(sentry.Severity.Error).toBe("error");
|
|
134
|
-
|
|
135
|
-
const client = sentry.getClient();
|
|
136
|
-
client.captureException(new Error("c"));
|
|
137
|
-
client.captureMessage("m");
|
|
138
|
-
await client.flush();
|
|
139
|
-
await client.close();
|
|
140
|
-
client.getOptions();
|
|
141
|
-
|
|
142
|
-
const hub = sentry.getCurrentHub();
|
|
143
|
-
hub.addBreadcrumb({});
|
|
144
|
-
hub.captureException(new Error("h"));
|
|
145
|
-
hub.captureMessage("hm");
|
|
146
|
-
hub.configureScope(() => undefined);
|
|
147
|
-
hub.getClient();
|
|
148
|
-
hub.getScope();
|
|
149
|
-
hub.popScope();
|
|
150
|
-
hub.pushScope();
|
|
151
|
-
hub.setContext("c", {});
|
|
152
|
-
hub.setTag("t", "v");
|
|
153
|
-
hub.setTags({t: "v"});
|
|
154
|
-
hub.setUser({id: "2"});
|
|
155
|
-
hub.withScope(() => undefined);
|
|
156
|
-
|
|
157
|
-
const scope = sentry.getCurrentScope();
|
|
158
|
-
scope.addBreadcrumb({});
|
|
159
|
-
scope.clear();
|
|
160
|
-
scope.getSpan();
|
|
161
|
-
scope.setContext("c", {});
|
|
162
|
-
scope.setFingerprint(["f"]);
|
|
163
|
-
scope.setLevel("info");
|
|
164
|
-
scope.setSpan({});
|
|
165
|
-
scope.setTag("t", "v");
|
|
166
|
-
scope.setTags({t: "v"});
|
|
167
|
-
scope.setTransactionName("tx");
|
|
168
|
-
scope.setUser({id: "3"});
|
|
169
|
-
|
|
170
|
-
const tx = sentry.startTransaction({name: "t"});
|
|
171
|
-
tx.setData("k", "v");
|
|
172
|
-
tx.setName("n");
|
|
173
|
-
tx.setStatus("ok");
|
|
174
|
-
tx.setTag("t", "v");
|
|
175
|
-
const child = tx.startChild();
|
|
176
|
-
child.setData("k", "v");
|
|
177
|
-
child.setStatus("ok");
|
|
178
|
-
child.setTag("t", "v");
|
|
179
|
-
child.startChild();
|
|
180
|
-
child.finish();
|
|
181
|
-
expect(tx.toTraceparent()).toBe("mock-trace-parent");
|
|
182
|
-
tx.finish();
|
|
183
|
-
|
|
184
|
-
sentry.logger.debug("d");
|
|
185
|
-
sentry.logger.error("e");
|
|
186
|
-
sentry.logger.fatal("f");
|
|
187
|
-
sentry.logger.info("i");
|
|
188
|
-
sentry.logger.trace("t");
|
|
189
|
-
sentry.logger.warn("w");
|
|
190
|
-
|
|
191
|
-
const next = (): void => undefined;
|
|
192
|
-
sentry.Handlers.errorHandler()(new Error("e"), {}, {}, next);
|
|
193
|
-
sentry.Handlers.requestHandler()({}, {}, next);
|
|
194
|
-
sentry.Handlers.tracingHandler()({}, {}, next);
|
|
195
|
-
|
|
196
|
-
sentry.withScope((innerScope: {setTag: (key: string, value: string) => void}) => {
|
|
197
|
-
innerScope.setTag("k", "v");
|
|
198
|
-
});
|
|
199
|
-
await sentry.flush();
|
|
200
|
-
await sentry.close();
|
|
201
|
-
|
|
202
|
-
sentry.default.captureException(new Error("d"));
|
|
203
|
-
sentry.default.captureMessage("dm");
|
|
204
|
-
sentry.default.init({});
|
|
205
|
-
sentry.default.addBreadcrumb({});
|
|
206
|
-
sentry.default.clearScope();
|
|
207
|
-
sentry.default.configureScope(() => undefined);
|
|
208
|
-
sentry.default.setContext("c", {});
|
|
209
|
-
sentry.default.setFingerprint(["f"]);
|
|
210
|
-
sentry.default.setLevel("error");
|
|
211
|
-
sentry.default.setTag("t", "v");
|
|
212
|
-
sentry.default.setTags({t: "v"});
|
|
213
|
-
sentry.default.setUser({id: "4"});
|
|
214
|
-
sentry.default.setupExpressErrorHandler();
|
|
215
|
-
sentry.default.pushScope();
|
|
216
|
-
sentry.default.popScope();
|
|
217
|
-
expect(sentry.default.isInitialized()).toBe(true);
|
|
218
|
-
sentry.default.logger.info("di");
|
|
219
|
-
sentry.default.startTransaction({name: "dt"}).finish();
|
|
220
|
-
await sentry.default.flush();
|
|
221
|
-
await sentry.default.close();
|
|
222
|
-
sentry.default.withScope(() => undefined);
|
|
223
|
-
sentry.default.Handlers.errorHandler()(new Error("de"), {}, {}, next);
|
|
224
|
-
sentry.default.Handlers.tracingHandler()({}, {}, next);
|
|
225
|
-
sentry.default.getClient();
|
|
226
|
-
sentry.default.getCurrentHub();
|
|
227
|
-
sentry.default.getCurrentScope();
|
|
228
|
-
expect(sentry.default.Severity.Warning).toBe("warning");
|
|
229
|
-
});
|
|
230
|
-
});
|