jaypie 0.1.3 → 0.1.5
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jaypie",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"author": "Finlayson Studio",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"test:spec:mongoose.package": "vitest run ./src/__tests__/mongoose.package.spec.js"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@jaypie/core": "^0.4.
|
|
20
|
+
"@jaypie/core": "^0.4.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@jaypie/testkit": "^1.0.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@jaypie/aws": "^0.1.1",
|
|
37
|
-
"@jaypie/lambda": "^0.1.
|
|
37
|
+
"@jaypie/lambda": "^0.1.3",
|
|
38
38
|
"@jaypie/mongoose": "^0.1.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
@@ -73,13 +73,24 @@ describe("Dynamic Export Function", () => {
|
|
|
73
73
|
it("Returns an object", () => {
|
|
74
74
|
expect(dynamicExport({ moduleImport: MOCK.MODULE })).toBeObject();
|
|
75
75
|
});
|
|
76
|
-
it("
|
|
76
|
+
it("If module is not found and you try to get a scalar it will throw", async () => {
|
|
77
77
|
const vars = ["scalar"];
|
|
78
78
|
const result = await dynamicExport({
|
|
79
79
|
vars,
|
|
80
80
|
moduleImport: MOCK.MODULE,
|
|
81
81
|
});
|
|
82
|
-
expect(
|
|
82
|
+
await expect(() => {
|
|
83
|
+
console.log("result.scalar :>> ", result.scalar);
|
|
84
|
+
try {
|
|
85
|
+
console.log("result.scalar.taco :>> ", result.scalar.taco);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.log("error :>> ", error);
|
|
88
|
+
}
|
|
89
|
+
if (result.scalar) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}).toThrow();
|
|
83
94
|
});
|
|
84
95
|
it("Exported functions throw if the real module is not installed", async () => {
|
|
85
96
|
const functions = ["default"];
|
|
@@ -87,7 +98,17 @@ describe("Dynamic Export Function", () => {
|
|
|
87
98
|
functions,
|
|
88
99
|
moduleImport: MOCK.MODULE,
|
|
89
100
|
});
|
|
90
|
-
await expect(
|
|
101
|
+
await expect(() => {
|
|
102
|
+
result.default();
|
|
103
|
+
}).toThrow();
|
|
104
|
+
});
|
|
105
|
+
it("Scalars that never existed are undefined", async () => {
|
|
106
|
+
const vars = ["scalar"];
|
|
107
|
+
const result = await dynamicExport({
|
|
108
|
+
vars,
|
|
109
|
+
moduleImport: MOCK.MODULE,
|
|
110
|
+
});
|
|
111
|
+
expect(result.bogus).toBeUndefined();
|
|
91
112
|
});
|
|
92
113
|
});
|
|
93
114
|
describe("Features", () => {
|
|
@@ -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();
|
|
@@ -56,26 +56,28 @@ export default async ({
|
|
|
56
56
|
"Either `functions` or `vars` must be provided",
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
|
-
// Setup
|
|
60
|
-
const returning = {};
|
|
61
59
|
// Process
|
|
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 = {};
|
|
69
60
|
try {
|
|
70
|
-
|
|
61
|
+
// Attempt to import the module
|
|
62
|
+
return await dynamicImport(moduleImport);
|
|
71
63
|
} catch (error) {
|
|
72
64
|
moduleLogger.trace(
|
|
73
65
|
`[jaypie] ${moduleImport} could not be imported; continuing`,
|
|
74
66
|
);
|
|
75
67
|
}
|
|
76
|
-
for (const key of vars) {
|
|
77
|
-
returning[key] = imported[key];
|
|
78
|
-
}
|
|
79
68
|
// Return
|
|
80
|
-
|
|
69
|
+
// * Returns a proxy that throws if you call a functions or get a vars
|
|
70
|
+
return new Proxy(
|
|
71
|
+
{},
|
|
72
|
+
{
|
|
73
|
+
get: (target, prop) => {
|
|
74
|
+
if (functions.includes(prop) || vars.includes(prop)) {
|
|
75
|
+
throw new ConfigurationError(
|
|
76
|
+
`Attempted to access ${prop} from ${moduleImport}, but it is not installed`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
);
|
|
81
83
|
};
|