@terreno/test 57.4.0 → 57.6.0
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/README.md +2 -2
- package/dist/cache/mongoTestCache.js +175 -427
- package/dist/env/setTerrenoTestEnv.js +15 -65
- package/dist/http/authAsUser.js +28 -153
- package/dist/http/getBaseServer.js +6 -7
- package/dist/logging/setupEnvironment.js +1 -1
- package/dist/logging/silenceLogs.js +36 -93
- package/dist/logging/testLogger.js +4 -4
- package/dist/mocks/sentryBun.js +39 -39
- package/dist/mongo/connection.js +31 -115
- package/dist/mongo/ensureMongoBinary.js +12 -92
- package/dist/mongo/mongoServer.js +142 -390
- package/dist/preload/defaultBackendPreload.js +1 -1
- package/dist/preload/memoryMongo.d.ts +1 -0
- package/dist/preload/memoryMongo.js +1 -0
- package/dist/preload/registerBackendPreload.js +87 -262
- package/dist/transaction/testTransaction.js +224 -444
- package/dist/utils/ensureAllIndexes.js +9 -76
- package/dist/utils/timeout.js +3 -41
- package/dist/utils/waitForDocuments.js +18 -115
- package/package.json +4 -4
- package/tsconfig.json +6 -22
- package/dist/cache/mongoTestCache.test.d.ts +0 -1
- package/dist/cache/mongoTestCache.test.js +0 -182
- package/dist/env/setTerrenoTestEnv.test.d.ts +0 -1
- package/dist/env/setTerrenoTestEnv.test.js +0 -24
- package/dist/http/authAsUser.test.d.ts +0 -1
- package/dist/http/authAsUser.test.js +0 -93
- package/dist/http/getBaseServer.test.d.ts +0 -1
- package/dist/http/getBaseServer.test.js +0 -91
- package/dist/logging/setupEnvironment.test.d.ts +0 -1
- package/dist/logging/setupEnvironment.test.js +0 -23
- package/dist/logging/silenceLogs.test.d.ts +0 -1
- package/dist/logging/silenceLogs.test.js +0 -51
- package/dist/logging/testLogger.test.d.ts +0 -1
- package/dist/logging/testLogger.test.js +0 -56
- package/dist/mocks/sentryBun.test.d.ts +0 -1
- package/dist/mocks/sentryBun.test.js +0 -207
- package/dist/mongo/connection.test.d.ts +0 -1
- package/dist/mongo/connection.test.js +0 -40
- package/dist/mongo/mongoServer.test.d.ts +0 -1
- package/dist/mongo/mongoServer.test.js +0 -196
- package/dist/preload/registerBackendPreload.test.d.ts +0 -1
- package/dist/preload/registerBackendPreload.test.js +0 -10
- package/dist/transaction/testTransaction.test.d.ts +0 -1
- package/dist/transaction/testTransaction.test.js +0 -142
- package/dist/utils/helpers.test.d.ts +0 -1
- package/dist/utils/helpers.test.js +0 -113
|
@@ -1,35 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
3
|
exports.setTerrenoTestEnv = void 0;
|
|
31
|
-
|
|
32
|
-
|
|
4
|
+
const setupEnvironment_1 = require("../logging/setupEnvironment");
|
|
5
|
+
const DEFAULT_AUTH_ENV = {
|
|
33
6
|
REFRESH_TOKEN_SECRET: "refreshTokenSecret",
|
|
34
7
|
SESSION_SECRET: "sessionSecret",
|
|
35
8
|
TOKEN_ISSUER: "terreno.test",
|
|
@@ -38,50 +11,27 @@ var DEFAULT_AUTH_ENV = {
|
|
|
38
11
|
/**
|
|
39
12
|
* Applies the canonical Terreno backend test `process.env` surface for auth secrets.
|
|
40
13
|
*/
|
|
41
|
-
|
|
42
|
-
var e_1, _a, e_2, _b;
|
|
43
|
-
var _c, _d, _e, _f, _g;
|
|
44
|
-
if (options === void 0) { options = {}; }
|
|
14
|
+
const setTerrenoTestEnv = (options = {}) => {
|
|
45
15
|
process.env.NODE_ENV = "test";
|
|
46
|
-
process.env.TZ =
|
|
47
|
-
process.env.TOKEN_SECRET =
|
|
48
|
-
process.env.TOKEN_ISSUER =
|
|
49
|
-
process.env.SESSION_SECRET =
|
|
16
|
+
process.env.TZ = options.timezone ?? "UTC";
|
|
17
|
+
process.env.TOKEN_SECRET = options.tokenSecret ?? DEFAULT_AUTH_ENV.TOKEN_SECRET;
|
|
18
|
+
process.env.TOKEN_ISSUER = options.tokenIssuer ?? DEFAULT_AUTH_ENV.TOKEN_ISSUER;
|
|
19
|
+
process.env.SESSION_SECRET = options.sessionSecret ?? DEFAULT_AUTH_ENV.SESSION_SECRET;
|
|
50
20
|
process.env.REFRESH_TOKEN_SECRET =
|
|
51
|
-
|
|
21
|
+
options.refreshTokenSecret ?? DEFAULT_AUTH_ENV.REFRESH_TOKEN_SECRET;
|
|
52
22
|
if (options.extra) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (value === undefined) {
|
|
57
|
-
Reflect.deleteProperty(process.env, key);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
process.env[key] = value;
|
|
61
|
-
}
|
|
23
|
+
for (const [key, value] of Object.entries(options.extra)) {
|
|
24
|
+
if (value === undefined) {
|
|
25
|
+
Reflect.deleteProperty(process.env, key);
|
|
62
26
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
finally {
|
|
66
|
-
try {
|
|
67
|
-
if (_j && !_j.done && (_a = _h.return)) _a.call(_h);
|
|
27
|
+
else {
|
|
28
|
+
process.env[key] = value;
|
|
68
29
|
}
|
|
69
|
-
finally { if (e_1) throw e_1.error; }
|
|
70
30
|
}
|
|
71
31
|
}
|
|
72
32
|
if (options.deleteKeys) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var key = _m.value;
|
|
76
|
-
Reflect.deleteProperty(process.env, key);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
80
|
-
finally {
|
|
81
|
-
try {
|
|
82
|
-
if (_m && !_m.done && (_b = _l.return)) _b.call(_l);
|
|
83
|
-
}
|
|
84
|
-
finally { if (e_2) throw e_2.error; }
|
|
33
|
+
for (const key of options.deleteKeys) {
|
|
34
|
+
Reflect.deleteProperty(process.env, key);
|
|
85
35
|
}
|
|
86
36
|
}
|
|
87
37
|
(0, setupEnvironment_1.setupTestEnvironment)();
|
package/dist/http/authAsUser.js
CHANGED
|
@@ -1,165 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
-
if (!m) return o;
|
|
52
|
-
var i = m.call(o), r, ar = [], e;
|
|
53
|
-
try {
|
|
54
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
-
}
|
|
56
|
-
catch (error) { e = { error: error }; }
|
|
57
|
-
finally {
|
|
58
|
-
try {
|
|
59
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
-
}
|
|
61
|
-
finally { if (e) throw e.error; }
|
|
62
|
-
}
|
|
63
|
-
return ar;
|
|
64
|
-
};
|
|
65
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
-
if (ar || !(i in from)) {
|
|
68
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
-
ar[i] = from[i];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
-
};
|
|
74
|
-
var __values = (this && this.__values) || function(o) {
|
|
75
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
76
|
-
if (m) return m.call(o);
|
|
77
|
-
if (o && typeof o.length === "number") return {
|
|
78
|
-
next: function () {
|
|
79
|
-
if (o && i >= o.length) o = void 0;
|
|
80
|
-
return { value: o && o[i++], done: !o };
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
84
|
-
};
|
|
85
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
86
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
87
4
|
};
|
|
88
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
89
6
|
exports.authAsUser = void 0;
|
|
90
|
-
|
|
7
|
+
const supertest_1 = __importDefault(require("supertest"));
|
|
91
8
|
/**
|
|
92
9
|
* Logs in via POST /auth/login (by default) and returns a supertest agent with Bearer auth.
|
|
93
10
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
var _e, _f, _g;
|
|
103
|
-
if (options === void 0) { options = {}; }
|
|
104
|
-
return __generator(this, function (_h) {
|
|
105
|
-
switch (_h.label) {
|
|
106
|
-
case 0:
|
|
107
|
-
loginPath = (_e = options.loginPath) !== null && _e !== void 0 ? _e : "/auth/login";
|
|
108
|
-
tokenPath = (_f = options.tokenPath) !== null && _f !== void 0 ? _f : "data.token";
|
|
109
|
-
timeoutMs = (_g = options.timeoutMs) !== null && _g !== void 0 ? _g : 5000;
|
|
110
|
-
agent = supertest_1.default.agent(app);
|
|
111
|
-
request = agent.post(loginPath).send({
|
|
112
|
-
email: credentials.email,
|
|
113
|
-
password: credentials.password,
|
|
114
|
-
});
|
|
115
|
-
if (timeoutMs > 0) {
|
|
116
|
-
request.timeout(timeoutMs);
|
|
117
|
-
}
|
|
118
|
-
return [4 /*yield*/, request.expect(200)];
|
|
119
|
-
case 1:
|
|
120
|
-
res = _h.sent();
|
|
121
|
-
token = tokenPath.split(".").reduce(function (value, key) {
|
|
122
|
-
if (value && typeof value === "object" && key in value) {
|
|
123
|
-
return value[key];
|
|
124
|
-
}
|
|
125
|
-
return undefined;
|
|
126
|
-
}, res.body);
|
|
127
|
-
if (typeof token !== "string" || !token) {
|
|
128
|
-
throw new Error("authAsUser: expected string token at response path \"".concat(tokenPath, "\""));
|
|
129
|
-
}
|
|
130
|
-
headers = __assign(__assign({}, options.headers), credentials.headers);
|
|
131
|
-
return [4 /*yield*/, agent.set("authorization", "Bearer ".concat(token))];
|
|
132
|
-
case 2:
|
|
133
|
-
_h.sent();
|
|
134
|
-
_h.label = 3;
|
|
135
|
-
case 3:
|
|
136
|
-
_h.trys.push([3, 8, 9, 10]);
|
|
137
|
-
_a = __values(Object.entries(headers)), _b = _a.next();
|
|
138
|
-
_h.label = 4;
|
|
139
|
-
case 4:
|
|
140
|
-
if (!!_b.done) return [3 /*break*/, 7];
|
|
141
|
-
_c = __read(_b.value, 2), key = _c[0], value = _c[1];
|
|
142
|
-
return [4 /*yield*/, agent.set(key, value)];
|
|
143
|
-
case 5:
|
|
144
|
-
_h.sent();
|
|
145
|
-
_h.label = 6;
|
|
146
|
-
case 6:
|
|
147
|
-
_b = _a.next();
|
|
148
|
-
return [3 /*break*/, 4];
|
|
149
|
-
case 7: return [3 /*break*/, 10];
|
|
150
|
-
case 8:
|
|
151
|
-
e_1_1 = _h.sent();
|
|
152
|
-
e_1 = { error: e_1_1 };
|
|
153
|
-
return [3 /*break*/, 10];
|
|
154
|
-
case 9:
|
|
155
|
-
try {
|
|
156
|
-
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
157
|
-
}
|
|
158
|
-
finally { if (e_1) throw e_1.error; }
|
|
159
|
-
return [7 /*endfinally*/];
|
|
160
|
-
case 10: return [2 /*return*/, agent];
|
|
161
|
-
}
|
|
162
|
-
});
|
|
11
|
+
const authAsUser = async (app, credentials, options = {}) => {
|
|
12
|
+
const loginPath = options.loginPath ?? "/auth/login";
|
|
13
|
+
const tokenPath = options.tokenPath ?? "data.token";
|
|
14
|
+
const timeoutMs = options.timeoutMs ?? 5000;
|
|
15
|
+
const agent = supertest_1.default.agent(app);
|
|
16
|
+
const request = agent.post(loginPath).send({
|
|
17
|
+
email: credentials.email,
|
|
18
|
+
password: credentials.password,
|
|
163
19
|
});
|
|
20
|
+
if (timeoutMs > 0) {
|
|
21
|
+
request.timeout(timeoutMs);
|
|
22
|
+
}
|
|
23
|
+
const res = await request.expect(200);
|
|
24
|
+
const token = tokenPath.split(".").reduce((value, key) => {
|
|
25
|
+
if (value && typeof value === "object" && key in value) {
|
|
26
|
+
return value[key];
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}, res.body);
|
|
30
|
+
if (typeof token !== "string" || !token) {
|
|
31
|
+
throw new Error(`authAsUser: expected string token at response path "${tokenPath}"`);
|
|
32
|
+
}
|
|
33
|
+
const headers = { ...options.headers, ...credentials.headers };
|
|
34
|
+
await agent.set("authorization", `Bearer ${token}`);
|
|
35
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
36
|
+
await agent.set(key, value);
|
|
37
|
+
}
|
|
38
|
+
return agent;
|
|
164
39
|
};
|
|
165
40
|
exports.authAsUser = authAsUser;
|
|
@@ -4,20 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getBaseServer = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const qs_1 = __importDefault(require("qs"));
|
|
9
9
|
/**
|
|
10
10
|
* Minimal Express app for supertest with qs query parsing (Express 5 compatible).
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
app.set("query parser", function (str) { return qs_1.default.parse(str, { arrayLimit: 200 }); });
|
|
12
|
+
const getBaseServer = (options = {}) => {
|
|
13
|
+
const app = (0, express_1.default)();
|
|
14
|
+
app.set("query parser", (str) => qs_1.default.parse(str, { arrayLimit: 200 }));
|
|
16
15
|
if (options.patchOpenApiCompat) {
|
|
17
16
|
options.patchOpenApiCompat(app);
|
|
18
17
|
}
|
|
19
18
|
if (options.enableCors !== false) {
|
|
20
|
-
app.use(
|
|
19
|
+
app.use((req, res, next) => {
|
|
21
20
|
res.header("Access-Control-Allow-Origin", "*");
|
|
22
21
|
res.header("Access-Control-Allow-Headers", "*");
|
|
23
22
|
if (req.method === "OPTIONS") {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupTestEnvironment = void 0;
|
|
4
4
|
/** Minimal auth env validation for backend tests (mirrors @terreno/api setupEnvironment). */
|
|
5
|
-
|
|
5
|
+
const setupTestEnvironment = () => {
|
|
6
6
|
if (!process.env.TOKEN_ISSUER) {
|
|
7
7
|
throw new Error("TOKEN_ISSUER must be set in env.");
|
|
8
8
|
}
|
|
@@ -1,40 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
var __values = (this && this.__values) || function(o) {
|
|
28
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
-
if (m) return m.call(o);
|
|
30
|
-
if (o && typeof o.length === "number") return {
|
|
31
|
-
next: function () {
|
|
32
|
-
if (o && i >= o.length) o = void 0;
|
|
33
|
-
return { value: o && o[i++], done: !o };
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
@@ -42,25 +6,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
42
6
|
exports.registerLogSilencing = exports.createLogSilencer = void 0;
|
|
43
7
|
// noExplicitAny: test mock typing
|
|
44
8
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
9
|
+
const bun_test_1 = require("bun:test");
|
|
10
|
+
const node_stream_1 = require("node:stream");
|
|
11
|
+
const winston_1 = __importDefault(require("winston"));
|
|
12
|
+
const getApiWinstonLogger = () => {
|
|
49
13
|
try {
|
|
50
14
|
// Runtime-only so @terreno/test compiles without @terreno/api.
|
|
51
15
|
// noExplicitAny: optional peer resolved at preload time
|
|
52
16
|
// biome-ignore lint/suspicious/noExplicitAny: optional peer resolved at preload time
|
|
53
|
-
|
|
17
|
+
const api = require("@terreno/api");
|
|
54
18
|
return api.winstonLogger;
|
|
55
19
|
}
|
|
56
|
-
catch
|
|
20
|
+
catch {
|
|
57
21
|
return undefined;
|
|
58
22
|
}
|
|
59
23
|
};
|
|
60
|
-
|
|
24
|
+
const createLogStream = (logs, showAllLogs) => {
|
|
61
25
|
return new node_stream_1.Writable({
|
|
62
|
-
write
|
|
63
|
-
|
|
26
|
+
write(chunk, _encoding, callback) {
|
|
27
|
+
const text = String(chunk);
|
|
64
28
|
logs.push(text);
|
|
65
29
|
if (showAllLogs) {
|
|
66
30
|
process.stdout.write(text);
|
|
@@ -72,12 +36,10 @@ var createLogStream = function (logs, showAllLogs) {
|
|
|
72
36
|
/**
|
|
73
37
|
* Silences winston and console output during tests while capturing log lines in memory.
|
|
74
38
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
var logs = [];
|
|
80
|
-
var originalConsole = {
|
|
39
|
+
const createLogSilencer = (options = {}) => {
|
|
40
|
+
const showAllLogs = options.showAllLogs ?? process.env.SHOW_ALL_TEST_LOGS === "true";
|
|
41
|
+
let logs = [];
|
|
42
|
+
const originalConsole = {
|
|
81
43
|
debug: console.debug,
|
|
82
44
|
error: console.error,
|
|
83
45
|
info: console.info,
|
|
@@ -85,49 +47,33 @@ var createLogSilencer = function (options) {
|
|
|
85
47
|
log: console.log,
|
|
86
48
|
warn: console.warn,
|
|
87
49
|
};
|
|
88
|
-
|
|
89
|
-
|
|
50
|
+
const logStream = createLogStream(logs, showAllLogs);
|
|
51
|
+
const silentTransport = new winston_1.default.transports.Stream({
|
|
90
52
|
format: winston_1.default.format.simple(),
|
|
91
53
|
stream: logStream,
|
|
92
54
|
});
|
|
93
|
-
|
|
94
|
-
console[method] =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
var logMessage = "[console.".concat(method, "] ").concat(args
|
|
100
|
-
.map(function (arg) { return (typeof arg === "object" ? JSON.stringify(arg) : String(arg)); })
|
|
101
|
-
.join(" "));
|
|
55
|
+
const captureConsoleMethod = (method) => {
|
|
56
|
+
console[method] = (...args) => {
|
|
57
|
+
const logMessage = `[console.${method}] ${args
|
|
58
|
+
.map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : String(arg)))
|
|
59
|
+
.join(" ")}`;
|
|
102
60
|
logs.push(logMessage);
|
|
103
61
|
if (showAllLogs) {
|
|
104
|
-
originalConsole[method]
|
|
62
|
+
originalConsole[method](...args);
|
|
105
63
|
}
|
|
106
64
|
};
|
|
107
65
|
};
|
|
108
|
-
|
|
109
|
-
var e_1, _a;
|
|
110
|
-
var _b;
|
|
66
|
+
const applySilencing = () => {
|
|
111
67
|
winston_1.default.clear();
|
|
112
68
|
winston_1.default.add(silentTransport);
|
|
113
69
|
// Only reach for @terreno/api when the caller has not supplied its logger. Requiring the
|
|
114
70
|
// package from inside api's own test run would load its built dist alongside the sources
|
|
115
71
|
// under test, registering every Mongoose model twice.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
extraLogger.clear();
|
|
122
|
-
extraLogger.add(silentTransport);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
126
|
-
finally {
|
|
127
|
-
try {
|
|
128
|
-
if (extraLoggers_1_1 && !extraLoggers_1_1.done && (_a = extraLoggers_1.return)) _a.call(extraLoggers_1);
|
|
129
|
-
}
|
|
130
|
-
finally { if (e_1) throw e_1.error; }
|
|
72
|
+
const provided = options.additionalWinstonLoggers ?? [];
|
|
73
|
+
const extraLoggers = (provided.length > 0 ? provided : [getApiWinstonLogger()]).filter(Boolean);
|
|
74
|
+
for (const extraLogger of extraLoggers) {
|
|
75
|
+
extraLogger.clear();
|
|
76
|
+
extraLogger.add(silentTransport);
|
|
131
77
|
}
|
|
132
78
|
captureConsoleMethod("log");
|
|
133
79
|
captureConsoleMethod("info");
|
|
@@ -137,12 +83,12 @@ var createLogSilencer = function (options) {
|
|
|
137
83
|
};
|
|
138
84
|
applySilencing();
|
|
139
85
|
return {
|
|
140
|
-
clearLogs:
|
|
86
|
+
clearLogs: () => {
|
|
141
87
|
logs = [];
|
|
142
88
|
},
|
|
143
|
-
getLogs:
|
|
89
|
+
getLogs: () => logs,
|
|
144
90
|
reapply: applySilencing,
|
|
145
|
-
restore:
|
|
91
|
+
restore: () => {
|
|
146
92
|
console.debug = originalConsole.debug;
|
|
147
93
|
console.error = originalConsole.error;
|
|
148
94
|
console.info = originalConsole.info;
|
|
@@ -153,19 +99,16 @@ var createLogSilencer = function (options) {
|
|
|
153
99
|
};
|
|
154
100
|
exports.createLogSilencer = createLogSilencer;
|
|
155
101
|
/** Registers beforeEach/afterEach hooks that silence logs and clear the capture buffer. */
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
var _a;
|
|
161
|
-
(_a = options.onBeforeEach) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
102
|
+
const registerLogSilencing = (options = {}) => {
|
|
103
|
+
const silencer = (0, exports.createLogSilencer)(options);
|
|
104
|
+
(0, bun_test_1.beforeEach)(() => {
|
|
105
|
+
options.onBeforeEach?.();
|
|
162
106
|
silencer.reapply();
|
|
163
107
|
silencer.clearLogs();
|
|
164
108
|
});
|
|
165
|
-
(0, bun_test_1.afterEach)(
|
|
166
|
-
var _a;
|
|
109
|
+
(0, bun_test_1.afterEach)(() => {
|
|
167
110
|
silencer.clearLogs();
|
|
168
|
-
|
|
111
|
+
options.onAfterEach?.();
|
|
169
112
|
});
|
|
170
113
|
return silencer;
|
|
171
114
|
};
|
|
@@ -3,20 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.testLogger = void 0;
|
|
4
4
|
/** Lightweight logger for @terreno/test internals (avoids importing @terreno/api). */
|
|
5
5
|
exports.testLogger = {
|
|
6
|
-
catch:
|
|
6
|
+
catch: (error) => {
|
|
7
7
|
if (process.env.DEBUG_MONGO_PRELOAD === "true" || process.env.SHOW_ALL_TEST_LOGS === "true") {
|
|
8
8
|
console.error(error);
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
|
-
debug:
|
|
11
|
+
debug: (message) => {
|
|
12
12
|
if (process.env.DEBUG_MONGO_PRELOAD === "true") {
|
|
13
13
|
console.debug(message);
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
info:
|
|
16
|
+
info: (message) => {
|
|
17
17
|
console.info(message);
|
|
18
18
|
},
|
|
19
|
-
warn:
|
|
19
|
+
warn: (message) => {
|
|
20
20
|
console.warn(message);
|
|
21
21
|
},
|
|
22
22
|
};
|