jaypie 0.1.3 → 0.1.4
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/package.json
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from "vitest";
|
|
10
10
|
|
|
11
11
|
// Subject
|
|
12
|
-
|
|
12
|
+
// * Subject is imported dynamically to allow `vi.resetModules()` to apply different mocks
|
|
13
13
|
|
|
14
14
|
//
|
|
15
15
|
//
|
|
@@ -41,6 +41,16 @@ afterEach(() => {
|
|
|
41
41
|
//
|
|
42
42
|
|
|
43
43
|
describe("Mongoose Package", () => {
|
|
44
|
+
let connectFromSecretEnv;
|
|
45
|
+
let disconnect;
|
|
46
|
+
beforeAll(async () => {
|
|
47
|
+
const {
|
|
48
|
+
connectFromSecretEnv: _connectFromSecretEnv,
|
|
49
|
+
disconnect: _disconnect,
|
|
50
|
+
} = await import("../mongoose.package.js");
|
|
51
|
+
connectFromSecretEnv = _connectFromSecretEnv;
|
|
52
|
+
disconnect = _disconnect;
|
|
53
|
+
});
|
|
44
54
|
it("Works", () => {
|
|
45
55
|
expect(connectFromSecretEnv).toBeFunction();
|
|
46
56
|
expect(disconnect).toBeFunction();
|
|
@@ -58,7 +68,8 @@ describe("Mongoose Package", () => {
|
|
|
58
68
|
describe("Features", () => {
|
|
59
69
|
const mockConnectFromSecretEnv = vi.fn();
|
|
60
70
|
const mockDisconnect = vi.fn();
|
|
61
|
-
beforeAll(() => {
|
|
71
|
+
beforeAll(async () => {
|
|
72
|
+
// Setup mock of mongoose
|
|
62
73
|
vi.doMock("@jaypie/mongoose", () => {
|
|
63
74
|
return {
|
|
64
75
|
connectFromSecretEnv: mockConnectFromSecretEnv,
|
|
@@ -68,6 +79,15 @@ describe("Mongoose Package", () => {
|
|
|
68
79
|
},
|
|
69
80
|
};
|
|
70
81
|
});
|
|
82
|
+
// Preprocess
|
|
83
|
+
vi.resetModules();
|
|
84
|
+
const {
|
|
85
|
+
connectFromSecretEnv: _connectFromSecretEnv,
|
|
86
|
+
disconnect: _disconnect,
|
|
87
|
+
} = await import("../mongoose.package.js");
|
|
88
|
+
// Return
|
|
89
|
+
connectFromSecretEnv = _connectFromSecretEnv;
|
|
90
|
+
disconnect = _disconnect;
|
|
71
91
|
});
|
|
72
92
|
it("Calls @jaypie/mongoose for connectFromSecretEnv", async () => {
|
|
73
93
|
await connectFromSecretEnv();
|
|
@@ -57,15 +57,9 @@ export default async ({
|
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
59
|
// Setup
|
|
60
|
+
let imported;
|
|
60
61
|
const returning = {};
|
|
61
|
-
//
|
|
62
|
-
for (const key of functions) {
|
|
63
|
-
returning[key] = async () => {
|
|
64
|
-
const imported = await dynamicImport(moduleImport);
|
|
65
|
-
return await imported[key]();
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
let imported = {};
|
|
62
|
+
// Preprocess
|
|
69
63
|
try {
|
|
70
64
|
imported = await dynamicImport(moduleImport);
|
|
71
65
|
} catch (error) {
|
|
@@ -73,8 +67,25 @@ export default async ({
|
|
|
73
67
|
`[jaypie] ${moduleImport} could not be imported; continuing`,
|
|
74
68
|
);
|
|
75
69
|
}
|
|
70
|
+
// Process
|
|
71
|
+
for (const key of functions) {
|
|
72
|
+
if (imported) {
|
|
73
|
+
returning[key] = imported[key];
|
|
74
|
+
} else {
|
|
75
|
+
returning[key] = () => {
|
|
76
|
+
throw new ConfigurationError(
|
|
77
|
+
`Function ${key} cannot be called because ${moduleImport} is not installed`,
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
76
82
|
for (const key of vars) {
|
|
77
|
-
|
|
83
|
+
if (imported) {
|
|
84
|
+
returning[key] = imported[key];
|
|
85
|
+
} else {
|
|
86
|
+
// TODO: make the not found vars throw only _when accessed_
|
|
87
|
+
returning[key] = undefined;
|
|
88
|
+
}
|
|
78
89
|
}
|
|
79
90
|
// Return
|
|
80
91
|
return returning;
|