@cedarjs/testing 0.7.2-next.2 → 0.7.2-next.49
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/config/jest/api/package.json +8 -0
- package/config/jest/web/package.json +8 -0
- package/dist/api/mockContext.d.ts +5 -0
- package/dist/api/mockContext.d.ts.map +1 -0
- package/dist/api/mockContext.js +33 -0
- package/dist/api/vitest/CedarApiVitestEnv.d.ts +5 -0
- package/dist/api/vitest/CedarApiVitestEnv.d.ts.map +1 -0
- package/dist/api/vitest/CedarApiVitestEnv.js +41 -0
- package/dist/api/vitest/index.d.ts +4 -0
- package/dist/api/vitest/index.d.ts.map +1 -0
- package/dist/api/vitest/index.js +8 -0
- package/dist/api/vitest/vite-plugin-auto-import.d.ts +2 -0
- package/dist/api/vitest/vite-plugin-auto-import.d.ts.map +1 -0
- package/dist/api/vitest/vite-plugin-auto-import.js +37 -0
- package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.d.ts +3 -0
- package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.d.ts.map +1 -0
- package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.js +34 -0
- package/dist/api/vitest/vite-plugin-track-db-imports.d.ts +3 -0
- package/dist/api/vitest/vite-plugin-track-db-imports.d.ts.map +1 -0
- package/dist/api/vitest/vite-plugin-track-db-imports.js +23 -0
- package/dist/api/vitest/vitest-api.setup.d.ts +9 -0
- package/dist/api/vitest/vitest-api.setup.d.ts.map +1 -0
- package/dist/api/vitest/vitest-api.setup.js +247 -0
- package/dist/cjs/api/mockContext.d.ts +5 -0
- package/dist/cjs/api/mockContext.d.ts.map +1 -0
- package/dist/cjs/api/mockContext.js +58 -0
- package/dist/cjs/api/vitest/CedarApiVitestEnv.js +71 -0
- package/dist/cjs/api/vitest/index.js +34 -0
- package/dist/cjs/api/vitest/vite-plugin-auto-import.js +71 -0
- package/dist/cjs/api/vitest/vite-plugin-cedar-vitest-api-config.js +69 -0
- package/dist/cjs/api/vitest/vite-plugin-track-db-imports.js +47 -0
- package/dist/cjs/api/vitest/vitest-api.setup.js +270 -0
- package/dist/cjs/web/MockProviders.d.ts +0 -4
- package/dist/cjs/web/MockProviders.d.ts.map +1 -1
- package/dist/cjs/web/MockProviders.js +2 -1
- package/dist/cjs/web/MockRouter.d.ts +0 -3
- package/dist/cjs/web/MockRouter.d.ts.map +1 -1
- package/dist/cjs/web/globRoutesImporter.d.ts +13 -0
- package/dist/cjs/web/globRoutesImporter.d.ts.map +1 -0
- package/dist/cjs/web/globRoutesImporter.js +46 -0
- package/dist/cjs/web/vitest/index.d.ts +4 -0
- package/dist/cjs/web/vitest/index.d.ts.map +1 -0
- package/dist/cjs/web/vitest/index.js +34 -0
- package/dist/cjs/web/vitest/vite-plugin-auto-import.d.ts +2 -0
- package/dist/cjs/web/vitest/vite-plugin-auto-import.d.ts.map +1 -0
- package/dist/cjs/web/vitest/vite-plugin-auto-import.js +60 -0
- package/dist/cjs/web/vitest/vite-plugin-cedarjs-router-import-transform.d.ts +7 -0
- package/dist/cjs/web/vitest/vite-plugin-cedarjs-router-import-transform.d.ts.map +1 -0
- package/dist/cjs/web/vitest/vite-plugin-cedarjs-router-import-transform.js +42 -0
- package/dist/cjs/web/vitest/vite-plugin-create-auth-import-transform.d.ts +3 -0
- package/dist/cjs/web/vitest/vite-plugin-create-auth-import-transform.d.ts.map +1 -0
- package/dist/cjs/web/vitest/vite-plugin-create-auth-import-transform.js +43 -0
- package/dist/web/MockProviders.d.ts +0 -4
- package/dist/web/MockProviders.d.ts.map +1 -1
- package/dist/web/MockProviders.js +2 -1
- package/dist/web/MockRouter.d.ts +0 -3
- package/dist/web/MockRouter.d.ts.map +1 -1
- package/dist/web/globRoutesImporter.d.ts +13 -0
- package/dist/web/globRoutesImporter.d.ts.map +1 -0
- package/dist/web/globRoutesImporter.js +21 -0
- package/dist/web/vitest/index.d.ts +4 -0
- package/dist/web/vitest/index.d.ts.map +1 -0
- package/dist/web/vitest/index.js +8 -0
- package/dist/web/vitest/vite-plugin-auto-import.d.ts +2 -0
- package/dist/web/vitest/vite-plugin-auto-import.d.ts.map +1 -0
- package/dist/web/vitest/vite-plugin-auto-import.js +26 -0
- package/dist/web/vitest/vite-plugin-cedarjs-router-import-transform.d.ts +7 -0
- package/dist/web/vitest/vite-plugin-cedarjs-router-import-transform.d.ts.map +1 -0
- package/dist/web/vitest/vite-plugin-cedarjs-router-import-transform.js +18 -0
- package/dist/web/vitest/vite-plugin-create-auth-import-transform.d.ts +3 -0
- package/dist/web/vitest/vite-plugin-create-auth-import-transform.d.ts.map +1 -0
- package/dist/web/vitest/vite-plugin-create-auth-import-transform.js +19 -0
- package/package.json +39 -12
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var vitest_exports = {};
|
|
20
|
+
__export(vitest_exports, {
|
|
21
|
+
autoImportsPlugin: () => import_vite_plugin_auto_import.autoImportsPlugin,
|
|
22
|
+
cedarVitestApiConfigPlugin: () => import_vite_plugin_cedar_vitest_api_config.cedarVitestApiConfigPlugin,
|
|
23
|
+
trackDbImportsPlugin: () => import_vite_plugin_track_db_imports.trackDbImportsPlugin
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(vitest_exports);
|
|
26
|
+
var import_vite_plugin_auto_import = require("./vite-plugin-auto-import.js");
|
|
27
|
+
var import_vite_plugin_cedar_vitest_api_config = require("./vite-plugin-cedar-vitest-api-config.js");
|
|
28
|
+
var import_vite_plugin_track_db_imports = require("./vite-plugin-track-db-imports.js");
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
autoImportsPlugin,
|
|
32
|
+
cedarVitestApiConfigPlugin,
|
|
33
|
+
trackDbImportsPlugin
|
|
34
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var vite_plugin_auto_import_exports = {};
|
|
30
|
+
__export(vite_plugin_auto_import_exports, {
|
|
31
|
+
autoImportsPlugin: () => autoImportsPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_auto_import_exports);
|
|
34
|
+
var import_vite = __toESM(require("unplugin-auto-import/vite"), 1);
|
|
35
|
+
function autoImportsPlugin() {
|
|
36
|
+
return (0, import_vite.default)({
|
|
37
|
+
// targets to transform
|
|
38
|
+
include: [
|
|
39
|
+
/\.[tj]sx?$/
|
|
40
|
+
// .ts, .tsx, .js, .jsx
|
|
41
|
+
],
|
|
42
|
+
// global imports to register
|
|
43
|
+
imports: [
|
|
44
|
+
// import { mockContext, mockHttpEvent, mockSignedWebhook } from '@cedarjs/testing/api';
|
|
45
|
+
{
|
|
46
|
+
"@cedarjs/testing/api": [
|
|
47
|
+
"mockContext",
|
|
48
|
+
"mockHttpEvent",
|
|
49
|
+
"mockSignedWebhook"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
// import { gql } from 'graphql-tag'
|
|
53
|
+
{
|
|
54
|
+
"graphql-tag": ["gql"]
|
|
55
|
+
},
|
|
56
|
+
// import { context } from '@cedarjs/context'
|
|
57
|
+
{
|
|
58
|
+
"@cedarjs/context": ["context"]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
// We provide our mocking types elsewhere and so don't need this plugin to
|
|
62
|
+
// generate them.
|
|
63
|
+
// TODO: Maybe we should have it at least generate the types for the gql
|
|
64
|
+
// import? (Or do we already provide that some other way?)
|
|
65
|
+
dts: false
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
autoImportsPlugin
|
|
71
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var vite_plugin_cedar_vitest_api_config_exports = {};
|
|
30
|
+
__export(vite_plugin_cedar_vitest_api_config_exports, {
|
|
31
|
+
cedarVitestApiConfigPlugin: () => cedarVitestApiConfigPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_cedar_vitest_api_config_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
36
|
+
const import_meta = {};
|
|
37
|
+
function cedarVitestApiConfigPlugin() {
|
|
38
|
+
return {
|
|
39
|
+
name: "cedar-vitest-plugin",
|
|
40
|
+
config: () => {
|
|
41
|
+
return {
|
|
42
|
+
define: (0, import_project_config.getEnvVarDefinitions)(),
|
|
43
|
+
ssr: {
|
|
44
|
+
noExternal: ["@cedarjs/testing"]
|
|
45
|
+
},
|
|
46
|
+
resolve: {
|
|
47
|
+
alias: {
|
|
48
|
+
src: (0, import_project_config.getPaths)().api.src
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
test: {
|
|
52
|
+
environment: import_node_path.default.join(import_meta.dirname, "CedarApiVitestEnv.js"),
|
|
53
|
+
// fileParallelism: false,
|
|
54
|
+
// fileParallelism doesn't work with vitest projects (which is what
|
|
55
|
+
// we're using in the root vitest.config.ts). As a workaround we set
|
|
56
|
+
// poolOptions instead, which also shouldn't work, but was suggested
|
|
57
|
+
// by Vitest team member AriPerkkio (Hiroshi's answer didn't work).
|
|
58
|
+
// https://github.com/vitest-dev/vitest/discussions/7416
|
|
59
|
+
poolOptions: { forks: { singleFork: true } },
|
|
60
|
+
setupFiles: [import_node_path.default.join(import_meta.dirname, "vitest-api.setup.js")]
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
cedarVitestApiConfigPlugin
|
|
69
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var vite_plugin_track_db_imports_exports = {};
|
|
20
|
+
__export(vite_plugin_track_db_imports_exports, {
|
|
21
|
+
trackDbImportsPlugin: () => trackDbImportsPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(vite_plugin_track_db_imports_exports);
|
|
24
|
+
function trackDbImportsPlugin() {
|
|
25
|
+
return {
|
|
26
|
+
name: "db-import-tracker",
|
|
27
|
+
transform(code, id) {
|
|
28
|
+
if (id.match(/\/api\/src\/lib\/db\.(js|ts)$/) && code.includes("PrismaClient")) {
|
|
29
|
+
return code + `
|
|
30
|
+
;if (typeof globalThis !== "undefined") {
|
|
31
|
+
globalThis.__cedarjs_db_imported__ = true;
|
|
32
|
+
} else {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"vite-plugin-track-db-imports: globalThis is undefined. " +
|
|
35
|
+
"This is an error with CedarJS"
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
return code;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
trackDbImportsPlugin
|
|
47
|
+
});
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
25
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
26
|
+
var import_vitest = require("vitest");
|
|
27
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
28
|
+
var import_api = require("@cedarjs/testing/api");
|
|
29
|
+
const mockContextStore = import_vitest.vi.hoisted(() => /* @__PURE__ */ new Map());
|
|
30
|
+
const mockContext = import_vitest.vi.hoisted(
|
|
31
|
+
() => new Proxy(
|
|
32
|
+
{},
|
|
33
|
+
{
|
|
34
|
+
get: (_target, prop) => {
|
|
35
|
+
if (prop === "toJSON") {
|
|
36
|
+
return () => mockContextStore.get("context");
|
|
37
|
+
}
|
|
38
|
+
return mockContextStore.get("context")[prop];
|
|
39
|
+
},
|
|
40
|
+
set: (_target, prop, value) => {
|
|
41
|
+
const ctx = mockContextStore.get("context");
|
|
42
|
+
ctx[prop] = value;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
import_vitest.vi.mock("@cedarjs/context", () => {
|
|
49
|
+
return {
|
|
50
|
+
context: mockContext,
|
|
51
|
+
setContext: (newContext) => {
|
|
52
|
+
mockContextStore.set("context", newContext);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
(0, import_vitest.beforeEach)(() => {
|
|
57
|
+
mockContextStore.set("context", {});
|
|
58
|
+
});
|
|
59
|
+
globalThis.mockCurrentUser = (currentUser) => {
|
|
60
|
+
mockContextStore.set("context", { currentUser });
|
|
61
|
+
};
|
|
62
|
+
globalThis.defineScenario = import_api.defineScenario;
|
|
63
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
64
|
+
const FOREIGN_KEY_ERRORS = [1451, 1811, 23503];
|
|
65
|
+
const TEARDOWN_CACHE_PATH = import_node_path.default.join(
|
|
66
|
+
cedarPaths.generated.base,
|
|
67
|
+
"scenarioTeardown.json"
|
|
68
|
+
);
|
|
69
|
+
const DEFAULT_SCENARIO = "standard";
|
|
70
|
+
let teardownOrder = [];
|
|
71
|
+
let originalTeardownOrder = [];
|
|
72
|
+
function buildScenario(itFunc) {
|
|
73
|
+
return (...args) => {
|
|
74
|
+
let scenarioName;
|
|
75
|
+
let testName;
|
|
76
|
+
let testFunc;
|
|
77
|
+
if (args.length === 3) {
|
|
78
|
+
;
|
|
79
|
+
[scenarioName, testName, testFunc] = args;
|
|
80
|
+
} else if (args.length === 2) {
|
|
81
|
+
scenarioName = DEFAULT_SCENARIO;
|
|
82
|
+
[testName, testFunc] = args;
|
|
83
|
+
} else {
|
|
84
|
+
throw new Error("scenario() requires 2 or 3 arguments");
|
|
85
|
+
}
|
|
86
|
+
return itFunc(testName, async (ctx) => {
|
|
87
|
+
const testPath = ctx.task.file.filepath;
|
|
88
|
+
const { scenario } = await loadScenarios(testPath, scenarioName);
|
|
89
|
+
const scenarioData = await seedScenario(scenario);
|
|
90
|
+
try {
|
|
91
|
+
const result = await testFunc(scenarioData);
|
|
92
|
+
return result;
|
|
93
|
+
} finally {
|
|
94
|
+
await teardown();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function buildDescribeScenario(describeFunc) {
|
|
100
|
+
return (...args) => {
|
|
101
|
+
let scenarioName;
|
|
102
|
+
let describeBlockName;
|
|
103
|
+
let describeBlock;
|
|
104
|
+
if (args.length === 3) {
|
|
105
|
+
;
|
|
106
|
+
[scenarioName, describeBlockName, describeBlock] = args;
|
|
107
|
+
} else if (args.length === 2) {
|
|
108
|
+
scenarioName = DEFAULT_SCENARIO;
|
|
109
|
+
[describeBlockName, describeBlock] = args;
|
|
110
|
+
} else {
|
|
111
|
+
throw new Error("describeScenario() requires 2 or 3 arguments");
|
|
112
|
+
}
|
|
113
|
+
return describeFunc(describeBlockName, () => {
|
|
114
|
+
let scenarioData;
|
|
115
|
+
(0, import_vitest.beforeAll)(async (ctx) => {
|
|
116
|
+
const testPath = ctx.file.filepath;
|
|
117
|
+
const { scenario } = await loadScenarios(testPath, scenarioName);
|
|
118
|
+
scenarioData = await seedScenario(scenario);
|
|
119
|
+
});
|
|
120
|
+
(0, import_vitest.afterAll)(async () => {
|
|
121
|
+
await teardown();
|
|
122
|
+
});
|
|
123
|
+
const getScenario = () => scenarioData;
|
|
124
|
+
describeBlock(getScenario);
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async function configureTeardown() {
|
|
129
|
+
if (!wasDbImported()) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const { getDMMF, getSchema } = await import("@prisma/internals");
|
|
133
|
+
const datamodel = await getSchema(cedarPaths.api.dbSchema);
|
|
134
|
+
const schema = await getDMMF({ datamodel });
|
|
135
|
+
const schemaModels = schema.datamodel.models.map((m) => {
|
|
136
|
+
return m.dbName || m.name;
|
|
137
|
+
});
|
|
138
|
+
if (import_node_fs.default.existsSync(TEARDOWN_CACHE_PATH)) {
|
|
139
|
+
teardownOrder = JSON.parse(import_node_fs.default.readFileSync(TEARDOWN_CACHE_PATH).toString());
|
|
140
|
+
}
|
|
141
|
+
if (teardownOrder.length !== schemaModels.length) {
|
|
142
|
+
teardownOrder = schemaModels;
|
|
143
|
+
}
|
|
144
|
+
originalTeardownOrder = deepCopy(teardownOrder);
|
|
145
|
+
}
|
|
146
|
+
(0, import_vitest.beforeAll)(async () => {
|
|
147
|
+
await configureTeardown();
|
|
148
|
+
});
|
|
149
|
+
(0, import_vitest.afterAll)(() => {
|
|
150
|
+
globalThis.__cedarjs_db_imported__ = false;
|
|
151
|
+
});
|
|
152
|
+
async function teardown() {
|
|
153
|
+
if (!wasDbImported()) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const quoteStyle2 = await getQuoteStyle();
|
|
157
|
+
const projectDb = await getProjectDb();
|
|
158
|
+
for (const modelName of teardownOrder) {
|
|
159
|
+
try {
|
|
160
|
+
const query = `DELETE FROM ${quoteStyle2}${modelName}${quoteStyle2}`;
|
|
161
|
+
await projectDb.$executeRawUnsafe(query);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
console.error("teardown error\n", e);
|
|
164
|
+
const match = isErrorWithMessage(e) && e.message.match(/Code: `(\d+)`/);
|
|
165
|
+
if (match && FOREIGN_KEY_ERRORS.includes(parseInt(match[1]))) {
|
|
166
|
+
const index = teardownOrder.indexOf(modelName);
|
|
167
|
+
teardownOrder[index] = null;
|
|
168
|
+
teardownOrder.push(modelName);
|
|
169
|
+
} else {
|
|
170
|
+
throw e;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
teardownOrder = teardownOrder.filter((val) => val);
|
|
175
|
+
if (!isIdenticalArray(teardownOrder, originalTeardownOrder)) {
|
|
176
|
+
originalTeardownOrder = deepCopy(teardownOrder);
|
|
177
|
+
import_node_fs.default.writeFileSync(TEARDOWN_CACHE_PATH, JSON.stringify(teardownOrder));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const seedScenario = async (scenario) => {
|
|
181
|
+
if (scenario) {
|
|
182
|
+
const scenarios = {};
|
|
183
|
+
const projectDb = await getProjectDb();
|
|
184
|
+
for (const [model, namedFixtures] of Object.entries(scenario)) {
|
|
185
|
+
scenarios[model] = {};
|
|
186
|
+
for (const [name, createArgs] of Object.entries(namedFixtures)) {
|
|
187
|
+
if (typeof createArgs === "function") {
|
|
188
|
+
scenarios[model][name] = await projectDb[model].create(
|
|
189
|
+
createArgs(scenarios)
|
|
190
|
+
);
|
|
191
|
+
} else {
|
|
192
|
+
scenarios[model][name] = await projectDb[model].create(createArgs);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return scenarios;
|
|
197
|
+
} else {
|
|
198
|
+
return {};
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
async function loadScenarios(testPath, scenarioName) {
|
|
202
|
+
const testFileDir = import_node_path.default.parse(testPath);
|
|
203
|
+
const testFileNameParts = testFileDir.name.split(".");
|
|
204
|
+
const testFilePath = `${testFileDir.dir}/${testFileNameParts.slice(0, testFileNameParts.length - 1).join(".")}.scenarios`;
|
|
205
|
+
let allScenarios;
|
|
206
|
+
let scenario;
|
|
207
|
+
try {
|
|
208
|
+
allScenarios = await import(testFilePath);
|
|
209
|
+
} catch (e) {
|
|
210
|
+
if (isErrorWithCode(e)) {
|
|
211
|
+
if (e instanceof Error) {
|
|
212
|
+
throw e;
|
|
213
|
+
} else {
|
|
214
|
+
console.error("unexpected error type", e);
|
|
215
|
+
throw e;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (allScenarios) {
|
|
220
|
+
if (allScenarios[scenarioName]) {
|
|
221
|
+
scenario = allScenarios[scenarioName];
|
|
222
|
+
} else {
|
|
223
|
+
throw new Error(
|
|
224
|
+
`UndefinedScenario: There is no scenario named "${scenarioName}" in ${testFilePath}.{js,ts}`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return { scenario };
|
|
229
|
+
}
|
|
230
|
+
const wasDbImported = () => {
|
|
231
|
+
return Boolean(globalThis.__cedarjs_db_imported__);
|
|
232
|
+
};
|
|
233
|
+
let quoteStyle;
|
|
234
|
+
async function getQuoteStyle() {
|
|
235
|
+
const { getConfig: getPrismaConfig, getSchema } = await import("@prisma/internals");
|
|
236
|
+
const datamodel = await getSchema(cedarPaths.api.dbSchema);
|
|
237
|
+
if (!quoteStyle) {
|
|
238
|
+
const config = await getPrismaConfig({
|
|
239
|
+
datamodel
|
|
240
|
+
});
|
|
241
|
+
switch (config.datasources?.[0]?.provider) {
|
|
242
|
+
case "mysql":
|
|
243
|
+
quoteStyle = "`";
|
|
244
|
+
break;
|
|
245
|
+
default:
|
|
246
|
+
quoteStyle = '"';
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return quoteStyle;
|
|
250
|
+
}
|
|
251
|
+
async function getProjectDb() {
|
|
252
|
+
const libDb = await import(`${cedarPaths.api.lib}/db`);
|
|
253
|
+
return libDb.db;
|
|
254
|
+
}
|
|
255
|
+
function isIdenticalArray(a, b) {
|
|
256
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
257
|
+
}
|
|
258
|
+
function deepCopy(obj) {
|
|
259
|
+
return JSON.parse(JSON.stringify(obj));
|
|
260
|
+
}
|
|
261
|
+
function isErrorWithMessage(e) {
|
|
262
|
+
return !!e && typeof e === "object" && "message" in e && typeof e.message === "string";
|
|
263
|
+
}
|
|
264
|
+
function isErrorWithCode(e) {
|
|
265
|
+
return !!e && typeof e === "object" && "code" in e && typeof e.code === "string";
|
|
266
|
+
}
|
|
267
|
+
globalThis.scenario = buildScenario(import_vitest.it);
|
|
268
|
+
globalThis.scenario.only = buildScenario(import_vitest.it.only);
|
|
269
|
+
globalThis.describeScenario = buildDescribeScenario(import_vitest.describe);
|
|
270
|
+
globalThis.describeScenario.only = buildDescribeScenario(import_vitest.describe.only);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockProviders.d.ts","sourceRoot":"","sources":["../../../src/web/MockProviders.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"MockProviders.d.ts","sourceRoot":"","sources":["../../../src/web/MockProviders.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AA+BzB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,iBAAiB,CAAC;IAClD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAYA,CAAA"}
|
|
@@ -35,6 +35,7 @@ var import_react = __toESM(require("react"), 1);
|
|
|
35
35
|
var import_router = require("@cedarjs/router");
|
|
36
36
|
var import_web = require("@cedarjs/web");
|
|
37
37
|
var import_apollo = require("@cedarjs/web/apollo");
|
|
38
|
+
var import_globRoutesImporter = require("./globRoutesImporter.js");
|
|
38
39
|
var import_mockAuth = require("./mockAuth.js");
|
|
39
40
|
var import_MockParamsProvider = require("./MockParamsProvider.js");
|
|
40
41
|
let UserRoutes;
|
|
@@ -48,7 +49,7 @@ try {
|
|
|
48
49
|
UserRoutes = () => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null);
|
|
49
50
|
}
|
|
50
51
|
const MockProviders = ({ children }) => {
|
|
51
|
-
return /* @__PURE__ */ import_react.default.createElement(import_web.RedwoodProvider, { titleTemplate: "%PageTitle | %AppTitle" }, /* @__PURE__ */ import_react.default.createElement(import_apollo.RedwoodApolloProvider, { useAuth: import_mockAuth.useAuth }, /* @__PURE__ */ import_react.default.createElement(UserRoutes, null), /* @__PURE__ */ import_react.default.createElement(import_router.LocationProvider, null, /* @__PURE__ */ import_react.default.createElement(import_MockParamsProvider.MockParamsProvider, null, children))));
|
|
52
|
+
return /* @__PURE__ */ import_react.default.createElement(import_web.RedwoodProvider, { titleTemplate: "%PageTitle | %AppTitle" }, /* @__PURE__ */ import_react.default.createElement(import_apollo.RedwoodApolloProvider, { useAuth: import_mockAuth.useAuth }, /* @__PURE__ */ import_react.default.createElement(UserRoutes, null), /* @__PURE__ */ import_react.default.createElement(import_globRoutesImporter.UserRoutes, null), /* @__PURE__ */ import_react.default.createElement(import_router.LocationProvider, null, /* @__PURE__ */ import_react.default.createElement(import_MockParamsProvider.MockParamsProvider, null, children))));
|
|
52
53
|
};
|
|
53
54
|
function isModuleNotFoundError(error, module2) {
|
|
54
55
|
return !!error && typeof error === "object" && "code" in error && error.code === "MODULE_NOT_FOUND" && "moduleName" in error && error.moduleName === module2;
|
|
@@ -5,9 +5,6 @@ export declare const routes: {
|
|
|
5
5
|
[routeName: string]: () => string;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
|
-
* We overwrite the default `Router` export (see jest-preset). So every import
|
|
9
|
-
* of @cedarjs/router will import this Router instead
|
|
10
|
-
*
|
|
11
8
|
* This router populates the `routes.<pageName>()` utility object.
|
|
12
9
|
*/
|
|
13
10
|
export declare const Router: React.FC<RouterProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockRouter.d.ts","sourceRoot":"","sources":["../../../src/web/MockRouter.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MockRouter.d.ts","sourceRoot":"","sources":["../../../src/web/MockRouter.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAO9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAG9D,cAAc,4BAA4B,CAAA;AAE1C,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,MAAM,CAAA;CAAO,CAAA;AAE/D;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAcxC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* All the routes the user has defined
|
|
3
|
+
*
|
|
4
|
+
* We render this in the `<MockProviders>` component to populate the `routes`
|
|
5
|
+
* import from `@cedarjs/router` to make sure code like
|
|
6
|
+
* `<Link to={routes.home()}>Home</Link>` works in tests
|
|
7
|
+
*
|
|
8
|
+
* The final piece to this puzzle is to realize that the user's Routes file
|
|
9
|
+
* imports `@cedarjs/router`, which we replace to import from '@cedarjs/testing'
|
|
10
|
+
* instead using a vite plugin that we only run for vitest and storybook
|
|
11
|
+
*/
|
|
12
|
+
export declare const UserRoutes: React.FC;
|
|
13
|
+
//# sourceMappingURL=globRoutesImporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globRoutesImporter.d.ts","sourceRoot":"","sources":["../../../src/web/globRoutesImporter.ts"],"names":[],"mappings":"AAwCA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,EAAqB,KAAK,CAAC,EAAE,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var globRoutesImporter_exports = {};
|
|
20
|
+
__export(globRoutesImporter_exports, {
|
|
21
|
+
UserRoutes: () => UserRoutes
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(globRoutesImporter_exports);
|
|
24
|
+
const import_meta = { glob: () => ({ "routes.tsx": () => null }) };
|
|
25
|
+
const defaultExports = import_meta.glob(
|
|
26
|
+
["/src/Routes.{tsx,jsx}", "/Routes.{tsx,jsx}"],
|
|
27
|
+
{
|
|
28
|
+
import: "default",
|
|
29
|
+
eager: true
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
const routesFileName = Object.keys(defaultExports)[0];
|
|
33
|
+
if (!routesFileName) {
|
|
34
|
+
throw new Error("@cedarjs/testing: No routes found");
|
|
35
|
+
}
|
|
36
|
+
const routesFunction = defaultExports[routesFileName];
|
|
37
|
+
if (typeof routesFunction !== "function") {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"@cedarjs/testing: Routes file does not export a React component"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
const UserRoutes = routesFunction;
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
UserRoutes
|
|
46
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { cedarJsRouterImportTransformPlugin } from './vite-plugin-cedarjs-router-import-transform.js';
|
|
2
|
+
export { createAuthImportTransformPlugin } from './vite-plugin-create-auth-import-transform.js';
|
|
3
|
+
export { autoImportsPlugin } from './vite-plugin-auto-import.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/web/vitest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,kDAAkD,CAAA;AACrG,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAA;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var vitest_exports = {};
|
|
20
|
+
__export(vitest_exports, {
|
|
21
|
+
autoImportsPlugin: () => import_vite_plugin_auto_import.autoImportsPlugin,
|
|
22
|
+
cedarJsRouterImportTransformPlugin: () => import_vite_plugin_cedarjs_router_import_transform.cedarJsRouterImportTransformPlugin,
|
|
23
|
+
createAuthImportTransformPlugin: () => import_vite_plugin_create_auth_import_transform.createAuthImportTransformPlugin
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(vitest_exports);
|
|
26
|
+
var import_vite_plugin_cedarjs_router_import_transform = require("./vite-plugin-cedarjs-router-import-transform.js");
|
|
27
|
+
var import_vite_plugin_create_auth_import_transform = require("./vite-plugin-create-auth-import-transform.js");
|
|
28
|
+
var import_vite_plugin_auto_import = require("./vite-plugin-auto-import.js");
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
autoImportsPlugin,
|
|
32
|
+
cedarJsRouterImportTransformPlugin,
|
|
33
|
+
createAuthImportTransformPlugin
|
|
34
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-auto-import.d.ts","sourceRoot":"","sources":["../../../../src/web/vitest/vite-plugin-auto-import.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,QAsBhC"}
|