@cedarjs/testing 6.0.2 → 6.0.3-next.227
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/dist/api/checkTestDatabase.d.ts +27 -0
- package/dist/api/checkTestDatabase.d.ts.map +1 -1
- package/dist/api/checkTestDatabase.js +102 -0
- package/dist/api/mockContext.d.ts +1 -1
- package/dist/api/mockContext.d.ts.map +1 -1
- package/dist/api/vitest/CedarApiVitestEnv.d.ts.map +1 -1
- package/dist/api/vitest/CedarApiVitestEnv.js +14 -2
- package/dist/api/vitest/teardown.d.ts +18 -0
- package/dist/api/vitest/teardown.d.ts.map +1 -0
- package/dist/api/vitest/teardown.js +43 -0
- package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.d.ts.map +1 -1
- package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.js +6 -1
- package/dist/api/vitest/vitest-api.setup.d.ts.map +1 -1
- package/dist/api/vitest/vitest-api.setup.js +9 -22
- package/dist/web/MockParamsProvider.d.ts.map +1 -1
- package/dist/web/MockParamsProvider.js +10 -1
- package/dist/web/MockRouter.d.ts.map +1 -1
- package/dist/web/mockRequests.d.ts +14 -0
- package/dist/web/mockRequests.d.ts.map +1 -1
- package/dist/web/mockRequests.js +8 -0
- package/package.json +22 -95
- package/config/jest/api/RedwoodApiJestEnv.d.ts +0 -11
- package/config/jest/api/RedwoodApiJestEnv.d.ts.map +0 -1
- package/config/jest/api/RedwoodApiJestEnv.js +0 -48
- package/config/jest/api/apiBabelConfig.d.ts +0 -5
- package/config/jest/api/apiBabelConfig.d.ts.map +0 -1
- package/config/jest/api/apiBabelConfig.js +0 -34
- package/config/jest/api/globalSetup.d.ts +0 -3
- package/config/jest/api/globalSetup.d.ts.map +0 -1
- package/config/jest/api/globalSetup.js +0 -63
- package/config/jest/api/index.d.ts +0 -3
- package/config/jest/api/index.d.ts.map +0 -1
- package/config/jest/api/index.js +0 -25
- package/config/jest/api/jest-preset.d.ts +0 -4
- package/config/jest/api/jest-preset.d.ts.map +0 -1
- package/config/jest/api/jest-preset.js +0 -140
- package/config/jest/api/jest.setup.d.ts +0 -2
- package/config/jest/api/jest.setup.d.ts.map +0 -1
- package/config/jest/api/jest.setup.js +0 -267
- package/config/jest/api/package.json +0 -8
- package/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts +0 -11
- package/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +0 -1
- package/config/jest/babelPlugins/babel-plugin-redwood-cell.js +0 -122
- package/config/jest/jest-serial-runner.d.ts +0 -8
- package/config/jest/jest-serial-runner.d.ts.map +0 -1
- package/config/jest/jest-serial-runner.js +0 -37
- package/config/jest/web/RedwoodWebJestEnv.d.ts +0 -6
- package/config/jest/web/RedwoodWebJestEnv.d.ts.map +0 -1
- package/config/jest/web/RedwoodWebJestEnv.js +0 -43
- package/config/jest/web/index.d.ts +0 -3
- package/config/jest/web/index.d.ts.map +0 -1
- package/config/jest/web/index.js +0 -25
- package/config/jest/web/jest-fixed-jsdom.d.js +0 -1
- package/config/jest/web/jest-preset.d.ts +0 -4
- package/config/jest/web/jest-preset.d.ts.map +0 -1
- package/config/jest/web/jest-preset.js +0 -224
- package/config/jest/web/jest.setup.d.ts +0 -7
- package/config/jest/web/jest.setup.d.ts.map +0 -1
- package/config/jest/web/jest.setup.js +0 -21
- package/config/jest/web/package.json +0 -8
- package/config/jest/web/resolver.d.ts +0 -4
- package/config/jest/web/resolver.d.ts.map +0 -1
- package/config/jest/web/resolver.js +0 -30
- package/config/jest/web/webBabelConfig.d.ts +0 -10
- package/config/jest/web/webBabelConfig.d.ts.map +0 -1
- package/config/jest/web/webBabelConfig.js +0 -48
- package/config/package.json +0 -1
- package/dist/cjs/api/apiFunction.d.ts +0 -37
- package/dist/cjs/api/apiFunction.d.ts.map +0 -1
- package/dist/cjs/api/apiFunction.js +0 -89
- package/dist/cjs/api/checkTestDatabase.d.ts +0 -23
- package/dist/cjs/api/checkTestDatabase.d.ts.map +0 -1
- package/dist/cjs/api/checkTestDatabase.js +0 -69
- package/dist/cjs/api/directive.d.ts +0 -51
- package/dist/cjs/api/directive.d.ts.map +0 -1
- package/dist/cjs/api/directive.js +0 -77
- package/dist/cjs/api/index.d.ts +0 -4
- package/dist/cjs/api/index.d.ts.map +0 -1
- package/dist/cjs/api/index.js +0 -26
- package/dist/cjs/api/mockContext.d.ts +0 -5
- package/dist/cjs/api/mockContext.d.ts.map +0 -1
- package/dist/cjs/api/mockContext.js +0 -58
- package/dist/cjs/api/scenario.d.ts +0 -108
- package/dist/cjs/api/scenario.d.ts.map +0 -1
- package/dist/cjs/api/scenario.js +0 -30
- package/dist/cjs/api/vitest/CedarApiVitestEnv.js +0 -75
- package/dist/cjs/api/vitest/index.js +0 -34
- package/dist/cjs/api/vitest/vite-plugin-auto-import.js +0 -71
- package/dist/cjs/api/vitest/vite-plugin-cedar-vitest-api-config.js +0 -69
- package/dist/cjs/api/vitest/vite-plugin-track-db-imports.js +0 -47
- package/dist/cjs/api/vitest/vitest-api.setup.js +0 -270
- package/dist/cjs/cache/index.d.ts +0 -50
- package/dist/cjs/cache/index.d.ts.map +0 -1
- package/dist/cjs/cache/index.js +0 -104
- package/dist/cjs/config/jest/api/RedwoodApiJestEnv.d.ts +0 -11
- package/dist/cjs/config/jest/api/RedwoodApiJestEnv.d.ts.map +0 -1
- package/dist/cjs/config/jest/api/RedwoodApiJestEnv.js +0 -48
- package/dist/cjs/config/jest/api/apiBabelConfig.d.ts +0 -5
- package/dist/cjs/config/jest/api/apiBabelConfig.d.ts.map +0 -1
- package/dist/cjs/config/jest/api/apiBabelConfig.js +0 -34
- package/dist/cjs/config/jest/api/globalSetup.d.ts +0 -3
- package/dist/cjs/config/jest/api/globalSetup.d.ts.map +0 -1
- package/dist/cjs/config/jest/api/globalSetup.js +0 -63
- package/dist/cjs/config/jest/api/index.d.ts +0 -3
- package/dist/cjs/config/jest/api/index.d.ts.map +0 -1
- package/dist/cjs/config/jest/api/index.js +0 -25
- package/dist/cjs/config/jest/api/jest-preset.d.ts +0 -4
- package/dist/cjs/config/jest/api/jest-preset.d.ts.map +0 -1
- package/dist/cjs/config/jest/api/jest-preset.js +0 -140
- package/dist/cjs/config/jest/api/jest.setup.d.ts +0 -2
- package/dist/cjs/config/jest/api/jest.setup.d.ts.map +0 -1
- package/dist/cjs/config/jest/api/jest.setup.js +0 -267
- package/dist/cjs/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts +0 -11
- package/dist/cjs/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +0 -1
- package/dist/cjs/config/jest/babelPlugins/babel-plugin-redwood-cell.js +0 -122
- package/dist/cjs/config/jest/jest-serial-runner.d.ts +0 -8
- package/dist/cjs/config/jest/jest-serial-runner.d.ts.map +0 -1
- package/dist/cjs/config/jest/jest-serial-runner.js +0 -37
- package/dist/cjs/config/jest/web/RedwoodWebJestEnv.d.ts +0 -6
- package/dist/cjs/config/jest/web/RedwoodWebJestEnv.d.ts.map +0 -1
- package/dist/cjs/config/jest/web/RedwoodWebJestEnv.js +0 -43
- package/dist/cjs/config/jest/web/index.d.ts +0 -3
- package/dist/cjs/config/jest/web/index.d.ts.map +0 -1
- package/dist/cjs/config/jest/web/index.js +0 -25
- package/dist/cjs/config/jest/web/jest-fixed-jsdom.d.js +0 -1
- package/dist/cjs/config/jest/web/jest-preset.d.ts +0 -4
- package/dist/cjs/config/jest/web/jest-preset.d.ts.map +0 -1
- package/dist/cjs/config/jest/web/jest-preset.js +0 -224
- package/dist/cjs/config/jest/web/jest.setup.d.ts +0 -7
- package/dist/cjs/config/jest/web/jest.setup.d.ts.map +0 -1
- package/dist/cjs/config/jest/web/jest.setup.js +0 -21
- package/dist/cjs/config/jest/web/resolver.d.ts +0 -4
- package/dist/cjs/config/jest/web/resolver.d.ts.map +0 -1
- package/dist/cjs/config/jest/web/resolver.js +0 -30
- package/dist/cjs/config/jest/web/webBabelConfig.d.ts +0 -10
- package/dist/cjs/config/jest/web/webBabelConfig.d.ts.map +0 -1
- package/dist/cjs/config/jest/web/webBabelConfig.js +0 -48
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/web/MockParamsProvider.d.ts +0 -7
- package/dist/cjs/web/MockParamsProvider.d.ts.map +0 -1
- package/dist/cjs/web/MockParamsProvider.js +0 -44
- package/dist/cjs/web/MockProviders.d.ts +0 -5
- package/dist/cjs/web/MockProviders.d.ts.map +0 -1
- package/dist/cjs/web/MockProviders.js +0 -66
- package/dist/cjs/web/MockRouter.d.ts +0 -11
- package/dist/cjs/web/MockRouter.d.ts.map +0 -1
- package/dist/cjs/web/MockRouter.js +0 -48
- package/dist/cjs/web/customRender.d.ts +0 -6
- package/dist/cjs/web/customRender.d.ts.map +0 -1
- package/dist/cjs/web/customRender.js +0 -54
- package/dist/cjs/web/fileMock.d.ts +0 -10
- package/dist/cjs/web/fileMock.d.ts.map +0 -1
- package/dist/cjs/web/fileMock.js +0 -24
- package/dist/cjs/web/findCellMocks.d.ts +0 -2
- package/dist/cjs/web/findCellMocks.d.ts.map +0 -1
- package/dist/cjs/web/findCellMocks.js +0 -45
- package/dist/cjs/web/globRoutesImporter.d.ts +0 -13
- package/dist/cjs/web/globRoutesImporter.d.ts.map +0 -1
- package/dist/cjs/web/globRoutesImporter.js +0 -46
- package/dist/cjs/web/global.d.ts +0 -6
- package/dist/cjs/web/global.d.ts.map +0 -1
- package/dist/cjs/web/global.js +0 -1
- package/dist/cjs/web/index.d.ts +0 -6
- package/dist/cjs/web/index.d.ts.map +0 -1
- package/dist/cjs/web/index.js +0 -41
- package/dist/cjs/web/mockAuth.d.ts +0 -29
- package/dist/cjs/web/mockAuth.d.ts.map +0 -1
- package/dist/cjs/web/mockAuth.js +0 -89
- package/dist/cjs/web/mockRequests.d.ts +0 -72
- package/dist/cjs/web/mockRequests.d.ts.map +0 -1
- package/dist/cjs/web/mockRequests.js +0 -210
- package/dist/cjs/web/vitest/index.js +0 -37
- package/dist/cjs/web/vitest/vite-plugin-auto-import.js +0 -60
- package/dist/cjs/web/vitest/vite-plugin-cedar-vitest-web-config.js +0 -51
- package/dist/cjs/web/vitest/vite-plugin-cedarjs-router-import-transform.js +0 -42
- package/dist/cjs/web/vitest/vite-plugin-create-auth-import-transform.js +0 -43
- package/dist/cjs/web/vitest/vitest-web.setup.js +0 -19
- package/dist/config/jest/api/RedwoodApiJestEnv.d.ts +0 -11
- package/dist/config/jest/api/RedwoodApiJestEnv.d.ts.map +0 -1
- package/dist/config/jest/api/RedwoodApiJestEnv.js +0 -28
- package/dist/config/jest/api/apiBabelConfig.d.ts +0 -5
- package/dist/config/jest/api/apiBabelConfig.d.ts.map +0 -1
- package/dist/config/jest/api/apiBabelConfig.js +0 -18
- package/dist/config/jest/api/globalSetup.d.ts +0 -3
- package/dist/config/jest/api/globalSetup.d.ts.map +0 -1
- package/dist/config/jest/api/globalSetup.js +0 -36
- package/dist/config/jest/api/index.d.ts +0 -3
- package/dist/config/jest/api/index.d.ts.map +0 -1
- package/dist/config/jest/api/index.js +0 -15
- package/dist/config/jest/api/jest-preset.d.ts +0 -4
- package/dist/config/jest/api/jest-preset.d.ts.map +0 -1
- package/dist/config/jest/api/jest-preset.js +0 -110
- package/dist/config/jest/api/jest.setup.d.ts +0 -2
- package/dist/config/jest/api/jest.setup.d.ts.map +0 -1
- package/dist/config/jest/api/jest.setup.js +0 -244
- package/dist/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts +0 -11
- package/dist/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +0 -1
- package/dist/config/jest/babelPlugins/babel-plugin-redwood-cell.js +0 -102
- package/dist/config/jest/jest-serial-runner.d.ts +0 -8
- package/dist/config/jest/jest-serial-runner.d.ts.map +0 -1
- package/dist/config/jest/jest-serial-runner.js +0 -27
- package/dist/config/jest/web/RedwoodWebJestEnv.d.ts +0 -6
- package/dist/config/jest/web/RedwoodWebJestEnv.d.ts.map +0 -1
- package/dist/config/jest/web/RedwoodWebJestEnv.js +0 -13
- package/dist/config/jest/web/index.d.ts +0 -3
- package/dist/config/jest/web/index.d.ts.map +0 -1
- package/dist/config/jest/web/index.js +0 -15
- package/dist/config/jest/web/jest-fixed-jsdom.d.js +0 -0
- package/dist/config/jest/web/jest-preset.d.ts +0 -4
- package/dist/config/jest/web/jest-preset.d.ts.map +0 -1
- package/dist/config/jest/web/jest-preset.js +0 -194
- package/dist/config/jest/web/jest.setup.d.ts +0 -7
- package/dist/config/jest/web/jest.setup.d.ts.map +0 -1
- package/dist/config/jest/web/jest.setup.js +0 -27
- package/dist/config/jest/web/resolver.d.ts +0 -4
- package/dist/config/jest/web/resolver.d.ts.map +0 -1
- package/dist/config/jest/web/resolver.js +0 -42
- package/dist/config/jest/web/webBabelConfig.d.ts +0 -10
- package/dist/config/jest/web/webBabelConfig.d.ts.map +0 -1
- package/dist/config/jest/web/webBabelConfig.js +0 -18
- package/dist/web/fileMock.d.ts +0 -10
- package/dist/web/fileMock.d.ts.map +0 -1
- package/dist/web/fileMock.js +0 -4
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { defineScenario } from "../../../api/scenario.js";
|
|
4
|
-
const { apiSrcPath, tearDownCachePath } = global.__CEDARJS__TEST_IMPORTS;
|
|
5
|
-
global.defineScenario = defineScenario;
|
|
6
|
-
const mockContextStore = /* @__PURE__ */ new Map();
|
|
7
|
-
const mockContext = new Proxy(
|
|
8
|
-
{},
|
|
9
|
-
{
|
|
10
|
-
get: (_target, prop) => {
|
|
11
|
-
if (prop === "toJSON") {
|
|
12
|
-
return () => mockContextStore.get("context");
|
|
13
|
-
}
|
|
14
|
-
return mockContextStore.get("context")[prop];
|
|
15
|
-
},
|
|
16
|
-
set: (_target, prop, value) => {
|
|
17
|
-
const ctx = mockContextStore.get("context");
|
|
18
|
-
ctx[prop] = value;
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
global.mockCurrentUser = (currentUser) => {
|
|
24
|
-
mockContextStore.set("context", { currentUser });
|
|
25
|
-
};
|
|
26
|
-
const HANDLED_ERRORS = [1451, 1811, 23001, 23503];
|
|
27
|
-
const TEARDOWN_CACHE_PATH = tearDownCachePath;
|
|
28
|
-
const DEFAULT_SCENARIO = "standard";
|
|
29
|
-
let teardownOrder = [];
|
|
30
|
-
let originalTeardownOrder = [];
|
|
31
|
-
const deepCopy = (obj) => {
|
|
32
|
-
return JSON.parse(JSON.stringify(obj));
|
|
33
|
-
};
|
|
34
|
-
const isIdenticalArray = (a, b) => {
|
|
35
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
36
|
-
};
|
|
37
|
-
const configureTeardown = async () => {
|
|
38
|
-
const { getDMMF } = await import("@prisma/internals");
|
|
39
|
-
const { getPrismaSchemas } = await import("@cedarjs/project-config");
|
|
40
|
-
const { schemas } = await getPrismaSchemas();
|
|
41
|
-
const schema = await getDMMF({ datamodel: schemas });
|
|
42
|
-
const schemaModels = schema.datamodel.models.map(
|
|
43
|
-
(m) => m.dbName || m.name
|
|
44
|
-
);
|
|
45
|
-
if (fs.existsSync(TEARDOWN_CACHE_PATH)) {
|
|
46
|
-
teardownOrder = JSON.parse(fs.readFileSync(TEARDOWN_CACHE_PATH).toString());
|
|
47
|
-
}
|
|
48
|
-
if (teardownOrder.length !== schemaModels.length) {
|
|
49
|
-
teardownOrder = schemaModels;
|
|
50
|
-
}
|
|
51
|
-
originalTeardownOrder = deepCopy(teardownOrder);
|
|
52
|
-
};
|
|
53
|
-
let quoteStyle;
|
|
54
|
-
const getQuoteStyle = async () => {
|
|
55
|
-
const { getConfig: getPrismaConfig } = await import("@prisma/internals");
|
|
56
|
-
const { getPrismaSchemas } = await import("@cedarjs/project-config");
|
|
57
|
-
const result = await getPrismaSchemas();
|
|
58
|
-
if (!quoteStyle) {
|
|
59
|
-
const config = await getPrismaConfig({ datamodel: result.schemas });
|
|
60
|
-
switch (config.datasources?.[0]?.provider) {
|
|
61
|
-
case "mysql":
|
|
62
|
-
quoteStyle = "`";
|
|
63
|
-
break;
|
|
64
|
-
default:
|
|
65
|
-
quoteStyle = '"';
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return quoteStyle;
|
|
69
|
-
};
|
|
70
|
-
const getProjectDb = async () => {
|
|
71
|
-
const { db } = await import(`${apiSrcPath}/lib/db`);
|
|
72
|
-
return db;
|
|
73
|
-
};
|
|
74
|
-
function buildScenario(itFunc, testPath) {
|
|
75
|
-
const scenarioFunc = (...args) => {
|
|
76
|
-
let scenarioName, testName, 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 () => {
|
|
87
|
-
const { scenario } = await loadScenarios(testPath, scenarioName);
|
|
88
|
-
const scenarioData = await seedScenario(scenario);
|
|
89
|
-
try {
|
|
90
|
-
const result = await testFunc(scenarioData);
|
|
91
|
-
return result;
|
|
92
|
-
} finally {
|
|
93
|
-
if (wasDbUsed()) {
|
|
94
|
-
await teardown();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
return Object.assign(scenarioFunc, { only: scenarioFunc });
|
|
100
|
-
}
|
|
101
|
-
function buildDescribeScenario(describeFunc, testPath) {
|
|
102
|
-
const describeScenarioFunc = (...args) => {
|
|
103
|
-
let scenarioName, describeBlockName, 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
|
-
beforeAll(async () => {
|
|
116
|
-
const { scenario } = await loadScenarios(testPath, scenarioName);
|
|
117
|
-
scenarioData = await seedScenario(scenario);
|
|
118
|
-
});
|
|
119
|
-
afterAll(async () => {
|
|
120
|
-
if (wasDbUsed()) {
|
|
121
|
-
await teardown();
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
const getScenario = () => scenarioData;
|
|
125
|
-
describeBlock(getScenario);
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
return Object.assign(describeScenarioFunc, { only: describeScenarioFunc });
|
|
129
|
-
}
|
|
130
|
-
const teardown = async () => {
|
|
131
|
-
const quoteStyle2 = await getQuoteStyle();
|
|
132
|
-
for (let i = 0; i < teardownOrder.length; i++) {
|
|
133
|
-
const modelName = teardownOrder[i];
|
|
134
|
-
if (!modelName) {
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
try {
|
|
138
|
-
const db = await getProjectDb();
|
|
139
|
-
await db.$executeRawUnsafe(
|
|
140
|
-
`DELETE FROM ${quoteStyle2}${modelName}${quoteStyle2}`
|
|
141
|
-
);
|
|
142
|
-
} catch (e) {
|
|
143
|
-
const message = isErrorWithMessage(e) ? e.message : "";
|
|
144
|
-
const match = message.match(/Code: `(\d+)`/);
|
|
145
|
-
if (match && HANDLED_ERRORS.includes(parseInt(match[1]))) {
|
|
146
|
-
teardownOrder.splice(i, 1);
|
|
147
|
-
teardownOrder.push(modelName);
|
|
148
|
-
i--;
|
|
149
|
-
} else {
|
|
150
|
-
throw e;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (!isIdenticalArray(teardownOrder, originalTeardownOrder)) {
|
|
155
|
-
originalTeardownOrder = deepCopy(teardownOrder);
|
|
156
|
-
fs.writeFileSync(TEARDOWN_CACHE_PATH, JSON.stringify(teardownOrder));
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const seedScenario = async (scenario) => {
|
|
160
|
-
if (scenario) {
|
|
161
|
-
const scenarios = {};
|
|
162
|
-
const db = await getProjectDb();
|
|
163
|
-
for (const [model, namedFixtures] of Object.entries(scenario)) {
|
|
164
|
-
scenarios[model] = {};
|
|
165
|
-
for (const [name, createArgs] of Object.entries(namedFixtures)) {
|
|
166
|
-
if (typeof createArgs === "function") {
|
|
167
|
-
scenarios[model][name] = await db[model].create(createArgs(scenarios));
|
|
168
|
-
} else {
|
|
169
|
-
scenarios[model][name] = await db[model].create(createArgs);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return scenarios;
|
|
174
|
-
} else {
|
|
175
|
-
return {};
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
global.scenario = buildScenario(global.it, global.testPath);
|
|
179
|
-
global.describeScenario = buildDescribeScenario(
|
|
180
|
-
global.describe,
|
|
181
|
-
global.testPath
|
|
182
|
-
);
|
|
183
|
-
const wasDbUsed = () => {
|
|
184
|
-
try {
|
|
185
|
-
const libDbPath = require.resolve(`${apiSrcPath}/lib/db`);
|
|
186
|
-
return Object.keys(require.cache).some((module) => {
|
|
187
|
-
return module === libDbPath;
|
|
188
|
-
});
|
|
189
|
-
} catch {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
jest.mock("@cedarjs/context", () => {
|
|
194
|
-
return {
|
|
195
|
-
context: mockContext,
|
|
196
|
-
setContext: (newContext) => {
|
|
197
|
-
mockContextStore.set("context", newContext);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
});
|
|
201
|
-
beforeEach(() => {
|
|
202
|
-
mockContextStore.set("context", {});
|
|
203
|
-
});
|
|
204
|
-
beforeAll(async () => {
|
|
205
|
-
if (wasDbUsed()) {
|
|
206
|
-
await configureTeardown();
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
afterAll(async () => {
|
|
210
|
-
if (wasDbUsed()) {
|
|
211
|
-
const db = await getProjectDb();
|
|
212
|
-
db.$disconnect();
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
async function loadScenarios(testPath, scenarioName) {
|
|
216
|
-
const testFileDir = path.parse(testPath);
|
|
217
|
-
const testFileNameParts = testFileDir.name.split(".");
|
|
218
|
-
const testFilePath = `${testFileDir.dir}/${testFileNameParts.slice(0, testFileNameParts.length - 1).join(".")}.scenarios`;
|
|
219
|
-
let allScenarios;
|
|
220
|
-
let scenario;
|
|
221
|
-
try {
|
|
222
|
-
allScenarios = await import(testFilePath);
|
|
223
|
-
} catch (e) {
|
|
224
|
-
if (isErrorWithCode(e) && e.code !== "MODULE_NOT_FOUND") {
|
|
225
|
-
throw new Error(`Failed to load scenario: ${e}`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (allScenarios) {
|
|
229
|
-
if (allScenarios[scenarioName]) {
|
|
230
|
-
scenario = allScenarios[scenarioName];
|
|
231
|
-
} else {
|
|
232
|
-
throw new Error(
|
|
233
|
-
`UndefinedScenario: There is no scenario named "${scenarioName}" in ${testFilePath}.{js,ts}`
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return { scenario };
|
|
238
|
-
}
|
|
239
|
-
function isErrorWithCode(error) {
|
|
240
|
-
return !!error && typeof error === "object" && "code" in error && typeof error.code === "string";
|
|
241
|
-
}
|
|
242
|
-
function isErrorWithMessage(error) {
|
|
243
|
-
return !!error && typeof error === "object" && "message" in error && typeof error.message === "string";
|
|
244
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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;AAsCtC,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,CAoHzB"}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { parse } from "node:path";
|
|
2
|
-
const EXPECTED_EXPORTS_FROM_CELL = [
|
|
3
|
-
"beforeQuery",
|
|
4
|
-
"QUERY",
|
|
5
|
-
"FRAGMENT",
|
|
6
|
-
"data",
|
|
7
|
-
"isEmpty",
|
|
8
|
-
"afterQuery",
|
|
9
|
-
"Loading",
|
|
10
|
-
"Success",
|
|
11
|
-
"Failure",
|
|
12
|
-
"Empty"
|
|
13
|
-
];
|
|
14
|
-
function isExpectedExport(name) {
|
|
15
|
-
return name !== void 0 && EXPECTED_EXPORTS_FROM_CELL.includes(name);
|
|
16
|
-
}
|
|
17
|
-
function babel_plugin_redwood_cell_default({
|
|
18
|
-
types
|
|
19
|
-
}) {
|
|
20
|
-
return {
|
|
21
|
-
name: "babel-plugin-redwood-cell",
|
|
22
|
-
visitor: {
|
|
23
|
-
ExportDefaultDeclaration(path, state) {
|
|
24
|
-
state.hasDefaultExport = true;
|
|
25
|
-
},
|
|
26
|
-
ExportNamedDeclaration(path, state) {
|
|
27
|
-
const declaration = path.node.declaration;
|
|
28
|
-
if (!declaration) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
let name;
|
|
32
|
-
if (declaration.type === "VariableDeclaration") {
|
|
33
|
-
const id = declaration.declarations[0].id;
|
|
34
|
-
if (id.type === "Identifier") {
|
|
35
|
-
name = id.name;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (declaration.type === "FunctionDeclaration") {
|
|
39
|
-
name = declaration?.id?.name;
|
|
40
|
-
}
|
|
41
|
-
if (isExpectedExport(name)) {
|
|
42
|
-
state.exportNames.push(name);
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
Program: {
|
|
46
|
-
enter(_path, state) {
|
|
47
|
-
state.exportNames = [];
|
|
48
|
-
state.hasDefaultExport = false;
|
|
49
|
-
},
|
|
50
|
-
exit(path, state) {
|
|
51
|
-
const hasQueryOrDataExport = state.exportNames.includes("QUERY") || state.exportNames.includes("FRAGMENT") || state.exportNames.includes("data");
|
|
52
|
-
if (state.hasDefaultExport || !hasQueryOrDataExport) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const createCellHookName = state.exportNames.includes("data") ? "createServerCell" : "createCell";
|
|
56
|
-
const importFrom = state.exportNames.includes("data") ? "@cedarjs/web/dist/components/cell/createServerCell" : "@cedarjs/web";
|
|
57
|
-
path.node.body.unshift(
|
|
58
|
-
types.importDeclaration(
|
|
59
|
-
[
|
|
60
|
-
types.importSpecifier(
|
|
61
|
-
types.identifier(createCellHookName),
|
|
62
|
-
types.identifier(createCellHookName)
|
|
63
|
-
)
|
|
64
|
-
],
|
|
65
|
-
types.stringLiteral(importFrom)
|
|
66
|
-
)
|
|
67
|
-
);
|
|
68
|
-
const objectProperties = [
|
|
69
|
-
...state.exportNames.map(
|
|
70
|
-
(name) => types.objectProperty(
|
|
71
|
-
types.identifier(name),
|
|
72
|
-
types.identifier(name),
|
|
73
|
-
false,
|
|
74
|
-
true
|
|
75
|
-
)
|
|
76
|
-
)
|
|
77
|
-
];
|
|
78
|
-
if (state.file.opts.filename) {
|
|
79
|
-
objectProperties.push(
|
|
80
|
-
types.objectProperty(
|
|
81
|
-
types.identifier("displayName"),
|
|
82
|
-
types.stringLiteral(parse(state.file.opts.filename).name),
|
|
83
|
-
false,
|
|
84
|
-
true
|
|
85
|
-
)
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
path.node.body.push(
|
|
89
|
-
types.exportDefaultDeclaration(
|
|
90
|
-
types.callExpression(types.identifier(createCellHookName), [
|
|
91
|
-
types.objectExpression(objectProperties)
|
|
92
|
-
])
|
|
93
|
-
)
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
export {
|
|
101
|
-
babel_plugin_redwood_cell_default as default
|
|
102
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import jestRunner from 'jest-runner';
|
|
2
|
-
declare const TestRunner: (typeof jestRunner)['default'];
|
|
3
|
-
declare class SerialRunner extends TestRunner {
|
|
4
|
-
isSerial: boolean;
|
|
5
|
-
constructor(...attr: ConstructorParameters<typeof TestRunner>);
|
|
6
|
-
}
|
|
7
|
-
export = SerialRunner;
|
|
8
|
-
//# sourceMappingURL=jest-serial-runner.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jest-serial-runner.d.ts","sourceRoot":"","sources":["../../../src/config/jest/jest-serial-runner.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,MAAM,aAAa,CAAA;AAGpC,QAAA,MAAM,UAAU,EAAE,CAAC,OAAO,UAAU,CAAC,CAAC,SAAS,CAGb,CAAA;AAElC,cAAM,YAAa,SAAQ,UAAU;IAC5B,QAAQ,EAAE,OAAO,CAAA;gBAEZ,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,UAAU,CAAC;CAI9D;AAMD,SAAS,YAAY,CAAA"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
-
try {
|
|
4
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
5
|
-
} catch (e) {
|
|
6
|
-
throw mod = 0, e;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
import jestRunner from "jest-runner";
|
|
10
|
-
var require_jest_serial_runner = __commonJS({
|
|
11
|
-
"src/config/jest/jest-serial-runner.ts"(exports, module) {
|
|
12
|
-
const TestRunner = (
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
jestRunner.default || jestRunner
|
|
16
|
-
);
|
|
17
|
-
class SerialRunner extends TestRunner {
|
|
18
|
-
isSerial;
|
|
19
|
-
constructor(...attr) {
|
|
20
|
-
super(...attr);
|
|
21
|
-
this.isSerial = true;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
module.exports = SerialRunner;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
export default require_jest_serial_runner();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RedwoodWebJestEnv.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/web/RedwoodWebJestEnv.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,kBAAkB,CAAA;AAkB/C,cAAM,yBAA0B,SAAQ,gBAAgB;IAChD,KAAK;CASZ;AAED,eAAe,yBAAyB,CAAA"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import JSDOMEnvironment from "jest-fixed-jsdom";
|
|
2
|
-
class RedwoodWebJestEnvironment extends JSDOMEnvironment {
|
|
3
|
-
async setup() {
|
|
4
|
-
await super.setup();
|
|
5
|
-
if (typeof this.global.crypto.subtle === "undefined") {
|
|
6
|
-
this.global.crypto.subtle = {};
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
var RedwoodWebJestEnv_default = RedwoodWebJestEnvironment;
|
|
11
|
-
export {
|
|
12
|
-
RedwoodWebJestEnv_default as default
|
|
13
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/web/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAA;AAM9C,SAAS,UAAU,CAAA"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
-
try {
|
|
4
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
5
|
-
} catch (e) {
|
|
6
|
-
throw mod = 0, e;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
import * as jestPreset from "./jest-preset.js";
|
|
10
|
-
var require_web = __commonJS({
|
|
11
|
-
"src/config/jest/web/index.ts"(exports, module) {
|
|
12
|
-
module.exports = jestPreset;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
export default require_web();
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/web/jest-preset.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAiIlC,QAAA,MAAM,MAAM,EAAE,MA0Ib,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { getPaths } from "@cedarjs/project-config";
|
|
4
|
-
const cedarPaths = getPaths();
|
|
5
|
-
const RESOLVE_FROM = [cedarPaths.web.base, cedarPaths.base];
|
|
6
|
-
function resolvePackageDir(packageName, resolveFrom = RESOLVE_FROM) {
|
|
7
|
-
try {
|
|
8
|
-
return path.dirname(
|
|
9
|
-
require.resolve(`${packageName}/package.json`, { paths: resolveFrom })
|
|
10
|
-
);
|
|
11
|
-
} catch {
|
|
12
|
-
}
|
|
13
|
-
try {
|
|
14
|
-
let dir = path.dirname(require.resolve(packageName, { paths: resolveFrom }));
|
|
15
|
-
for (; ; ) {
|
|
16
|
-
const manifestPath = path.join(dir, "package.json");
|
|
17
|
-
if (fs.existsSync(manifestPath)) {
|
|
18
|
-
const manifest = JSON.parse(
|
|
19
|
-
fs.readFileSync(manifestPath, "utf-8")
|
|
20
|
-
);
|
|
21
|
-
if (manifest && typeof manifest === "object" && "name" in manifest && manifest.name === packageName) {
|
|
22
|
-
return dir;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
const parent = path.dirname(dir);
|
|
26
|
-
if (parent === dir) {
|
|
27
|
-
return void 0;
|
|
28
|
-
}
|
|
29
|
-
dir = parent;
|
|
30
|
-
}
|
|
31
|
-
} catch {
|
|
32
|
-
return void 0;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function packagePath(packageName, relativePath = "", resolveFrom = RESOLVE_FROM) {
|
|
36
|
-
const packageDir = resolvePackageDir(packageName, resolveFrom);
|
|
37
|
-
return packageDir && path.join(packageDir, relativePath);
|
|
38
|
-
}
|
|
39
|
-
function resolveSubpath(specifier, resolveFrom = RESOLVE_FROM) {
|
|
40
|
-
try {
|
|
41
|
-
return require.resolve(specifier, { paths: resolveFrom });
|
|
42
|
-
} catch {
|
|
43
|
-
return void 0;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const cedarWebDir = resolvePackageDir("@cedarjs/web");
|
|
47
|
-
const cedarWebResolveFrom = cedarWebDir ? [cedarWebDir, ...RESOLVE_FROM] : RESOLVE_FROM;
|
|
48
|
-
function definedEntries(mappings) {
|
|
49
|
-
return Object.fromEntries(
|
|
50
|
-
Object.entries(mappings).filter(
|
|
51
|
-
(entry) => entry[1] !== void 0
|
|
52
|
-
)
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
const config = {
|
|
56
|
-
// To make sure other config option which depends on rootDir always
|
|
57
|
-
// use correct path, for example, coverageDirectory
|
|
58
|
-
rootDir: cedarPaths.base,
|
|
59
|
-
roots: [path.join(cedarPaths.web.src)],
|
|
60
|
-
// Opting out of jsdom's browser-style export condition resolution (needed to
|
|
61
|
-
// resolve `msw/node`) is handled by the environment itself, via
|
|
62
|
-
// jest-fixed-jsdom
|
|
63
|
-
testEnvironment: path.join(__dirname, "./RedwoodWebJestEnv.js"),
|
|
64
|
-
displayName: {
|
|
65
|
-
color: "blueBright",
|
|
66
|
-
name: "web"
|
|
67
|
-
},
|
|
68
|
-
globals: {
|
|
69
|
-
__RWJS_TESTROOT_DIR: path.join(cedarPaths.web.src),
|
|
70
|
-
// used in jest setup to load mocks
|
|
71
|
-
RWJS_ENV: {
|
|
72
|
-
RWJS_API_URL: "",
|
|
73
|
-
RWJS_API_GRAPHQL_URL: "/",
|
|
74
|
-
__REDWOOD__APP_TITLE: "Redwood App"
|
|
75
|
-
},
|
|
76
|
-
RWJS_DEBUG_ENV: {
|
|
77
|
-
RWJS_SRC_ROOT: cedarPaths.web.src
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
collectCoverageFrom: [
|
|
81
|
-
"**/*.{js,jsx,ts,tsx}",
|
|
82
|
-
"!**/node_modules/**",
|
|
83
|
-
"!**/dist/**"
|
|
84
|
-
],
|
|
85
|
-
coverageDirectory: path.join(cedarPaths.base, "coverage"),
|
|
86
|
-
watchPlugins: [
|
|
87
|
-
"jest-watch-typeahead/filename",
|
|
88
|
-
"jest-watch-typeahead/testname"
|
|
89
|
-
],
|
|
90
|
-
setupFilesAfterEnv: [path.resolve(__dirname, "./jest.setup.js")],
|
|
91
|
-
moduleNameMapper: {
|
|
92
|
-
...definedEntries({
|
|
93
|
-
/**
|
|
94
|
-
* Make sure modules that require different versions of these
|
|
95
|
-
* dependencies end up using the same one.
|
|
96
|
-
*/
|
|
97
|
-
"^react$": resolveSubpath("react"),
|
|
98
|
-
"^react-dom$": resolveSubpath("react-dom"),
|
|
99
|
-
// Point straight at Apollo Client's CJS build. Resolving the subpath
|
|
100
|
-
// would go through its `exports` map and land on the ESM build (Node 22+
|
|
101
|
-
// picks the `module-sync` condition), which Jest can't parse.
|
|
102
|
-
// Resolved starting from `@cedarjs/web` because that's what depends on
|
|
103
|
-
// Apollo — a project doesn't declare it itself, so under pnpm it isn't
|
|
104
|
-
// reachable from the web side at all, and searching from there finds
|
|
105
|
-
// either nothing or some unrelated copy pulled in by another dependency
|
|
106
|
-
"^@apollo/client/react$": packagePath(
|
|
107
|
-
"@apollo/client",
|
|
108
|
-
"__cjs/react/index.cjs",
|
|
109
|
-
cedarWebResolveFrom
|
|
110
|
-
),
|
|
111
|
-
// We replace imports to "@cedarjs/router" with our own "mock" implementation.
|
|
112
|
-
"^@cedarjs/router$": resolveSubpath("@cedarjs/testing/web/MockRouter.js"),
|
|
113
|
-
"^@cedarjs/web$": resolveSubpath("@cedarjs/web"),
|
|
114
|
-
// This allows us to mock `createAuthentication` which is used by auth
|
|
115
|
-
// clients, which in turn lets us mock `useAuth` in tests
|
|
116
|
-
"^@cedarjs/auth$": resolveSubpath("@cedarjs/testing/auth"),
|
|
117
|
-
// @NOTE: Import @cedarjs/testing in web tests, and it automatically remaps to the web side only
|
|
118
|
-
// This is to prevent web stuff leaking into api, and vice versa
|
|
119
|
-
"^@cedarjs/testing$": resolveSubpath("@cedarjs/testing/web"),
|
|
120
|
-
/**
|
|
121
|
-
* Mock out files that aren't particularly useful in tests. See fileMock.js for more info.
|
|
122
|
-
*/
|
|
123
|
-
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|css)$": resolveSubpath("@cedarjs/testing/dist/cjs/web/fileMock.js")
|
|
124
|
-
}),
|
|
125
|
-
"~__CEDAR__USER_ROUTES_FOR_MOCK": cedarPaths.web.routes,
|
|
126
|
-
"~__CEDAR__USER_AUTH_FOR_MOCK": path.join(cedarPaths.web.src, "auth"),
|
|
127
|
-
// Support for importing files with extensions (like you'd do in ESM projects)
|
|
128
|
-
"^(\\.{1,2}/.*)\\.js$": "$1"
|
|
129
|
-
},
|
|
130
|
-
transform: {
|
|
131
|
-
// MSW's CommonJS build `require`s ESM-only packages (`rettime`,
|
|
132
|
-
// `@open-draft/deferred-promise` and `until-async`, which ships ESM in
|
|
133
|
-
// plain `.js` files). Node supports require(esm), but Jest's runtime
|
|
134
|
-
// doesn't, so compile any `.mjs` file that gets pulled in from
|
|
135
|
-
// node_modules (plus until-async) to CommonJS. This needs its own
|
|
136
|
-
// transform entry (with the config inlined) because the web babel config
|
|
137
|
-
// ignores node_modules
|
|
138
|
-
//
|
|
139
|
-
// The `@cedarjs/auth-*-web` packages are ESM-only too, and (like
|
|
140
|
-
// until-async) ship plain `.js` files rather than `.mjs` since their
|
|
141
|
-
// package.json already declares `"type": "module"`. A generated
|
|
142
|
-
// project's `web/src/auth.ts` imports one of these, so they need the
|
|
143
|
-
// same carve-out. `@cedarjs/forms` is ESM-only for the same reason, and
|
|
144
|
-
// gets pulled into virtually every generated project's web-side tests
|
|
145
|
-
// via `web/src/pages/**` scaffolds and dbAuth login/signup forms.
|
|
146
|
-
// `@cedarjs/web`, `@cedarjs/auth`, and `@cedarjs/router` are ESM-only
|
|
147
|
-
// too. `web` and `router` are imported directly by virtually every
|
|
148
|
-
// generated project's web-side test (`Routes.tsx`, page/component
|
|
149
|
-
// scaffolds), and `auth` gets pulled in transitively through `web`.
|
|
150
|
-
// Jest's own module loader re-applies this carve-out to every file it
|
|
151
|
-
// loads, including ones reached transitively through an
|
|
152
|
-
// already-transformed require() call, so all of them need to be listed
|
|
153
|
-
// even though only `web`/`router` are usually imported directly.
|
|
154
|
-
"[/\\\\]node_modules[/\\\\](?:.+\\.mjs|(?:until-async|@cedarjs[/\\\\](?:auth-[a-z-]+-web|forms|web|auth|router))[/\\\\].+\\.js)$": [
|
|
155
|
-
"babel-jest",
|
|
156
|
-
{
|
|
157
|
-
babelrc: false,
|
|
158
|
-
configFile: false,
|
|
159
|
-
presets: [
|
|
160
|
-
[require.resolve("@babel/preset-env"), { targets: { node: "20" } }]
|
|
161
|
-
]
|
|
162
|
-
}
|
|
163
|
-
],
|
|
164
|
-
"\\.[jt]sx?$": [
|
|
165
|
-
"babel-jest",
|
|
166
|
-
// When jest runs tests in parallel, it serializes the config before passing down options to babel
|
|
167
|
-
// that's why these must be serializable. Passing the reference to a config instead.
|
|
168
|
-
{
|
|
169
|
-
configFile: path.resolve(__dirname, "./webBabelConfig.js")
|
|
170
|
-
}
|
|
171
|
-
]
|
|
172
|
-
},
|
|
173
|
-
// Jest's default is to not transform anything in node_modules, but `.mjs`
|
|
174
|
-
// files (and until-async, @cedarjs/auth-*-web, @cedarjs/forms,
|
|
175
|
-
// @cedarjs/web, @cedarjs/auth, and @cedarjs/router) have to be compiled to
|
|
176
|
-
// CommonJS (see the transform above).
|
|
177
|
-
// The `.pnpm` lookahead is what makes this work with pnpm: its virtual store
|
|
178
|
-
// puts packages at `node_modules/.pnpm/<pkg>@<version>/node_modules/<pkg>`,
|
|
179
|
-
// so without it the pattern matches (and thereby ignores) at the *first*
|
|
180
|
-
// `node_modules` segment, where the following path starts with `.pnpm/`
|
|
181
|
-
// instead of `until-async/` and the exception never gets a chance to apply.
|
|
182
|
-
// Skipping that segment forces the match onto the inner `node_modules`,
|
|
183
|
-
// which looks the same as a hoisted npm/yarn layout
|
|
184
|
-
transformIgnorePatterns: [
|
|
185
|
-
"[/\\\\]node_modules[/\\\\](?!\\.pnpm[/\\\\])(?!.*\\.mjs$)(?!until-async[/\\\\])(?!@cedarjs[/\\\\]auth-[a-z-]+-web[/\\\\])(?!@cedarjs[/\\\\]forms[/\\\\])(?!@cedarjs[/\\\\]web[/\\\\])(?!@cedarjs[/\\\\]auth[/\\\\])(?!@cedarjs[/\\\\]router[/\\\\])",
|
|
186
|
-
"\\.pnp\\.[^\\\\/]+$"
|
|
187
|
-
],
|
|
188
|
-
resolver: path.resolve(__dirname, "./resolver.js"),
|
|
189
|
-
testPathIgnorePatterns: [".(stories|mock).[jt]sx?$"]
|
|
190
|
-
};
|
|
191
|
-
var jest_preset_default = config;
|
|
192
|
-
export {
|
|
193
|
-
jest_preset_default as default
|
|
194
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
2
|
-
import { mockCurrentUser as _mockCurrentUser } from '../../../web/mockRequests.js';
|
|
3
|
-
declare global {
|
|
4
|
-
var __RWJS_TESTROOT_DIR: string;
|
|
5
|
-
var mockCurrentUser: typeof _mockCurrentUser;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=jest.setup.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jest.setup.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/web/jest.setup.ts"],"names":[],"mappings":"AAEA,OAAO,2BAA2B,CAAA;AAGlC,OAAO,EAML,eAAe,IAAI,gBAAgB,EACpC,MAAM,8BAA8B,CAAA;AAErC,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,mBAAmB,EAAE,MAAM,CAAA;IAE/B,IAAI,eAAe,EAAE,OAAO,gBAAgB,CAAA;CAC7C"}
|