@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
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from "bun:test";
|
|
2
|
-
import {setTerrenoTestEnv} from "../env/setTerrenoTestEnv";
|
|
3
|
-
import {buildDatabaseUri, splitMongoUri} from "./connection";
|
|
4
|
-
|
|
5
|
-
describe("mongo connection helpers", () => {
|
|
6
|
-
it("splitMongoUri separates base URI and query options", () => {
|
|
7
|
-
const result = splitMongoUri("mongodb://127.0.0.1/mydb?retryWrites=true");
|
|
8
|
-
expect(result.baseUri).toBe("mongodb://127.0.0.1");
|
|
9
|
-
expect(result.uriOptions).toBe("?retryWrites=true");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("buildDatabaseUri appends database name and preserves query params", () => {
|
|
13
|
-
const uri = buildDatabaseUri({
|
|
14
|
-
databaseName: "terrenoTest_base",
|
|
15
|
-
uri: "mongodb://127.0.0.1/?retryWrites=true",
|
|
16
|
-
});
|
|
17
|
-
expect(uri).toBe("mongodb://127.0.0.1/terrenoTest_base?retryWrites=true");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("buildDatabaseUri appends database name without query params", () => {
|
|
21
|
-
const uri = buildDatabaseUri({
|
|
22
|
-
databaseName: "terrenoTest_base",
|
|
23
|
-
uri: "mongodb://127.0.0.1",
|
|
24
|
-
});
|
|
25
|
-
expect(uri).toBe("mongodb://127.0.0.1/terrenoTest_base");
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("splitMongoUri keeps a URI that has no database path", () => {
|
|
29
|
-
const result = splitMongoUri("mongodb://127.0.0.1");
|
|
30
|
-
expect(result.baseUri).toBe("mongodb://127.0.0.1");
|
|
31
|
-
expect(result.uriOptions).toBe("");
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("setTerrenoTestEnv", () => {
|
|
36
|
-
it("sets canonical auth env keys", () => {
|
|
37
|
-
setTerrenoTestEnv({tokenIssuer: "unit.test"});
|
|
38
|
-
expect(process.env.TOKEN_SECRET).toBe("secret");
|
|
39
|
-
expect(process.env.TOKEN_ISSUER).toBe("unit.test");
|
|
40
|
-
expect(process.env.SESSION_SECRET).toBe("sessionSecret");
|
|
41
|
-
expect(process.env.REFRESH_TOKEN_SECRET).toBe("refreshTokenSecret");
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from "bun:test";
|
|
2
|
-
import mongoose from "mongoose";
|
|
3
|
-
|
|
4
|
-
import {ensureTestMongooseConnected} from "./connection";
|
|
5
|
-
import {initializeModels, resolveMongoLaunchTimeoutMs, waitForDatabaseReady} from "./mongoServer";
|
|
6
|
-
|
|
7
|
-
describe("mongoServer", () => {
|
|
8
|
-
it("pings the connected database", async () => {
|
|
9
|
-
await waitForDatabaseReady(3, 10);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("throws when mongoose has no database handle", async () => {
|
|
13
|
-
const original = Object.getOwnPropertyDescriptor(mongoose.connection, "db");
|
|
14
|
-
Object.defineProperty(mongoose.connection, "db", {
|
|
15
|
-
configurable: true,
|
|
16
|
-
get: () => undefined,
|
|
17
|
-
});
|
|
18
|
-
try {
|
|
19
|
-
await expect(waitForDatabaseReady(1, 1)).rejects.toThrow(/undefined/);
|
|
20
|
-
} finally {
|
|
21
|
-
if (original) {
|
|
22
|
-
Object.defineProperty(mongoose.connection, "db", original);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("initializes models and reports zero work when none are new", async () => {
|
|
28
|
-
const first = await initializeModels();
|
|
29
|
-
const second = await initializeModels();
|
|
30
|
-
expect(second.modelCount).toBe(first.modelCount);
|
|
31
|
-
expect(second.modelInitMs).toBe(0);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("resolveMongoLaunchTimeoutMs", () => {
|
|
36
|
-
it("defaults to 60 seconds", () => {
|
|
37
|
-
Reflect.deleteProperty(process.env, "TERRENO_TEST_MONGO_LAUNCH_TIMEOUT_MS");
|
|
38
|
-
expect(resolveMongoLaunchTimeoutMs()).toBe(60000);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("reads a positive integer override", () => {
|
|
42
|
-
process.env.TERRENO_TEST_MONGO_LAUNCH_TIMEOUT_MS = "90000";
|
|
43
|
-
try {
|
|
44
|
-
expect(resolveMongoLaunchTimeoutMs()).toBe(90000);
|
|
45
|
-
} finally {
|
|
46
|
-
Reflect.deleteProperty(process.env, "TERRENO_TEST_MONGO_LAUNCH_TIMEOUT_MS");
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it.each(["0", "-5", "1.5", "999", "soon"])("ignores the invalid override %p", (value) => {
|
|
51
|
-
process.env.TERRENO_TEST_MONGO_LAUNCH_TIMEOUT_MS = value;
|
|
52
|
-
try {
|
|
53
|
-
expect(resolveMongoLaunchTimeoutMs()).toBe(60000);
|
|
54
|
-
} finally {
|
|
55
|
-
Reflect.deleteProperty(process.env, "TERRENO_TEST_MONGO_LAUNCH_TIMEOUT_MS");
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe("ensureTestMongooseConnected", () => {
|
|
61
|
-
it("returns immediately when mongoose is already connected", async () => {
|
|
62
|
-
expect(mongoose.connection.readyState).toBe(1);
|
|
63
|
-
await ensureTestMongooseConnected();
|
|
64
|
-
expect(mongoose.connection.readyState).toBe(1);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe("startMongoServer", () => {
|
|
69
|
-
it("retries ping on retryable mongo codes", async () => {
|
|
70
|
-
let calls = 0;
|
|
71
|
-
const original = mongoose.connection.db;
|
|
72
|
-
Object.defineProperty(mongoose.connection, "db", {
|
|
73
|
-
configurable: true,
|
|
74
|
-
get: () => ({
|
|
75
|
-
admin: () => ({
|
|
76
|
-
command: async () => {
|
|
77
|
-
calls += 1;
|
|
78
|
-
if (calls === 1) {
|
|
79
|
-
const error = new Error("not ready") as Error & {code: number};
|
|
80
|
-
error.code = 11600;
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
return {ok: 1};
|
|
84
|
-
},
|
|
85
|
-
}),
|
|
86
|
-
}),
|
|
87
|
-
});
|
|
88
|
-
try {
|
|
89
|
-
const {waitForDatabaseReady} = await import("./mongoServer");
|
|
90
|
-
await waitForDatabaseReady(3, 1);
|
|
91
|
-
expect(calls).toBe(2);
|
|
92
|
-
} finally {
|
|
93
|
-
Object.defineProperty(mongoose.connection, "db", {
|
|
94
|
-
configurable: true,
|
|
95
|
-
get: () => original,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from "bun:test";
|
|
2
|
-
|
|
3
|
-
import {registerBackendPreload, registerSimpleMongoPreload} from "./registerBackendPreload";
|
|
4
|
-
|
|
5
|
-
describe("registerBackendPreload", () => {
|
|
6
|
-
it("exports preload helpers", () => {
|
|
7
|
-
expect(typeof registerSimpleMongoPreload).toBe("function");
|
|
8
|
-
expect(typeof registerBackendPreload).toBe("function");
|
|
9
|
-
});
|
|
10
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from "bun:test";
|
|
2
|
-
import mongoose from "mongoose";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
abortTestTransaction,
|
|
6
|
-
getTestSession,
|
|
7
|
-
installTransactionPatches,
|
|
8
|
-
resetTestSessionAfterReconnect,
|
|
9
|
-
startTestTransaction,
|
|
10
|
-
} from "./testTransaction";
|
|
11
|
-
|
|
12
|
-
const TxWidget =
|
|
13
|
-
mongoose.models.TxCoverageWidget ??
|
|
14
|
-
mongoose.model(
|
|
15
|
-
"TxCoverageWidget",
|
|
16
|
-
new mongoose.Schema({name: String}, {collection: "tx_coverage_widgets"})
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
describe("testTransaction", () => {
|
|
20
|
-
it("installs patches idempotently and no-ops without a session", async () => {
|
|
21
|
-
expect(getTestSession()).toBeNull();
|
|
22
|
-
installTransactionPatches();
|
|
23
|
-
installTransactionPatches();
|
|
24
|
-
await abortTestTransaction();
|
|
25
|
-
await resetTestSessionAfterReconnect();
|
|
26
|
-
expect(getTestSession()).toBeNull();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("serializes mongoose operations while a test session is active", async () => {
|
|
30
|
-
installTransactionPatches();
|
|
31
|
-
try {
|
|
32
|
-
await startTestTransaction();
|
|
33
|
-
expect(getTestSession()).toBeTruthy();
|
|
34
|
-
await TxWidget.create({name: "tx-a"});
|
|
35
|
-
await TxWidget.find({name: "tx-a"});
|
|
36
|
-
await TxWidget.updateOne({name: "tx-a"}, {name: "tx-b"});
|
|
37
|
-
await TxWidget.deleteOne({name: "tx-b"});
|
|
38
|
-
try {
|
|
39
|
-
await TxWidget.insertMany([{name: "tx-c"}]);
|
|
40
|
-
} catch {
|
|
41
|
-
// replica-set-only path
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
await TxWidget.bulkWrite([{insertOne: {document: {name: "tx-d"}}}]);
|
|
45
|
-
} catch {
|
|
46
|
-
// replica-set-only path
|
|
47
|
-
}
|
|
48
|
-
try {
|
|
49
|
-
await TxWidget.aggregate([{$match: {name: "tx-a"}}]);
|
|
50
|
-
} catch {
|
|
51
|
-
// replica-set-only path
|
|
52
|
-
}
|
|
53
|
-
const session = await TxWidget.startSession();
|
|
54
|
-
expect(session).toBeDefined();
|
|
55
|
-
await Promise.allSettled([TxWidget.find({name: "tx-a"}), TxWidget.find({name: "tx-b"})]);
|
|
56
|
-
} catch {
|
|
57
|
-
// Standalone memory Mongo rejects multi-document transactions.
|
|
58
|
-
} finally {
|
|
59
|
-
await abortTestTransaction();
|
|
60
|
-
await resetTestSessionAfterReconnect();
|
|
61
|
-
expect(getTestSession()).toBeNull();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from "bun:test";
|
|
2
|
-
import mongoose from "mongoose";
|
|
3
|
-
import {ensureAllIndexes} from "./ensureAllIndexes";
|
|
4
|
-
import {timeout} from "./timeout";
|
|
5
|
-
import {waitForDocument, waitForDocuments} from "./waitForDocuments";
|
|
6
|
-
|
|
7
|
-
const Widget =
|
|
8
|
-
mongoose.models.CoverageWidget ??
|
|
9
|
-
mongoose.model(
|
|
10
|
-
"CoverageWidget",
|
|
11
|
-
new mongoose.Schema({name: {required: true, type: String}}, {collection: "coverage_widgets"})
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
describe("timeout", () => {
|
|
15
|
-
it("resolves after the requested delay", async () => {
|
|
16
|
-
await timeout(1);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe("ensureAllIndexes", () => {
|
|
21
|
-
it("creates indexes for registered models", async () => {
|
|
22
|
-
await ensureAllIndexes();
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe("waitForDocuments", () => {
|
|
27
|
-
it("returns matching documents and supports sort", async () => {
|
|
28
|
-
await Widget.deleteMany({});
|
|
29
|
-
await Widget.create({name: "b"});
|
|
30
|
-
await Widget.create({name: "a"});
|
|
31
|
-
const docs = await waitForDocuments(Widget, {}, 2, {
|
|
32
|
-
intervalMs: 10,
|
|
33
|
-
sort: {name: 1},
|
|
34
|
-
timeoutMs: 2000,
|
|
35
|
-
});
|
|
36
|
-
expect(docs.map((doc) => (doc as {name: string}).name)).toEqual(["a", "b"]);
|
|
37
|
-
const one = await waitForDocument(Widget, {name: "a"}, {intervalMs: 10, timeoutMs: 2000});
|
|
38
|
-
expect((one as {name: string}).name).toBe("a");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("throws when the timeout elapses", async () => {
|
|
42
|
-
await expect(
|
|
43
|
-
waitForDocuments(Widget, {name: "missing-coverage-doc"}, 1, {intervalMs: 5, timeoutMs: 20})
|
|
44
|
-
).rejects.toThrow(/Timed out/);
|
|
45
|
-
});
|
|
46
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"declaration": true,
|
|
4
|
-
"isolatedModules": true,
|
|
5
|
-
"lib": ["es2023"],
|
|
6
|
-
"module": "nodenext",
|
|
7
|
-
"noImplicitAny": false,
|
|
8
|
-
"noImplicitReturns": true,
|
|
9
|
-
"outDir": "./dist",
|
|
10
|
-
"rootDir": "./src",
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"target": "es2023",
|
|
14
|
-
"types": ["bun", "node"]
|
|
15
|
-
},
|
|
16
|
-
"exclude": ["node_modules", "**/*.test.ts", "src/mongo/ensureMongoBinary.ts"],
|
|
17
|
-
"include": ["src"]
|
|
18
|
-
}
|