@cedarjs/testing 0.6.1-next.0 → 0.6.1-next.51
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/RedwoodApiJestEnv.d.ts +11 -0
- package/config/jest/api/RedwoodApiJestEnv.d.ts.map +1 -0
- package/config/jest/api/RedwoodApiJestEnv.js +33 -16
- package/config/jest/api/apiBabelConfig.d.ts +5 -0
- package/config/jest/api/apiBabelConfig.d.ts.map +1 -0
- package/config/jest/api/apiBabelConfig.js +33 -17
- package/config/jest/api/globalSetup.d.ts +3 -0
- package/config/jest/api/globalSetup.d.ts.map +1 -0
- package/config/jest/api/globalSetup.js +59 -44
- package/config/jest/api/index.d.ts +3 -0
- package/config/jest/api/index.d.ts.map +1 -0
- package/config/jest/api/index.js +25 -2
- package/config/jest/api/jest-preset.d.ts +4 -0
- package/config/jest/api/jest-preset.d.ts.map +1 -0
- package/config/jest/api/jest-preset.js +69 -39
- package/config/jest/api/jest.setup.d.ts +2 -0
- package/config/jest/api/jest.setup.d.ts.map +1 -0
- package/config/jest/api/jest.setup.js +189 -248
- package/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts +11 -0
- package/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -0
- package/config/jest/babelPlugins/babel-plugin-redwood-cell.js +103 -124
- package/config/jest/jest-serial-runner.d.ts +8 -0
- package/config/jest/jest-serial-runner.d.ts.map +1 -0
- package/config/jest/jest-serial-runner.js +33 -9
- package/config/jest/web/RedwoodWebJestEnv.d.ts +6 -0
- package/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -0
- package/config/jest/web/RedwoodWebJestEnv.js +33 -12
- package/config/jest/web/index.d.ts +3 -0
- package/config/jest/web/index.d.ts.map +1 -0
- package/config/jest/web/index.js +25 -2
- package/config/jest/web/jest-preset.d.ts +4 -0
- package/config/jest/web/jest-preset.d.ts.map +1 -0
- package/config/jest/web/jest-preset.js +78 -50
- package/config/jest/web/jest.setup.d.ts +8 -0
- package/config/jest/web/jest.setup.d.ts.map +1 -0
- package/config/jest/web/jest.setup.js +17 -36
- package/config/jest/web/resolver.d.ts +4 -0
- package/config/jest/web/resolver.d.ts.map +1 -0
- package/config/jest/web/resolver.js +24 -31
- package/config/jest/web/webBabelConfig.d.ts +10 -0
- package/config/jest/web/webBabelConfig.d.ts.map +1 -0
- package/config/jest/web/webBabelConfig.js +43 -13
- package/config/package.json +1 -0
- package/dist/api/directUrlHelpers.d.ts.map +1 -1
- 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/cjs/api/directUrlHelpers.d.ts.map +1 -1
- 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/config/jest/api/RedwoodApiJestEnv.d.ts +11 -0
- package/dist/cjs/config/jest/api/RedwoodApiJestEnv.d.ts.map +1 -0
- package/dist/cjs/config/jest/api/RedwoodApiJestEnv.js +48 -0
- package/dist/cjs/config/jest/api/apiBabelConfig.d.ts +5 -0
- package/dist/cjs/config/jest/api/apiBabelConfig.d.ts.map +1 -0
- package/dist/cjs/config/jest/api/apiBabelConfig.js +34 -0
- package/dist/cjs/config/jest/api/globalSetup.d.ts +3 -0
- package/dist/cjs/config/jest/api/globalSetup.d.ts.map +1 -0
- package/dist/cjs/config/jest/api/globalSetup.js +61 -0
- package/dist/cjs/config/jest/api/index.d.ts +3 -0
- package/dist/cjs/config/jest/api/index.d.ts.map +1 -0
- package/dist/cjs/config/jest/api/index.js +25 -0
- package/dist/cjs/config/jest/api/jest-preset.d.ts +4 -0
- package/dist/cjs/config/jest/api/jest-preset.d.ts.map +1 -0
- package/dist/cjs/config/jest/api/jest-preset.js +97 -0
- package/dist/cjs/config/jest/api/jest.setup.d.ts +2 -0
- package/dist/cjs/config/jest/api/jest.setup.d.ts.map +1 -0
- package/dist/cjs/config/jest/api/jest.setup.js +267 -0
- package/dist/cjs/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts +11 -0
- package/dist/cjs/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -0
- package/dist/cjs/config/jest/babelPlugins/babel-plugin-redwood-cell.js +121 -0
- package/dist/cjs/config/jest/jest-serial-runner.d.ts +8 -0
- package/dist/cjs/config/jest/jest-serial-runner.d.ts.map +1 -0
- package/dist/cjs/config/jest/jest-serial-runner.js +37 -0
- package/dist/cjs/config/jest/web/RedwoodWebJestEnv.d.ts +6 -0
- package/dist/cjs/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -0
- package/dist/cjs/config/jest/web/RedwoodWebJestEnv.js +38 -0
- package/dist/cjs/config/jest/web/index.d.ts +3 -0
- package/dist/cjs/config/jest/web/index.d.ts.map +1 -0
- package/dist/cjs/config/jest/web/index.js +25 -0
- package/dist/cjs/config/jest/web/jest-preset.d.ts +4 -0
- package/dist/cjs/config/jest/web/jest-preset.d.ts.map +1 -0
- package/dist/cjs/config/jest/web/jest-preset.js +117 -0
- package/dist/cjs/config/jest/web/jest.setup.d.ts +8 -0
- package/dist/cjs/config/jest/web/jest.setup.d.ts.map +1 -0
- package/dist/cjs/config/jest/web/jest.setup.js +22 -0
- package/dist/cjs/config/jest/web/resolver.d.ts +4 -0
- package/dist/cjs/config/jest/web/resolver.d.ts.map +1 -0
- package/dist/cjs/config/jest/web/resolver.js +30 -0
- package/dist/cjs/config/jest/web/webBabelConfig.d.ts +10 -0
- package/dist/cjs/config/jest/web/webBabelConfig.d.ts.map +1 -0
- package/dist/cjs/config/jest/web/webBabelConfig.js +48 -0
- package/dist/cjs/web/global.d.ts +2 -2
- package/dist/cjs/web/global.d.ts.map +1 -1
- package/dist/config/jest/api/RedwoodApiJestEnv.d.ts +11 -0
- package/dist/config/jest/api/RedwoodApiJestEnv.d.ts.map +1 -0
- package/dist/config/jest/api/RedwoodApiJestEnv.js +28 -0
- package/dist/config/jest/api/apiBabelConfig.d.ts +5 -0
- package/dist/config/jest/api/apiBabelConfig.d.ts.map +1 -0
- package/dist/config/jest/api/apiBabelConfig.js +18 -0
- package/dist/config/jest/api/globalSetup.d.ts +3 -0
- package/dist/config/jest/api/globalSetup.d.ts.map +1 -0
- package/dist/config/jest/api/globalSetup.js +34 -0
- package/dist/config/jest/api/index.d.ts +3 -0
- package/dist/config/jest/api/index.d.ts.map +1 -0
- package/dist/config/jest/api/index.js +11 -0
- package/dist/config/jest/api/jest-preset.d.ts +4 -0
- package/dist/config/jest/api/jest-preset.d.ts.map +1 -0
- package/dist/config/jest/api/jest-preset.js +67 -0
- package/dist/config/jest/api/jest.setup.d.ts +2 -0
- package/dist/config/jest/api/jest.setup.d.ts.map +1 -0
- package/dist/config/jest/api/jest.setup.js +244 -0
- package/dist/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts +11 -0
- package/dist/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -0
- package/dist/config/jest/babelPlugins/babel-plugin-redwood-cell.js +101 -0
- package/dist/config/jest/jest-serial-runner.d.ts +8 -0
- package/dist/config/jest/jest-serial-runner.d.ts.map +1 -0
- package/dist/config/jest/jest-serial-runner.js +23 -0
- package/dist/config/jest/web/RedwoodWebJestEnv.d.ts +6 -0
- package/dist/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -0
- package/dist/config/jest/web/RedwoodWebJestEnv.js +18 -0
- package/dist/config/jest/web/index.d.ts +3 -0
- package/dist/config/jest/web/index.d.ts.map +1 -0
- package/dist/config/jest/web/index.js +11 -0
- package/dist/config/jest/web/jest-preset.d.ts +4 -0
- package/dist/config/jest/web/jest-preset.d.ts.map +1 -0
- package/dist/config/jest/web/jest-preset.js +87 -0
- package/dist/config/jest/web/jest.setup.d.ts +8 -0
- package/dist/config/jest/web/jest.setup.d.ts.map +1 -0
- package/dist/config/jest/web/jest.setup.js +28 -0
- package/dist/config/jest/web/resolver.d.ts +4 -0
- package/dist/config/jest/web/resolver.d.ts.map +1 -0
- package/dist/config/jest/web/resolver.js +38 -0
- package/dist/config/jest/web/webBabelConfig.d.ts +10 -0
- package/dist/config/jest/web/webBabelConfig.d.ts.map +1 -0
- package/dist/config/jest/web/webBabelConfig.js +18 -0
- package/dist/web/global.d.ts +2 -2
- package/dist/web/global.d.ts.map +1 -1
- package/package.json +20 -11
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-commented-exports/code.js +0 -28
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-commented-exports/output.js +0 -35
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-default-and-other-named-export/code.js +0 -7
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-default-and-other-named-export/output.js +0 -6
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-default-export/code.js +0 -3
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-default-export/output.js +0 -3
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-required-exports/code.js +0 -28
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-required-exports/output.js +0 -34
- package/config/jest/babelPlugins/__tests__/__fixtures__/viteDistDir/client-build-manifest.json +0 -59
- package/config/jest/babelPlugins/__tests__/babel-plugin-redwood-cell.test.ts +0 -11
- package/config/jest/package.json +0 -3
|
@@ -1,326 +1,267 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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_scenario = require("@cedarjs/testing/dist/cjs/api/scenario.js");
|
|
27
|
+
const { apiSrcPath, tearDownCachePath, dbSchemaPath } = global.__RWJS__TEST_IMPORTS;
|
|
28
|
+
global.defineScenario = import_scenario.defineScenario;
|
|
29
|
+
const mockContextStore = /* @__PURE__ */ new Map();
|
|
30
|
+
const mockContext = new Proxy(
|
|
31
|
+
{},
|
|
32
|
+
{
|
|
33
|
+
get: (_target, prop) => {
|
|
34
|
+
if (prop === "toJSON") {
|
|
35
|
+
return () => mockContextStore.get("context");
|
|
36
|
+
}
|
|
37
|
+
return mockContextStore.get("context")[prop];
|
|
38
|
+
},
|
|
39
|
+
set: (_target, prop, value) => {
|
|
40
|
+
const ctx = mockContextStore.get("context");
|
|
41
|
+
ctx[prop] = value;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
global.mockCurrentUser = (currentUser) => {
|
|
47
|
+
mockContextStore.set("context", { currentUser });
|
|
48
|
+
};
|
|
49
|
+
const FOREIGN_KEY_ERRORS = [1451, 1811, 23503];
|
|
50
|
+
const TEARDOWN_CACHE_PATH = tearDownCachePath;
|
|
51
|
+
const DEFAULT_SCENARIO = "standard";
|
|
52
|
+
let teardownOrder = [];
|
|
53
|
+
let originalTeardownOrder = [];
|
|
25
54
|
const deepCopy = (obj) => {
|
|
26
|
-
return JSON.parse(JSON.stringify(obj))
|
|
27
|
-
}
|
|
28
|
-
|
|
55
|
+
return JSON.parse(JSON.stringify(obj));
|
|
56
|
+
};
|
|
29
57
|
const isIdenticalArray = (a, b) => {
|
|
30
|
-
return JSON.stringify(a) === JSON.stringify(b)
|
|
31
|
-
}
|
|
32
|
-
|
|
58
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
59
|
+
};
|
|
33
60
|
const configureTeardown = async () => {
|
|
34
|
-
const { getDMMF, getSchema } = require(
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// check if pre-defined delete order already exists and if so, use it to start
|
|
44
|
-
if (fs.existsSync(TEARDOWN_CACHE_PATH)) {
|
|
45
|
-
teardownOrder = JSON.parse(fs.readFileSync(TEARDOWN_CACHE_PATH).toString())
|
|
61
|
+
const { getDMMF, getSchema } = require("@prisma/internals");
|
|
62
|
+
const datamodel = await getSchema(dbSchemaPath);
|
|
63
|
+
const schema = await getDMMF({ datamodel });
|
|
64
|
+
const schemaModels = schema.datamodel.models.map(
|
|
65
|
+
(m) => m.dbName || m.name
|
|
66
|
+
);
|
|
67
|
+
if (import_node_fs.default.existsSync(TEARDOWN_CACHE_PATH)) {
|
|
68
|
+
teardownOrder = JSON.parse(import_node_fs.default.readFileSync(TEARDOWN_CACHE_PATH).toString());
|
|
46
69
|
}
|
|
47
|
-
|
|
48
|
-
// check the number of models in case we've added/removed since cache was built
|
|
49
70
|
if (teardownOrder.length !== schemaModels.length) {
|
|
50
|
-
teardownOrder = schemaModels
|
|
71
|
+
teardownOrder = schemaModels;
|
|
51
72
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let quoteStyle
|
|
58
|
-
// determine what kind of quotes are needed around table names in raw SQL
|
|
73
|
+
originalTeardownOrder = deepCopy(teardownOrder);
|
|
74
|
+
};
|
|
75
|
+
let quoteStyle;
|
|
59
76
|
const getQuoteStyle = async () => {
|
|
60
|
-
const { getConfig: getPrismaConfig, getSchema } = require(
|
|
61
|
-
|
|
62
|
-
// @NOTE prisma utils are available in cli lib/schemaHelpers
|
|
63
|
-
// But avoid importing them, to prevent memory leaks in jest
|
|
64
|
-
const datamodel = await getSchema(dbSchemaPath)
|
|
65
|
-
|
|
77
|
+
const { getConfig: getPrismaConfig, getSchema } = require("@prisma/internals");
|
|
78
|
+
const datamodel = await getSchema(dbSchemaPath);
|
|
66
79
|
if (!quoteStyle) {
|
|
67
80
|
const config = await getPrismaConfig({
|
|
68
|
-
datamodel
|
|
69
|
-
})
|
|
70
|
-
|
|
81
|
+
datamodel
|
|
82
|
+
});
|
|
71
83
|
switch (config.datasources?.[0]?.provider) {
|
|
72
|
-
case
|
|
73
|
-
quoteStyle =
|
|
74
|
-
break
|
|
84
|
+
case "mysql":
|
|
85
|
+
quoteStyle = "`";
|
|
86
|
+
break;
|
|
75
87
|
default:
|
|
76
|
-
quoteStyle = '"'
|
|
88
|
+
quoteStyle = '"';
|
|
77
89
|
}
|
|
78
90
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Wraps "it" or "test", to seed and teardown the scenario after each test
|
|
91
|
-
* This one passes scenario data to the test function
|
|
92
|
-
*/
|
|
93
|
-
const buildScenario =
|
|
94
|
-
(itFunc, testPath) =>
|
|
95
|
-
(...args) => {
|
|
96
|
-
let scenarioName, testName, testFunc
|
|
97
|
-
|
|
91
|
+
return quoteStyle;
|
|
92
|
+
};
|
|
93
|
+
const getProjectDb = async () => {
|
|
94
|
+
const { db } = require(`${apiSrcPath}/lib/db`);
|
|
95
|
+
return db;
|
|
96
|
+
};
|
|
97
|
+
function buildScenario(itFunc, testPath) {
|
|
98
|
+
const scenarioFunc = (...args) => {
|
|
99
|
+
let scenarioName, testName, testFunc;
|
|
98
100
|
if (args.length === 3) {
|
|
99
|
-
;
|
|
101
|
+
;
|
|
102
|
+
[scenarioName, testName, testFunc] = args;
|
|
100
103
|
} else if (args.length === 2) {
|
|
101
|
-
scenarioName = DEFAULT_SCENARIO
|
|
102
|
-
|
|
104
|
+
scenarioName = DEFAULT_SCENARIO;
|
|
105
|
+
[testName, testFunc] = args;
|
|
103
106
|
} else {
|
|
104
|
-
throw new Error(
|
|
107
|
+
throw new Error("scenario() requires 2 or 3 arguments");
|
|
105
108
|
}
|
|
106
|
-
|
|
107
109
|
return itFunc(testName, async () => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const scenarioData = await seedScenario(scenario)
|
|
110
|
+
const { scenario } = await loadScenarios(testPath, scenarioName);
|
|
111
|
+
const scenarioData = await seedScenario(scenario);
|
|
111
112
|
try {
|
|
112
|
-
const result = await testFunc(scenarioData)
|
|
113
|
-
|
|
114
|
-
return result
|
|
113
|
+
const result = await testFunc(scenarioData);
|
|
114
|
+
return result;
|
|
115
115
|
} finally {
|
|
116
|
-
// Make sure to cleanup, even if test fails
|
|
117
116
|
if (wasDbUsed()) {
|
|
118
|
-
await teardown()
|
|
117
|
+
await teardown();
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const buildDescribeScenario =
|
|
129
|
-
(describeFunc, testPath) =>
|
|
130
|
-
(...args) => {
|
|
131
|
-
let scenarioName, describeBlockName, describeBlock
|
|
132
|
-
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
return Object.assign(scenarioFunc, { only: scenarioFunc });
|
|
123
|
+
}
|
|
124
|
+
function buildDescribeScenario(describeFunc, testPath) {
|
|
125
|
+
const describeScenarioFunc = (...args) => {
|
|
126
|
+
let scenarioName, describeBlockName, describeBlock;
|
|
133
127
|
if (args.length === 3) {
|
|
134
|
-
;
|
|
128
|
+
;
|
|
129
|
+
[scenarioName, describeBlockName, describeBlock] = args;
|
|
135
130
|
} else if (args.length === 2) {
|
|
136
|
-
scenarioName = DEFAULT_SCENARIO
|
|
137
|
-
|
|
131
|
+
scenarioName = DEFAULT_SCENARIO;
|
|
132
|
+
[describeBlockName, describeBlock] = args;
|
|
138
133
|
} else {
|
|
139
|
-
throw new Error(
|
|
134
|
+
throw new Error("describeScenario() requires 2 or 3 arguments");
|
|
140
135
|
}
|
|
141
|
-
|
|
142
136
|
return describeFunc(describeBlockName, () => {
|
|
143
|
-
let scenarioData
|
|
137
|
+
let scenarioData;
|
|
144
138
|
beforeAll(async () => {
|
|
145
|
-
|
|
146
|
-
scenarioData = await seedScenario(scenario)
|
|
147
|
-
})
|
|
148
|
-
|
|
139
|
+
const { scenario } = await loadScenarios(testPath, scenarioName);
|
|
140
|
+
scenarioData = await seedScenario(scenario);
|
|
141
|
+
});
|
|
149
142
|
afterAll(async () => {
|
|
150
143
|
if (wasDbUsed()) {
|
|
151
|
-
await teardown()
|
|
144
|
+
await teardown();
|
|
152
145
|
}
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
146
|
+
});
|
|
147
|
+
const getScenario = () => scenarioData;
|
|
148
|
+
describeBlock(getScenario);
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
return Object.assign(describeScenarioFunc, { only: describeScenarioFunc });
|
|
152
|
+
}
|
|
161
153
|
const teardown = async () => {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
154
|
+
const quoteStyle2 = await getQuoteStyle();
|
|
155
|
+
for (let i = 0; i < teardownOrder.length; i++) {
|
|
156
|
+
const modelName = teardownOrder[i];
|
|
157
|
+
if (!modelName) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
167
160
|
try {
|
|
168
|
-
await getProjectDb()
|
|
169
|
-
|
|
170
|
-
|
|
161
|
+
const db = await getProjectDb();
|
|
162
|
+
await db.$executeRawUnsafe(
|
|
163
|
+
`DELETE FROM ${quoteStyle2}${modelName}${quoteStyle2}`
|
|
164
|
+
);
|
|
171
165
|
} catch (e) {
|
|
172
|
-
const
|
|
166
|
+
const message = isErrorWithMessage(e) ? e.message : "";
|
|
167
|
+
const match = message.match(/Code: `(\d+)`/);
|
|
173
168
|
if (match && FOREIGN_KEY_ERRORS.includes(parseInt(match[1]))) {
|
|
174
|
-
|
|
175
|
-
teardownOrder
|
|
176
|
-
|
|
169
|
+
teardownOrder.splice(i, 1);
|
|
170
|
+
teardownOrder.push(modelName);
|
|
171
|
+
i--;
|
|
177
172
|
} else {
|
|
178
|
-
throw e
|
|
173
|
+
throw e;
|
|
179
174
|
}
|
|
180
175
|
}
|
|
181
176
|
}
|
|
182
|
-
|
|
183
|
-
// remove nulls
|
|
184
|
-
teardownOrder = teardownOrder.filter((val) => val)
|
|
185
|
-
|
|
186
|
-
// if the order of delete changed, write out the cached file again
|
|
187
177
|
if (!isIdenticalArray(teardownOrder, originalTeardownOrder)) {
|
|
188
|
-
originalTeardownOrder = deepCopy(teardownOrder)
|
|
189
|
-
|
|
178
|
+
originalTeardownOrder = deepCopy(teardownOrder);
|
|
179
|
+
import_node_fs.default.writeFileSync(TEARDOWN_CACHE_PATH, JSON.stringify(teardownOrder));
|
|
190
180
|
}
|
|
191
|
-
}
|
|
192
|
-
|
|
181
|
+
};
|
|
193
182
|
const seedScenario = async (scenario) => {
|
|
194
183
|
if (scenario) {
|
|
195
|
-
const scenarios = {}
|
|
184
|
+
const scenarios = {};
|
|
185
|
+
const db = await getProjectDb();
|
|
196
186
|
for (const [model, namedFixtures] of Object.entries(scenario)) {
|
|
197
|
-
scenarios[model] = {}
|
|
187
|
+
scenarios[model] = {};
|
|
198
188
|
for (const [name, createArgs] of Object.entries(namedFixtures)) {
|
|
199
|
-
if (typeof createArgs ===
|
|
200
|
-
scenarios[model][name] = await
|
|
201
|
-
createArgs(scenarios),
|
|
202
|
-
)
|
|
189
|
+
if (typeof createArgs === "function") {
|
|
190
|
+
scenarios[model][name] = await db[model].create(createArgs(scenarios));
|
|
203
191
|
} else {
|
|
204
|
-
scenarios[model][name] =
|
|
205
|
-
await getProjectDb()[model].create(createArgs)
|
|
192
|
+
scenarios[model][name] = await db[model].create(createArgs);
|
|
206
193
|
}
|
|
207
194
|
}
|
|
208
195
|
}
|
|
209
|
-
return scenarios
|
|
196
|
+
return scenarios;
|
|
210
197
|
} else {
|
|
211
|
-
return {}
|
|
198
|
+
return {};
|
|
212
199
|
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
global.scenario = buildScenario(global.it, global.testPath)
|
|
216
|
-
global.scenario.only = buildScenario(global.it.only, global.testPath)
|
|
200
|
+
};
|
|
201
|
+
global.scenario = buildScenario(global.it, global.testPath);
|
|
217
202
|
global.describeScenario = buildDescribeScenario(
|
|
218
203
|
global.describe,
|
|
219
|
-
global.testPath
|
|
220
|
-
)
|
|
221
|
-
global.describeScenario.only = buildDescribeScenario(
|
|
222
|
-
global.describe.only,
|
|
223
|
-
global.testPath,
|
|
224
|
-
)
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
*
|
|
228
|
-
* All these hooks run in the VM/Context that the test runs in since we're using "setupAfterEnv".
|
|
229
|
-
* There's a new context for each test-suite i.e. each test file
|
|
230
|
-
*
|
|
231
|
-
* Doing this means if the db isn't used in the current test context,
|
|
232
|
-
* no need to do any of the teardown logic - allowing simple tests to run faster
|
|
233
|
-
* At the same time, if the db is used, disconnecting it in this context prevents connection limit errors.
|
|
234
|
-
* Just disconnecting db in jest-preset is not enough, because
|
|
235
|
-
* the Prisma client is created in a different context.
|
|
236
|
-
*/
|
|
204
|
+
global.testPath
|
|
205
|
+
);
|
|
237
206
|
const wasDbUsed = () => {
|
|
238
207
|
try {
|
|
239
|
-
const libDbPath = require.resolve(`${apiSrcPath}/lib/db`)
|
|
240
|
-
return Object.keys(require.cache).some((
|
|
241
|
-
return
|
|
242
|
-
})
|
|
243
|
-
} catch
|
|
244
|
-
|
|
245
|
-
return false
|
|
208
|
+
const libDbPath = require.resolve(`${apiSrcPath}/lib/db`);
|
|
209
|
+
return Object.keys(require.cache).some((module2) => {
|
|
210
|
+
return module2 === libDbPath;
|
|
211
|
+
});
|
|
212
|
+
} catch {
|
|
213
|
+
return false;
|
|
246
214
|
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Attempt to emulate the request context isolation behavior
|
|
250
|
-
// This is a little more complicated than it would necessarily need to be
|
|
251
|
-
// but we're following the same pattern as in `@cedarjs/context`
|
|
252
|
-
const mockContextStore = new Map()
|
|
253
|
-
const mockContext = new Proxy(
|
|
254
|
-
{},
|
|
255
|
-
{
|
|
256
|
-
get: (_target, prop) => {
|
|
257
|
-
// Handle toJSON() calls, i.e. JSON.stringify(context)
|
|
258
|
-
if (prop === 'toJSON') {
|
|
259
|
-
return () => mockContextStore.get('context')
|
|
260
|
-
}
|
|
261
|
-
return mockContextStore.get('context')[prop]
|
|
262
|
-
},
|
|
263
|
-
set: (_target, prop, value) => {
|
|
264
|
-
const ctx = mockContextStore.get('context')
|
|
265
|
-
ctx[prop] = value
|
|
266
|
-
return true
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
)
|
|
270
|
-
jest.mock('@cedarjs/context', () => {
|
|
215
|
+
};
|
|
216
|
+
jest.mock("@cedarjs/context", () => {
|
|
271
217
|
return {
|
|
272
218
|
context: mockContext,
|
|
273
219
|
setContext: (newContext) => {
|
|
274
|
-
mockContextStore.set(
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
})
|
|
220
|
+
mockContextStore.set("context", newContext);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
});
|
|
278
224
|
beforeEach(() => {
|
|
279
|
-
mockContextStore.set(
|
|
280
|
-
})
|
|
281
|
-
global.mockCurrentUser = (currentUser) => {
|
|
282
|
-
mockContextStore.set('context', { currentUser })
|
|
283
|
-
}
|
|
284
|
-
|
|
225
|
+
mockContextStore.set("context", {});
|
|
226
|
+
});
|
|
285
227
|
beforeAll(async () => {
|
|
286
228
|
if (wasDbUsed()) {
|
|
287
|
-
await configureTeardown()
|
|
229
|
+
await configureTeardown();
|
|
288
230
|
}
|
|
289
|
-
})
|
|
290
|
-
|
|
231
|
+
});
|
|
291
232
|
afterAll(async () => {
|
|
292
233
|
if (wasDbUsed()) {
|
|
293
|
-
getProjectDb()
|
|
234
|
+
const db = await getProjectDb();
|
|
235
|
+
db.$disconnect();
|
|
294
236
|
}
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const testFilePath = `${testFileDir.dir}/${testFileNameParts
|
|
303
|
-
.slice(0, testFileNameParts.length - 1)
|
|
304
|
-
.join('.')}.scenarios`
|
|
305
|
-
let allScenarios, scenario
|
|
306
|
-
|
|
237
|
+
});
|
|
238
|
+
async function loadScenarios(testPath, scenarioName) {
|
|
239
|
+
const testFileDir = import_node_path.default.parse(testPath);
|
|
240
|
+
const testFileNameParts = testFileDir.name.split(".");
|
|
241
|
+
const testFilePath = `${testFileDir.dir}/${testFileNameParts.slice(0, testFileNameParts.length - 1).join(".")}.scenarios`;
|
|
242
|
+
let allScenarios;
|
|
243
|
+
let scenario;
|
|
307
244
|
try {
|
|
308
|
-
allScenarios = require(testFilePath)
|
|
245
|
+
allScenarios = require(testFilePath);
|
|
309
246
|
} catch (e) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
throw e
|
|
247
|
+
if (isErrorWithCode(e) && e.code !== "MODULE_NOT_FOUND") {
|
|
248
|
+
throw new Error(`Failed to load scenario: ${e}`);
|
|
313
249
|
}
|
|
314
250
|
}
|
|
315
|
-
|
|
316
251
|
if (allScenarios) {
|
|
317
252
|
if (allScenarios[scenarioName]) {
|
|
318
|
-
scenario = allScenarios[scenarioName]
|
|
253
|
+
scenario = allScenarios[scenarioName];
|
|
319
254
|
} else {
|
|
320
255
|
throw new Error(
|
|
321
|
-
`UndefinedScenario: There is no scenario named "${scenarioName}" in ${testFilePath}.{js,ts}
|
|
322
|
-
)
|
|
256
|
+
`UndefinedScenario: There is no scenario named "${scenarioName}" in ${testFilePath}.{js,ts}`
|
|
257
|
+
);
|
|
323
258
|
}
|
|
324
259
|
}
|
|
325
|
-
return { scenario }
|
|
260
|
+
return { scenario };
|
|
261
|
+
}
|
|
262
|
+
function isErrorWithCode(error) {
|
|
263
|
+
return !!error && typeof error === "object" && "code" in error && typeof error.code === "string";
|
|
264
|
+
}
|
|
265
|
+
function isErrorWithMessage(error) {
|
|
266
|
+
return !!error && typeof error === "object" && "message" in error && typeof error.message === "string";
|
|
326
267
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PluginObj, PluginPass } from '@babel/core';
|
|
2
|
+
import type * as t from '@babel/types';
|
|
3
|
+
interface PluginState extends PluginPass {
|
|
4
|
+
exportNames: string[];
|
|
5
|
+
hasDefaultExport: boolean;
|
|
6
|
+
}
|
|
7
|
+
export default function ({ types, }: {
|
|
8
|
+
types: typeof t;
|
|
9
|
+
}): PluginObj<PluginState>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=babel-plugin-redwood-cell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"babel-plugin-redwood-cell.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/babelPlugins/babel-plugin-redwood-cell.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,KAAK,CAAC,MAAM,cAAc,CAAA;AAqCtC,UAAU,WAAY,SAAQ,UAAU;IAKtC,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,gBAAgB,EAAE,OAAO,CAAA;CAC1B;AAED,MAAM,CAAC,OAAO,WAAW,EACvB,KAAK,GACN,EAAE;IACD,KAAK,EAAE,OAAO,CAAC,CAAA;CAChB,GAAG,SAAS,CAAC,WAAW,CAAC,CAkHzB"}
|