@cedarjs/testing 2.8.1-next.116 → 2.8.1
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/globalSetup.d.ts.map +1 -1
- package/config/jest/api/globalSetup.js +18 -6
- package/config/jest/api/jest-preset.d.ts.map +1 -1
- package/config/jest/api/jest-preset.js +6 -7
- package/config/jest/api/jest.setup.js +12 -8
- package/dist/api/directUrlHelpers.d.ts +3 -0
- package/dist/api/directUrlHelpers.d.ts.map +1 -0
- package/dist/api/directUrlHelpers.js +25 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -0
- package/dist/api/vitest/CedarApiVitestEnv.d.ts.map +1 -1
- package/dist/api/vitest/CedarApiVitestEnv.js +15 -5
- package/dist/api/vitest/vitest-api.setup.js +7 -5
- package/dist/cjs/api/directUrlHelpers.d.ts +3 -0
- package/dist/cjs/api/directUrlHelpers.d.ts.map +1 -0
- package/dist/cjs/api/directUrlHelpers.js +60 -0
- package/dist/cjs/api/index.d.ts +1 -0
- package/dist/cjs/api/index.d.ts.map +1 -1
- package/dist/cjs/api/index.js +3 -1
- package/dist/cjs/api/vitest/CedarApiVitestEnv.js +14 -4
- package/dist/cjs/api/vitest/vitest-api.setup.js +6 -4
- package/dist/cjs/config/jest/api/globalSetup.d.ts.map +1 -1
- package/dist/cjs/config/jest/api/globalSetup.js +18 -6
- package/dist/cjs/config/jest/api/jest-preset.d.ts.map +1 -1
- package/dist/cjs/config/jest/api/jest-preset.js +6 -7
- package/dist/cjs/config/jest/api/jest.setup.js +12 -8
- package/dist/config/jest/api/globalSetup.d.ts.map +1 -1
- package/dist/config/jest/api/globalSetup.js +22 -7
- package/dist/config/jest/api/jest-preset.d.ts.map +1 -1
- package/dist/config/jest/api/jest-preset.js +6 -7
- package/dist/config/jest/api/jest.setup.js +12 -8
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalSetup.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/globalSetup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"globalSetup.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/globalSetup.ts"],"names":[],"mappings":"AACA,OAAO,wBAAwB,CAAA;AAc/B,0CAuCC"}
|
|
@@ -31,21 +31,33 @@ __export(globalSetup_exports, {
|
|
|
31
31
|
default: () => globalSetup_default
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(globalSetup_exports);
|
|
34
|
-
var
|
|
34
|
+
var import_internals = __toESM(require("@prisma/internals"), 1);
|
|
35
35
|
var import_config = require("dotenv-defaults/config");
|
|
36
36
|
var import_execa = __toESM(require("execa"), 1);
|
|
37
37
|
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
var import_directUrlHelpers = require("@cedarjs/testing/dist/cjs/api/directUrlHelpers.js");
|
|
39
|
+
const { getSchemaWithPath } = import_internals.default;
|
|
40
|
+
const rwjsPaths = (0, import_project_config.getPaths)();
|
|
38
41
|
async function globalSetup_default() {
|
|
39
42
|
if (process.env.SKIP_DB_PUSH === "1") {
|
|
40
43
|
return;
|
|
41
44
|
}
|
|
42
|
-
const
|
|
43
|
-
const defaultDb = `file:${import_node_path.default.join(cedarPaths.base, ".redwood", "test.db")}`;
|
|
45
|
+
const defaultDb = (0, import_directUrlHelpers.getDefaultDb)(rwjsPaths.base);
|
|
44
46
|
process.env.DATABASE_URL = process.env.TEST_DATABASE_URL || defaultDb;
|
|
45
|
-
const
|
|
47
|
+
const schemaPath = await (0, import_project_config.getSchemaPath)(rwjsPaths.api.prismaConfig);
|
|
48
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
49
|
+
const prismaSchema = result.schemas.map(([, content]) => content).join("\n");
|
|
50
|
+
const directUrlEnvVar = (0, import_directUrlHelpers.checkAndReplaceDirectUrl)(prismaSchema, defaultDb);
|
|
51
|
+
const command = process.env.TEST_DATABASE_STRATEGY === "reset" ? ["prisma", "migrate", "reset", "--force", "--skip-seed"] : ["prisma", "db", "push", "--force-reset", "--accept-data-loss"];
|
|
52
|
+
const env = {
|
|
53
|
+
DATABASE_URL: process.env.DATABASE_URL
|
|
54
|
+
};
|
|
55
|
+
if (directUrlEnvVar) {
|
|
56
|
+
env[directUrlEnvVar] = process.env[directUrlEnvVar];
|
|
57
|
+
}
|
|
46
58
|
import_execa.default.sync("yarn", ["cedar", ...command], {
|
|
47
|
-
cwd:
|
|
59
|
+
cwd: rwjsPaths.api.base,
|
|
48
60
|
stdio: "inherit",
|
|
49
|
-
env
|
|
61
|
+
env
|
|
50
62
|
});
|
|
51
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AASlC,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AASlC,QAAA,MAAM,MAAM,EAAE,MAyDb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -45,21 +45,22 @@ const config = {
|
|
|
45
45
|
runner: import_node_path.default.join(__dirname, "../jest-serial-runner.js"),
|
|
46
46
|
testEnvironment: import_node_path.default.join(__dirname, "./RedwoodApiJestEnv.js"),
|
|
47
47
|
globals: {
|
|
48
|
-
|
|
48
|
+
__RWJS__TEST_IMPORTS: {
|
|
49
49
|
apiSrcPath: rwjsPaths.api.src,
|
|
50
50
|
tearDownCachePath: import_node_path.default.join(
|
|
51
51
|
rwjsPaths.generated.base,
|
|
52
52
|
"scenarioTeardown.json"
|
|
53
|
-
)
|
|
53
|
+
),
|
|
54
|
+
prismaConfigPath: rwjsPaths.api.prismaConfig
|
|
54
55
|
}
|
|
55
56
|
},
|
|
56
|
-
sandboxInjectedGlobals: ["
|
|
57
|
+
sandboxInjectedGlobals: ["__RWJS__TEST_IMPORTS"],
|
|
57
58
|
displayName: {
|
|
58
59
|
color: "redBright",
|
|
59
60
|
name: "api"
|
|
60
61
|
},
|
|
61
62
|
collectCoverageFrom: [
|
|
62
|
-
"**/*.{js,jsx,ts,tsx
|
|
63
|
+
"**/*.{js,jsx,ts,tsx}",
|
|
63
64
|
"!**/node_modules/**",
|
|
64
65
|
"!**/dist/**"
|
|
65
66
|
],
|
|
@@ -73,8 +74,6 @@ const config = {
|
|
|
73
74
|
// Note this setup runs for each test file!
|
|
74
75
|
setupFilesAfterEnv: [import_node_path.default.join(__dirname, "./jest.setup.js")],
|
|
75
76
|
moduleNameMapper: {
|
|
76
|
-
"^api/(.*)$": import_node_path.default.join(rwjsPaths.base, "api/$1"),
|
|
77
|
-
"^src/(.*)$": import_node_path.default.join(rwjsPaths.api.src, "$1"),
|
|
78
77
|
// @NOTE: Import @cedarjs/testing in api tests, and it automatically remaps to the api side only
|
|
79
78
|
// This is to prevent web stuff leaking into api, and vice versa
|
|
80
79
|
"^@cedarjs/testing$": import_node_path.default.join(NODE_MODULES_PATH, "@cedarjs/testing/api"),
|
|
@@ -82,7 +81,7 @@ const config = {
|
|
|
82
81
|
"^(\\.{1,2}/.*)\\.js$": "$1"
|
|
83
82
|
},
|
|
84
83
|
transform: {
|
|
85
|
-
"\\.[
|
|
84
|
+
"\\.[jt]sx?$": [
|
|
86
85
|
"babel-jest",
|
|
87
86
|
// When jest runs tests in parallel, it serializes the config before passing down options to babel
|
|
88
87
|
// that's why these must be serializable. So ideally, we should just pass reference to a
|
|
@@ -24,7 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
25
25
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
26
26
|
var import_scenario = require("@cedarjs/testing/dist/cjs/api/scenario.js");
|
|
27
|
-
const { apiSrcPath, tearDownCachePath } = global.
|
|
27
|
+
const { apiSrcPath, tearDownCachePath, prismaConfigPath } = global.__RWJS__TEST_IMPORTS;
|
|
28
28
|
global.defineScenario = import_scenario.defineScenario;
|
|
29
29
|
const mockContextStore = /* @__PURE__ */ new Map();
|
|
30
30
|
const mockContext = new Proxy(
|
|
@@ -58,9 +58,10 @@ const isIdenticalArray = (a, b) => {
|
|
|
58
58
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
59
59
|
};
|
|
60
60
|
const configureTeardown = async () => {
|
|
61
|
-
const { getDMMF } = require("@prisma/internals");
|
|
62
|
-
const {
|
|
63
|
-
const
|
|
61
|
+
const { getDMMF, getSchemaWithPath } = require("@prisma/internals");
|
|
62
|
+
const { getSchemaPath } = require("@cedarjs/project-config");
|
|
63
|
+
const schemaPath = await getSchemaPath(prismaConfigPath);
|
|
64
|
+
const { schemas } = await getSchemaWithPath(schemaPath);
|
|
64
65
|
const schema = await getDMMF({ datamodel: schemas });
|
|
65
66
|
const schemaModels = schema.datamodel.models.map(
|
|
66
67
|
(m) => m.dbName || m.name
|
|
@@ -75,11 +76,14 @@ const configureTeardown = async () => {
|
|
|
75
76
|
};
|
|
76
77
|
let quoteStyle;
|
|
77
78
|
const getQuoteStyle = async () => {
|
|
78
|
-
const { getConfig: getPrismaConfig } = require("@prisma/internals");
|
|
79
|
-
const {
|
|
80
|
-
const
|
|
79
|
+
const { getConfig: getPrismaConfig, getSchemaWithPath } = require("@prisma/internals");
|
|
80
|
+
const { getSchemaPath } = require("@cedarjs/project-config");
|
|
81
|
+
const schemaPath = await getSchemaPath(prismaConfigPath);
|
|
82
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
81
83
|
if (!quoteStyle) {
|
|
82
|
-
const config = await getPrismaConfig({
|
|
84
|
+
const config = await getPrismaConfig({
|
|
85
|
+
datamodel: result.schemas
|
|
86
|
+
});
|
|
83
87
|
switch (config.datasources?.[0]?.provider) {
|
|
84
88
|
case "mysql":
|
|
85
89
|
quoteStyle = "`";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directUrlHelpers.d.ts","sourceRoot":"","sources":["../../src/api/directUrlHelpers.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,cAAc,EAAE,MAAM,UAElD;AAED,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,sBA+BlB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
function getDefaultDb(projectBaseDir) {
|
|
3
|
+
return `file:${path.join(projectBaseDir, ".redwood", "test.db")}`;
|
|
4
|
+
}
|
|
5
|
+
function checkAndReplaceDirectUrl(prismaSchema, defaultDb) {
|
|
6
|
+
const directUrl = prismaSchema.match(PRISMA_DIRECT_URL_REGEXP);
|
|
7
|
+
if (!directUrl) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const directUrlEnvMatch = directUrl[0].match(BETWEEN_PARENTHESES_REGEXP);
|
|
11
|
+
if (!directUrlEnvMatch) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
"Error parsing `directUrl` from schema.prisma. Proceeding with this env var could be dangerous. Please check your schema.prisma file; if everything looks ok, file an issue."
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const directUrlEnv = directUrlEnvMatch[2];
|
|
17
|
+
process.env[directUrlEnv] = process.env.TEST_DIRECT_URL || process.env.TEST_DATABASE_URL || defaultDb;
|
|
18
|
+
return directUrlEnv;
|
|
19
|
+
}
|
|
20
|
+
const PRISMA_DIRECT_URL_REGEXP = /directUrl(\s*)=(\s*)env\(('|")(.*)('|")\)/g;
|
|
21
|
+
const BETWEEN_PARENTHESES_REGEXP = /\(('|")([^)]+)('|")\)/;
|
|
22
|
+
export {
|
|
23
|
+
checkAndReplaceDirectUrl,
|
|
24
|
+
getDefaultDb
|
|
25
|
+
};
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,uBAAuB,CAAA"}
|
package/dist/api/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CedarApiVitestEnv.d.ts","sourceRoot":"","sources":["../../../src/api/vitest/CedarApiVitestEnv.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CedarApiVitestEnv.d.ts","sourceRoot":"","sources":["../../../src/api/vitest/CedarApiVitestEnv.ts"],"names":[],"mappings":"AACA,OAAO,2BAA2B,CAAA;AAElC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAQtD,QAAA,MAAM,yBAAyB,EAAE,WAkDhC,CAAA;AAED,eAAe,yBAAyB,CAAA"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import prismaInternals from "@prisma/internals";
|
|
2
2
|
import "dotenv-defaults/config.js";
|
|
3
3
|
import execa from "execa";
|
|
4
|
-
import { getPaths } from "@cedarjs/project-config";
|
|
4
|
+
import { getPaths, getSchemaPath } from "@cedarjs/project-config";
|
|
5
|
+
import { getDefaultDb, checkAndReplaceDirectUrl } from "../directUrlHelpers.js";
|
|
6
|
+
const { getSchemaWithPath } = prismaInternals;
|
|
5
7
|
const CedarApiVitestEnvironment = {
|
|
6
8
|
name: "cedar-api",
|
|
7
9
|
transformMode: "ssr",
|
|
@@ -13,13 +15,21 @@ const CedarApiVitestEnvironment = {
|
|
|
13
15
|
};
|
|
14
16
|
}
|
|
15
17
|
const cedarPaths = getPaths();
|
|
16
|
-
const defaultDb =
|
|
18
|
+
const defaultDb = getDefaultDb(cedarPaths.base);
|
|
17
19
|
process.env.DATABASE_URL = process.env.TEST_DATABASE_URL || defaultDb;
|
|
18
|
-
const
|
|
20
|
+
const schemaPath = await getSchemaPath(cedarPaths.api.prismaConfig);
|
|
21
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
22
|
+
const prismaSchema = result.schemas.map(([, content]) => content).join("\n");
|
|
23
|
+
const directUrlEnvVar = checkAndReplaceDirectUrl(prismaSchema, defaultDb);
|
|
24
|
+
const command = process.env.TEST_DATABASE_STRATEGY === "reset" ? ["prisma", "migrate", "reset", "--force", "--skip-seed"] : ["prisma", "db", "push", "--force-reset", "--accept-data-loss"];
|
|
25
|
+
const directUrlDefinition = directUrlEnvVar ? { [directUrlEnvVar]: process.env[directUrlEnvVar] } : {};
|
|
19
26
|
execa.sync("yarn", ["cedar", ...command], {
|
|
20
27
|
cwd: cedarPaths.api.base,
|
|
21
28
|
stdio: "inherit",
|
|
22
|
-
env:
|
|
29
|
+
env: {
|
|
30
|
+
DATABASE_URL: process.env.DATABASE_URL,
|
|
31
|
+
...directUrlDefinition
|
|
32
|
+
}
|
|
23
33
|
});
|
|
24
34
|
return {
|
|
25
35
|
teardown() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { afterAll, beforeEach, it, describe, vi, beforeAll } from "vitest";
|
|
4
|
-
import { getPaths,
|
|
4
|
+
import { getPaths, getSchemaPath } from "@cedarjs/project-config";
|
|
5
5
|
import { defineScenario } from "@cedarjs/testing/api";
|
|
6
6
|
const mockContextStore = vi.hoisted(() => /* @__PURE__ */ new Map());
|
|
7
7
|
const mockContext = vi.hoisted(
|
|
@@ -106,8 +106,9 @@ async function configureTeardown() {
|
|
|
106
106
|
if (!wasDbImported()) {
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
|
-
const { getDMMF } = await import("@prisma/internals");
|
|
110
|
-
const
|
|
109
|
+
const { getDMMF, getSchemaWithPath } = await import("@prisma/internals");
|
|
110
|
+
const schemaPath = await getSchemaPath(cedarPaths.api.prismaConfig);
|
|
111
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
111
112
|
const schema = await getDMMF({ datamodel: result.schemas });
|
|
112
113
|
const schemaModels = schema.datamodel.models.map((m) => {
|
|
113
114
|
return m.dbName || m.name;
|
|
@@ -209,8 +210,9 @@ const wasDbImported = () => {
|
|
|
209
210
|
};
|
|
210
211
|
let quoteStyle;
|
|
211
212
|
async function getQuoteStyle() {
|
|
212
|
-
const { getConfig: getPrismaConfig } = await import("@prisma/internals");
|
|
213
|
-
const
|
|
213
|
+
const { getConfig: getPrismaConfig, getSchemaWithPath } = await import("@prisma/internals");
|
|
214
|
+
const schemaPath = await getSchemaPath(cedarPaths.api.prismaConfig);
|
|
215
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
214
216
|
if (!quoteStyle) {
|
|
215
217
|
const config = await getPrismaConfig({
|
|
216
218
|
datamodel: result.schemas
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directUrlHelpers.d.ts","sourceRoot":"","sources":["../../../src/api/directUrlHelpers.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,cAAc,EAAE,MAAM,UAElD;AAED,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,sBA+BlB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 directUrlHelpers_exports = {};
|
|
30
|
+
__export(directUrlHelpers_exports, {
|
|
31
|
+
checkAndReplaceDirectUrl: () => checkAndReplaceDirectUrl,
|
|
32
|
+
getDefaultDb: () => getDefaultDb
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(directUrlHelpers_exports);
|
|
35
|
+
var import_path = __toESM(require("path"), 1);
|
|
36
|
+
function getDefaultDb(projectBaseDir) {
|
|
37
|
+
return `file:${import_path.default.join(projectBaseDir, ".redwood", "test.db")}`;
|
|
38
|
+
}
|
|
39
|
+
function checkAndReplaceDirectUrl(prismaSchema, defaultDb) {
|
|
40
|
+
const directUrl = prismaSchema.match(PRISMA_DIRECT_URL_REGEXP);
|
|
41
|
+
if (!directUrl) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const directUrlEnvMatch = directUrl[0].match(BETWEEN_PARENTHESES_REGEXP);
|
|
45
|
+
if (!directUrlEnvMatch) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
"Error parsing `directUrl` from schema.prisma. Proceeding with this env var could be dangerous. Please check your schema.prisma file; if everything looks ok, file an issue."
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const directUrlEnv = directUrlEnvMatch[2];
|
|
51
|
+
process.env[directUrlEnv] = process.env.TEST_DIRECT_URL || process.env.TEST_DATABASE_URL || defaultDb;
|
|
52
|
+
return directUrlEnv;
|
|
53
|
+
}
|
|
54
|
+
const PRISMA_DIRECT_URL_REGEXP = /directUrl(\s*)=(\s*)env\(('|")(.*)('|")\)/g;
|
|
55
|
+
const BETWEEN_PARENTHESES_REGEXP = /\(('|")([^)]+)('|")\)/;
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
checkAndReplaceDirectUrl,
|
|
59
|
+
getDefaultDb
|
|
60
|
+
});
|
package/dist/cjs/api/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,uBAAuB,CAAA"}
|
package/dist/cjs/api/index.js
CHANGED
|
@@ -18,9 +18,11 @@ module.exports = __toCommonJS(api_exports);
|
|
|
18
18
|
__reExport(api_exports, require("./apiFunction.js"), module.exports);
|
|
19
19
|
__reExport(api_exports, require("./scenario.js"), module.exports);
|
|
20
20
|
__reExport(api_exports, require("./directive.js"), module.exports);
|
|
21
|
+
__reExport(api_exports, require("./directUrlHelpers.js"), module.exports);
|
|
21
22
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
23
|
0 && (module.exports = {
|
|
23
24
|
...require("./apiFunction.js"),
|
|
24
25
|
...require("./scenario.js"),
|
|
25
|
-
...require("./directive.js")
|
|
26
|
+
...require("./directive.js"),
|
|
27
|
+
...require("./directUrlHelpers.js")
|
|
26
28
|
});
|
|
@@ -31,10 +31,12 @@ __export(CedarApiVitestEnv_exports, {
|
|
|
31
31
|
default: () => CedarApiVitestEnv_default
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(CedarApiVitestEnv_exports);
|
|
34
|
-
var
|
|
34
|
+
var import_internals = __toESM(require("@prisma/internals"), 1);
|
|
35
35
|
var import_config = require("dotenv-defaults/config.js");
|
|
36
36
|
var import_execa = __toESM(require("execa"), 1);
|
|
37
37
|
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
var import_directUrlHelpers = require("../directUrlHelpers.js");
|
|
39
|
+
const { getSchemaWithPath } = import_internals.default;
|
|
38
40
|
const CedarApiVitestEnvironment = {
|
|
39
41
|
name: "cedar-api",
|
|
40
42
|
transformMode: "ssr",
|
|
@@ -46,13 +48,21 @@ const CedarApiVitestEnvironment = {
|
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
const cedarPaths = (0, import_project_config.getPaths)();
|
|
49
|
-
const defaultDb =
|
|
51
|
+
const defaultDb = (0, import_directUrlHelpers.getDefaultDb)(cedarPaths.base);
|
|
50
52
|
process.env.DATABASE_URL = process.env.TEST_DATABASE_URL || defaultDb;
|
|
51
|
-
const
|
|
53
|
+
const schemaPath = await (0, import_project_config.getSchemaPath)(cedarPaths.api.prismaConfig);
|
|
54
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
55
|
+
const prismaSchema = result.schemas.map(([, content]) => content).join("\n");
|
|
56
|
+
const directUrlEnvVar = (0, import_directUrlHelpers.checkAndReplaceDirectUrl)(prismaSchema, defaultDb);
|
|
57
|
+
const command = process.env.TEST_DATABASE_STRATEGY === "reset" ? ["prisma", "migrate", "reset", "--force", "--skip-seed"] : ["prisma", "db", "push", "--force-reset", "--accept-data-loss"];
|
|
58
|
+
const directUrlDefinition = directUrlEnvVar ? { [directUrlEnvVar]: process.env[directUrlEnvVar] } : {};
|
|
52
59
|
import_execa.default.sync("yarn", ["cedar", ...command], {
|
|
53
60
|
cwd: cedarPaths.api.base,
|
|
54
61
|
stdio: "inherit",
|
|
55
|
-
env:
|
|
62
|
+
env: {
|
|
63
|
+
DATABASE_URL: process.env.DATABASE_URL,
|
|
64
|
+
...directUrlDefinition
|
|
65
|
+
}
|
|
56
66
|
});
|
|
57
67
|
return {
|
|
58
68
|
teardown() {
|
|
@@ -129,8 +129,9 @@ async function configureTeardown() {
|
|
|
129
129
|
if (!wasDbImported()) {
|
|
130
130
|
return;
|
|
131
131
|
}
|
|
132
|
-
const { getDMMF } = await import("@prisma/internals");
|
|
133
|
-
const
|
|
132
|
+
const { getDMMF, getSchemaWithPath } = await import("@prisma/internals");
|
|
133
|
+
const schemaPath = await (0, import_project_config.getSchemaPath)(cedarPaths.api.prismaConfig);
|
|
134
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
134
135
|
const schema = await getDMMF({ datamodel: result.schemas });
|
|
135
136
|
const schemaModels = schema.datamodel.models.map((m) => {
|
|
136
137
|
return m.dbName || m.name;
|
|
@@ -232,8 +233,9 @@ const wasDbImported = () => {
|
|
|
232
233
|
};
|
|
233
234
|
let quoteStyle;
|
|
234
235
|
async function getQuoteStyle() {
|
|
235
|
-
const { getConfig: getPrismaConfig } = await import("@prisma/internals");
|
|
236
|
-
const
|
|
236
|
+
const { getConfig: getPrismaConfig, getSchemaWithPath } = await import("@prisma/internals");
|
|
237
|
+
const schemaPath = await (0, import_project_config.getSchemaPath)(cedarPaths.api.prismaConfig);
|
|
238
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
237
239
|
if (!quoteStyle) {
|
|
238
240
|
const config = await getPrismaConfig({
|
|
239
241
|
datamodel: result.schemas
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalSetup.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/globalSetup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"globalSetup.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/globalSetup.ts"],"names":[],"mappings":"AACA,OAAO,wBAAwB,CAAA;AAc/B,0CAuCC"}
|
|
@@ -31,21 +31,33 @@ __export(globalSetup_exports, {
|
|
|
31
31
|
default: () => globalSetup_default
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(globalSetup_exports);
|
|
34
|
-
var
|
|
34
|
+
var import_internals = __toESM(require("@prisma/internals"), 1);
|
|
35
35
|
var import_config = require("dotenv-defaults/config");
|
|
36
36
|
var import_execa = __toESM(require("execa"), 1);
|
|
37
37
|
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
var import_directUrlHelpers = require("../../../api/directUrlHelpers.js");
|
|
39
|
+
const { getSchemaWithPath } = import_internals.default;
|
|
40
|
+
const rwjsPaths = (0, import_project_config.getPaths)();
|
|
38
41
|
async function globalSetup_default() {
|
|
39
42
|
if (process.env.SKIP_DB_PUSH === "1") {
|
|
40
43
|
return;
|
|
41
44
|
}
|
|
42
|
-
const
|
|
43
|
-
const defaultDb = `file:${import_node_path.default.join(cedarPaths.base, ".redwood", "test.db")}`;
|
|
45
|
+
const defaultDb = (0, import_directUrlHelpers.getDefaultDb)(rwjsPaths.base);
|
|
44
46
|
process.env.DATABASE_URL = process.env.TEST_DATABASE_URL || defaultDb;
|
|
45
|
-
const
|
|
47
|
+
const schemaPath = await (0, import_project_config.getSchemaPath)(rwjsPaths.api.prismaConfig);
|
|
48
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
49
|
+
const prismaSchema = result.schemas.map(([, content]) => content).join("\n");
|
|
50
|
+
const directUrlEnvVar = (0, import_directUrlHelpers.checkAndReplaceDirectUrl)(prismaSchema, defaultDb);
|
|
51
|
+
const command = process.env.TEST_DATABASE_STRATEGY === "reset" ? ["prisma", "migrate", "reset", "--force", "--skip-seed"] : ["prisma", "db", "push", "--force-reset", "--accept-data-loss"];
|
|
52
|
+
const env = {
|
|
53
|
+
DATABASE_URL: process.env.DATABASE_URL
|
|
54
|
+
};
|
|
55
|
+
if (directUrlEnvVar) {
|
|
56
|
+
env[directUrlEnvVar] = process.env[directUrlEnvVar];
|
|
57
|
+
}
|
|
46
58
|
import_execa.default.sync("yarn", ["cedar", ...command], {
|
|
47
|
-
cwd:
|
|
59
|
+
cwd: rwjsPaths.api.base,
|
|
48
60
|
stdio: "inherit",
|
|
49
|
-
env
|
|
61
|
+
env
|
|
50
62
|
});
|
|
51
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AASlC,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AASlC,QAAA,MAAM,MAAM,EAAE,MAyDb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -45,21 +45,22 @@ const config = {
|
|
|
45
45
|
runner: import_node_path.default.join(__dirname, "../jest-serial-runner.js"),
|
|
46
46
|
testEnvironment: import_node_path.default.join(__dirname, "./RedwoodApiJestEnv.js"),
|
|
47
47
|
globals: {
|
|
48
|
-
|
|
48
|
+
__RWJS__TEST_IMPORTS: {
|
|
49
49
|
apiSrcPath: rwjsPaths.api.src,
|
|
50
50
|
tearDownCachePath: import_node_path.default.join(
|
|
51
51
|
rwjsPaths.generated.base,
|
|
52
52
|
"scenarioTeardown.json"
|
|
53
|
-
)
|
|
53
|
+
),
|
|
54
|
+
prismaConfigPath: rwjsPaths.api.prismaConfig
|
|
54
55
|
}
|
|
55
56
|
},
|
|
56
|
-
sandboxInjectedGlobals: ["
|
|
57
|
+
sandboxInjectedGlobals: ["__RWJS__TEST_IMPORTS"],
|
|
57
58
|
displayName: {
|
|
58
59
|
color: "redBright",
|
|
59
60
|
name: "api"
|
|
60
61
|
},
|
|
61
62
|
collectCoverageFrom: [
|
|
62
|
-
"**/*.{js,jsx,ts,tsx
|
|
63
|
+
"**/*.{js,jsx,ts,tsx}",
|
|
63
64
|
"!**/node_modules/**",
|
|
64
65
|
"!**/dist/**"
|
|
65
66
|
],
|
|
@@ -73,8 +74,6 @@ const config = {
|
|
|
73
74
|
// Note this setup runs for each test file!
|
|
74
75
|
setupFilesAfterEnv: [import_node_path.default.join(__dirname, "./jest.setup.js")],
|
|
75
76
|
moduleNameMapper: {
|
|
76
|
-
"^api/(.*)$": import_node_path.default.join(rwjsPaths.base, "api/$1"),
|
|
77
|
-
"^src/(.*)$": import_node_path.default.join(rwjsPaths.api.src, "$1"),
|
|
78
77
|
// @NOTE: Import @cedarjs/testing in api tests, and it automatically remaps to the api side only
|
|
79
78
|
// This is to prevent web stuff leaking into api, and vice versa
|
|
80
79
|
"^@cedarjs/testing$": import_node_path.default.join(NODE_MODULES_PATH, "@cedarjs/testing/api"),
|
|
@@ -82,7 +81,7 @@ const config = {
|
|
|
82
81
|
"^(\\.{1,2}/.*)\\.js$": "$1"
|
|
83
82
|
},
|
|
84
83
|
transform: {
|
|
85
|
-
"\\.[
|
|
84
|
+
"\\.[jt]sx?$": [
|
|
86
85
|
"babel-jest",
|
|
87
86
|
// When jest runs tests in parallel, it serializes the config before passing down options to babel
|
|
88
87
|
// that's why these must be serializable. So ideally, we should just pass reference to a
|
|
@@ -24,7 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
25
25
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
26
26
|
var import_scenario = require("../../../api/scenario.js");
|
|
27
|
-
const { apiSrcPath, tearDownCachePath } = global.
|
|
27
|
+
const { apiSrcPath, tearDownCachePath, prismaConfigPath } = global.__RWJS__TEST_IMPORTS;
|
|
28
28
|
global.defineScenario = import_scenario.defineScenario;
|
|
29
29
|
const mockContextStore = /* @__PURE__ */ new Map();
|
|
30
30
|
const mockContext = new Proxy(
|
|
@@ -58,9 +58,10 @@ const isIdenticalArray = (a, b) => {
|
|
|
58
58
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
59
59
|
};
|
|
60
60
|
const configureTeardown = async () => {
|
|
61
|
-
const { getDMMF } = await import("@prisma/internals");
|
|
62
|
-
const {
|
|
63
|
-
const
|
|
61
|
+
const { getDMMF, getSchemaWithPath } = await import("@prisma/internals");
|
|
62
|
+
const { getSchemaPath } = await import("@cedarjs/project-config");
|
|
63
|
+
const schemaPath = await getSchemaPath(prismaConfigPath);
|
|
64
|
+
const { schemas } = await getSchemaWithPath(schemaPath);
|
|
64
65
|
const schema = await getDMMF({ datamodel: schemas });
|
|
65
66
|
const schemaModels = schema.datamodel.models.map(
|
|
66
67
|
(m) => m.dbName || m.name
|
|
@@ -75,11 +76,14 @@ const configureTeardown = async () => {
|
|
|
75
76
|
};
|
|
76
77
|
let quoteStyle;
|
|
77
78
|
const getQuoteStyle = async () => {
|
|
78
|
-
const { getConfig: getPrismaConfig } = await import("@prisma/internals");
|
|
79
|
-
const {
|
|
80
|
-
const
|
|
79
|
+
const { getConfig: getPrismaConfig, getSchemaWithPath } = await import("@prisma/internals");
|
|
80
|
+
const { getSchemaPath } = await import("@cedarjs/project-config");
|
|
81
|
+
const schemaPath = await getSchemaPath(prismaConfigPath);
|
|
82
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
81
83
|
if (!quoteStyle) {
|
|
82
|
-
const config = await getPrismaConfig({
|
|
84
|
+
const config = await getPrismaConfig({
|
|
85
|
+
datamodel: result.schemas
|
|
86
|
+
});
|
|
83
87
|
switch (config.datasources?.[0]?.provider) {
|
|
84
88
|
case "mysql":
|
|
85
89
|
quoteStyle = "`";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalSetup.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/api/globalSetup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"globalSetup.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/api/globalSetup.ts"],"names":[],"mappings":"AACA,OAAO,wBAAwB,CAAA;AAc/B,0CAuCC"}
|
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import prismaInternals from "@prisma/internals";
|
|
2
2
|
import "dotenv-defaults/config";
|
|
3
3
|
import execa from "execa";
|
|
4
|
-
import { getPaths } from "@cedarjs/project-config";
|
|
4
|
+
import { getPaths, getSchemaPath } from "@cedarjs/project-config";
|
|
5
|
+
import {
|
|
6
|
+
getDefaultDb,
|
|
7
|
+
checkAndReplaceDirectUrl
|
|
8
|
+
} from "../../../api/directUrlHelpers.js";
|
|
9
|
+
const { getSchemaWithPath } = prismaInternals;
|
|
10
|
+
const rwjsPaths = getPaths();
|
|
5
11
|
async function globalSetup_default() {
|
|
6
12
|
if (process.env.SKIP_DB_PUSH === "1") {
|
|
7
13
|
return;
|
|
8
14
|
}
|
|
9
|
-
const
|
|
10
|
-
const defaultDb = `file:${path.join(cedarPaths.base, ".redwood", "test.db")}`;
|
|
15
|
+
const defaultDb = getDefaultDb(rwjsPaths.base);
|
|
11
16
|
process.env.DATABASE_URL = process.env.TEST_DATABASE_URL || defaultDb;
|
|
12
|
-
const
|
|
17
|
+
const schemaPath = await getSchemaPath(rwjsPaths.api.prismaConfig);
|
|
18
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
19
|
+
const prismaSchema = result.schemas.map(([, content]) => content).join("\n");
|
|
20
|
+
const directUrlEnvVar = checkAndReplaceDirectUrl(prismaSchema, defaultDb);
|
|
21
|
+
const command = process.env.TEST_DATABASE_STRATEGY === "reset" ? ["prisma", "migrate", "reset", "--force", "--skip-seed"] : ["prisma", "db", "push", "--force-reset", "--accept-data-loss"];
|
|
22
|
+
const env = {
|
|
23
|
+
DATABASE_URL: process.env.DATABASE_URL
|
|
24
|
+
};
|
|
25
|
+
if (directUrlEnvVar) {
|
|
26
|
+
env[directUrlEnvVar] = process.env[directUrlEnvVar];
|
|
27
|
+
}
|
|
13
28
|
execa.sync("yarn", ["cedar", ...command], {
|
|
14
|
-
cwd:
|
|
29
|
+
cwd: rwjsPaths.api.base,
|
|
15
30
|
stdio: "inherit",
|
|
16
|
-
env
|
|
31
|
+
env
|
|
17
32
|
});
|
|
18
33
|
}
|
|
19
34
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AASlC,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AASlC,QAAA,MAAM,MAAM,EAAE,MAyDb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -12,21 +12,22 @@ const config = {
|
|
|
12
12
|
runner: path.join(__dirname, "../jest-serial-runner.js"),
|
|
13
13
|
testEnvironment: path.join(__dirname, "./RedwoodApiJestEnv.js"),
|
|
14
14
|
globals: {
|
|
15
|
-
|
|
15
|
+
__RWJS__TEST_IMPORTS: {
|
|
16
16
|
apiSrcPath: rwjsPaths.api.src,
|
|
17
17
|
tearDownCachePath: path.join(
|
|
18
18
|
rwjsPaths.generated.base,
|
|
19
19
|
"scenarioTeardown.json"
|
|
20
|
-
)
|
|
20
|
+
),
|
|
21
|
+
prismaConfigPath: rwjsPaths.api.prismaConfig
|
|
21
22
|
}
|
|
22
23
|
},
|
|
23
|
-
sandboxInjectedGlobals: ["
|
|
24
|
+
sandboxInjectedGlobals: ["__RWJS__TEST_IMPORTS"],
|
|
24
25
|
displayName: {
|
|
25
26
|
color: "redBright",
|
|
26
27
|
name: "api"
|
|
27
28
|
},
|
|
28
29
|
collectCoverageFrom: [
|
|
29
|
-
"**/*.{js,jsx,ts,tsx
|
|
30
|
+
"**/*.{js,jsx,ts,tsx}",
|
|
30
31
|
"!**/node_modules/**",
|
|
31
32
|
"!**/dist/**"
|
|
32
33
|
],
|
|
@@ -40,8 +41,6 @@ const config = {
|
|
|
40
41
|
// Note this setup runs for each test file!
|
|
41
42
|
setupFilesAfterEnv: [path.join(__dirname, "./jest.setup.js")],
|
|
42
43
|
moduleNameMapper: {
|
|
43
|
-
"^api/(.*)$": path.join(rwjsPaths.base, "api/$1"),
|
|
44
|
-
"^src/(.*)$": path.join(rwjsPaths.api.src, "$1"),
|
|
45
44
|
// @NOTE: Import @cedarjs/testing in api tests, and it automatically remaps to the api side only
|
|
46
45
|
// This is to prevent web stuff leaking into api, and vice versa
|
|
47
46
|
"^@cedarjs/testing$": path.join(NODE_MODULES_PATH, "@cedarjs/testing/api"),
|
|
@@ -49,7 +48,7 @@ const config = {
|
|
|
49
48
|
"^(\\.{1,2}/.*)\\.js$": "$1"
|
|
50
49
|
},
|
|
51
50
|
transform: {
|
|
52
|
-
"\\.[
|
|
51
|
+
"\\.[jt]sx?$": [
|
|
53
52
|
"babel-jest",
|
|
54
53
|
// When jest runs tests in parallel, it serializes the config before passing down options to babel
|
|
55
54
|
// that's why these must be serializable. So ideally, we should just pass reference to a
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { defineScenario } from "../../../api/scenario.js";
|
|
4
|
-
const { apiSrcPath, tearDownCachePath } = global.
|
|
4
|
+
const { apiSrcPath, tearDownCachePath, prismaConfigPath } = global.__RWJS__TEST_IMPORTS;
|
|
5
5
|
global.defineScenario = defineScenario;
|
|
6
6
|
const mockContextStore = /* @__PURE__ */ new Map();
|
|
7
7
|
const mockContext = new Proxy(
|
|
@@ -35,9 +35,10 @@ const isIdenticalArray = (a, b) => {
|
|
|
35
35
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
36
36
|
};
|
|
37
37
|
const configureTeardown = async () => {
|
|
38
|
-
const { getDMMF } = await import("@prisma/internals");
|
|
39
|
-
const {
|
|
40
|
-
const
|
|
38
|
+
const { getDMMF, getSchemaWithPath } = await import("@prisma/internals");
|
|
39
|
+
const { getSchemaPath } = await import("@cedarjs/project-config");
|
|
40
|
+
const schemaPath = await getSchemaPath(prismaConfigPath);
|
|
41
|
+
const { schemas } = await getSchemaWithPath(schemaPath);
|
|
41
42
|
const schema = await getDMMF({ datamodel: schemas });
|
|
42
43
|
const schemaModels = schema.datamodel.models.map(
|
|
43
44
|
(m) => m.dbName || m.name
|
|
@@ -52,11 +53,14 @@ const configureTeardown = async () => {
|
|
|
52
53
|
};
|
|
53
54
|
let quoteStyle;
|
|
54
55
|
const getQuoteStyle = async () => {
|
|
55
|
-
const { getConfig: getPrismaConfig } = await import("@prisma/internals");
|
|
56
|
-
const {
|
|
57
|
-
const
|
|
56
|
+
const { getConfig: getPrismaConfig, getSchemaWithPath } = await import("@prisma/internals");
|
|
57
|
+
const { getSchemaPath } = await import("@cedarjs/project-config");
|
|
58
|
+
const schemaPath = await getSchemaPath(prismaConfigPath);
|
|
59
|
+
const result = await getSchemaWithPath(schemaPath);
|
|
58
60
|
if (!quoteStyle) {
|
|
59
|
-
const config = await getPrismaConfig({
|
|
61
|
+
const config = await getPrismaConfig({
|
|
62
|
+
datamodel: result.schemas
|
|
63
|
+
});
|
|
60
64
|
switch (config.datasources?.[0]?.provider) {
|
|
61
65
|
case "mysql":
|
|
62
66
|
quoteStyle = "`";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/testing",
|
|
3
|
-
"version": "2.8.1
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"description": "Tools, wrappers and configuration for testing a Cedar project.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -119,13 +119,13 @@
|
|
|
119
119
|
"test:watch": "vitest watch"
|
|
120
120
|
},
|
|
121
121
|
"dependencies": {
|
|
122
|
-
"@cedarjs/auth": "2.8.1
|
|
123
|
-
"@cedarjs/babel-config": "2.8.1
|
|
124
|
-
"@cedarjs/context": "2.8.1
|
|
125
|
-
"@cedarjs/graphql-server": "2.8.1
|
|
126
|
-
"@cedarjs/project-config": "2.8.1
|
|
127
|
-
"@cedarjs/router": "2.8.1
|
|
128
|
-
"@cedarjs/web": "2.8.1
|
|
122
|
+
"@cedarjs/auth": "2.8.1",
|
|
123
|
+
"@cedarjs/babel-config": "2.8.1",
|
|
124
|
+
"@cedarjs/context": "2.8.1",
|
|
125
|
+
"@cedarjs/graphql-server": "2.8.1",
|
|
126
|
+
"@cedarjs/project-config": "2.8.1",
|
|
127
|
+
"@cedarjs/router": "2.8.1",
|
|
128
|
+
"@cedarjs/web": "2.8.1",
|
|
129
129
|
"@testing-library/jest-dom": "6.9.1",
|
|
130
130
|
"@testing-library/react": "14.3.1",
|
|
131
131
|
"@testing-library/user-event": "14.6.1",
|
|
@@ -145,9 +145,9 @@
|
|
|
145
145
|
"whatwg-fetch": "3.6.20"
|
|
146
146
|
},
|
|
147
147
|
"devDependencies": {
|
|
148
|
-
"@cedarjs/framework-tools": "
|
|
148
|
+
"@cedarjs/framework-tools": "0.0.0",
|
|
149
149
|
"concurrently": "9.2.1",
|
|
150
|
-
"jsdom": "
|
|
150
|
+
"jsdom": "24.1.3",
|
|
151
151
|
"publint": "0.3.18",
|
|
152
152
|
"tsx": "4.21.0",
|
|
153
153
|
"typescript": "5.9.3",
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
"publishConfig": {
|
|
165
165
|
"access": "public"
|
|
166
166
|
},
|
|
167
|
-
"gitHead": "
|
|
167
|
+
"gitHead": "b1a808f72ff10c72375d0ff2c0be03631a1b79a2",
|
|
168
168
|
"nx": {
|
|
169
169
|
"targets": {
|
|
170
170
|
"build": {
|