@cedarjs/testing 7.0.0-canary.2983 → 7.0.0-canary.2985
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/cjs/web/MockRouter.d.ts.map +1 -1
- package/dist/cjs/web/mockRequests.js +2 -2
- package/dist/web/MockRouter.d.ts.map +1 -1
- package/package.json +12 -53
- 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 -135
- 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/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 -135
- 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/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/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 -105
- 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,105 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { getApiSideDefaultBabelConfig } from "@cedarjs/babel-config";
|
|
3
|
-
import { getPaths } from "@cedarjs/project-config";
|
|
4
|
-
const rwjsPaths = getPaths();
|
|
5
|
-
const { babelrc } = getApiSideDefaultBabelConfig();
|
|
6
|
-
function resolveSubpath(specifier) {
|
|
7
|
-
try {
|
|
8
|
-
return require.resolve(specifier, {
|
|
9
|
-
paths: [rwjsPaths.api.base, rwjsPaths.base]
|
|
10
|
-
});
|
|
11
|
-
} catch {
|
|
12
|
-
return void 0;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const testingApiPath = resolveSubpath("@cedarjs/testing/api");
|
|
16
|
-
const config = {
|
|
17
|
-
// To make sure other config option which depends on rootDir use
|
|
18
|
-
// correct path, for example, coverageDirectory
|
|
19
|
-
rootDir: rwjsPaths.base,
|
|
20
|
-
roots: [path.join(rwjsPaths.api.src)],
|
|
21
|
-
runner: path.join(__dirname, "../jest-serial-runner.js"),
|
|
22
|
-
testEnvironment: path.join(__dirname, "./RedwoodApiJestEnv.js"),
|
|
23
|
-
globals: {
|
|
24
|
-
__CEDARJS__TEST_IMPORTS: {
|
|
25
|
-
apiSrcPath: rwjsPaths.api.src,
|
|
26
|
-
tearDownCachePath: path.join(
|
|
27
|
-
rwjsPaths.generated.base,
|
|
28
|
-
"scenarioTeardown.json"
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
sandboxInjectedGlobals: ["__CEDARJS__TEST_IMPORTS"],
|
|
33
|
-
displayName: {
|
|
34
|
-
color: "redBright",
|
|
35
|
-
name: "api"
|
|
36
|
-
},
|
|
37
|
-
collectCoverageFrom: [
|
|
38
|
-
"**/*.{js,jsx,ts,tsx,mts,cts}",
|
|
39
|
-
"!**/node_modules/**",
|
|
40
|
-
"!**/dist/**"
|
|
41
|
-
],
|
|
42
|
-
coverageDirectory: path.join(rwjsPaths.base, "coverage"),
|
|
43
|
-
watchPlugins: [
|
|
44
|
-
"jest-watch-typeahead/filename",
|
|
45
|
-
"jest-watch-typeahead/testname"
|
|
46
|
-
],
|
|
47
|
-
// This runs once before all tests
|
|
48
|
-
globalSetup: path.join(__dirname, "./globalSetup.js"),
|
|
49
|
-
// Note this setup runs for each test file!
|
|
50
|
-
setupFilesAfterEnv: [path.join(__dirname, "./jest.setup.js")],
|
|
51
|
-
moduleNameMapper: {
|
|
52
|
-
"^api/(.*)$": path.join(rwjsPaths.base, "api/$1"),
|
|
53
|
-
"^src/(.*)$": path.join(rwjsPaths.api.src, "$1"),
|
|
54
|
-
// @NOTE: Import @cedarjs/testing in api tests, and it automatically remaps to the api side only
|
|
55
|
-
// This is to prevent web stuff leaking into api, and vice versa
|
|
56
|
-
...testingApiPath ? { "^@cedarjs/testing$": testingApiPath } : {},
|
|
57
|
-
// Support for importing files with extensions (like you'd do in ESM projects)
|
|
58
|
-
"^(\\.{1,2}/.*)\\.js$": "$1"
|
|
59
|
-
},
|
|
60
|
-
transform: {
|
|
61
|
-
// `@cedarjs/context`, `@cedarjs/api`, `@cedarjs/graphql-server`, and
|
|
62
|
-
// `@cedarjs/storage` are ESM-only. Two things pull them in at the top
|
|
63
|
-
// level of a generated project's api-side test run: @cedarjs/testing's
|
|
64
|
-
// own api entry point (which virtually every test imports, for
|
|
65
|
-
// scenario/mock helpers — pulls in `@cedarjs/context` and
|
|
66
|
-
// `@cedarjs/graphql-server` via `directive.ts`, and
|
|
67
|
-
// `@cedarjs/api/webhooks` via `apiFunction.ts`), and the *user's own*
|
|
68
|
-
// generated code — the `cedar setup uploads` template imports
|
|
69
|
-
// `@cedarjs/storage`. Jest's CJS runtime can't parse the real ESM these
|
|
70
|
-
// now emit, so they need the same babel-jest carve-out the web preset
|
|
71
|
-
// already uses for ESM-only node_modules packages (see jest-preset.ts
|
|
72
|
-
// on the web side for the fuller explanation of why this is
|
|
73
|
-
// necessary).
|
|
74
|
-
"[/\\\\]node_modules[/\\\\]@cedarjs[/\\\\](context|api|graphql-server|storage)[/\\\\].+\\.js$": [
|
|
75
|
-
"babel-jest",
|
|
76
|
-
{
|
|
77
|
-
babelrc: false,
|
|
78
|
-
configFile: false,
|
|
79
|
-
presets: [
|
|
80
|
-
[require.resolve("@babel/preset-env"), { targets: { node: "20" } }]
|
|
81
|
-
]
|
|
82
|
-
}
|
|
83
|
-
],
|
|
84
|
-
"\\.[cm]?[jt]sx?$": [
|
|
85
|
-
"babel-jest",
|
|
86
|
-
// When jest runs tests in parallel, it serializes the config before passing down options to babel
|
|
87
|
-
// that's why these must be serializable. So ideally, we should just pass reference to a
|
|
88
|
-
// configFile or "extends" a config. But we need a few other option only at root level, so we'll pass
|
|
89
|
-
// here and remove those keys inside "extend"ed config.
|
|
90
|
-
{
|
|
91
|
-
babelrc,
|
|
92
|
-
// babelrc can not reside inside "extend"ed config, that's why we have it here
|
|
93
|
-
configFile: path.resolve(__dirname, "./apiBabelConfig.js")
|
|
94
|
-
}
|
|
95
|
-
]
|
|
96
|
-
},
|
|
97
|
-
transformIgnorePatterns: [
|
|
98
|
-
"[/\\\\]node_modules[/\\\\](?!@cedarjs[/\\\\]context[/\\\\])(?!@cedarjs[/\\\\]api[/\\\\])(?!@cedarjs[/\\\\]graphql-server[/\\\\])(?!@cedarjs[/\\\\]storage[/\\\\])"
|
|
99
|
-
],
|
|
100
|
-
testPathIgnorePatterns: [".scenarios.[jt]s$"]
|
|
101
|
-
};
|
|
102
|
-
var jest_preset_default = config;
|
|
103
|
-
export {
|
|
104
|
-
jest_preset_default as default
|
|
105
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jest.setup.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/api/jest.setup.ts"],"names":[],"mappings":""}
|
|
@@ -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"}
|