@cedarjs/testing 6.0.0-canary.2672 → 6.0.0-canary.2675
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/web/RedwoodWebJestEnv.d.ts +2 -2
- package/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -1
- package/config/jest/web/RedwoodWebJestEnv.js +12 -7
- package/config/jest/web/jest-fixed-jsdom.d.js +1 -0
- package/config/jest/web/jest-preset.d.ts.map +1 -1
- package/config/jest/web/jest-preset.js +27 -0
- package/config/jest/web/jest.setup.d.ts +0 -1
- package/config/jest/web/jest.setup.d.ts.map +1 -1
- package/config/jest/web/jest.setup.js +0 -1
- package/dist/api/vitest/CedarApiVitestEnv.js +1 -1
- package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.js +7 -7
- package/dist/api/vitest/vitest-api.setup.js +4 -4
- package/dist/cjs/api/vitest/CedarApiVitestEnv.js +1 -1
- package/dist/cjs/api/vitest/vite-plugin-cedar-vitest-api-config.js +7 -7
- package/dist/cjs/api/vitest/vitest-api.setup.js +4 -4
- package/dist/cjs/config/jest/web/RedwoodWebJestEnv.d.ts +2 -2
- package/dist/cjs/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -1
- package/dist/cjs/config/jest/web/RedwoodWebJestEnv.js +12 -7
- package/dist/cjs/config/jest/web/jest-fixed-jsdom.d.js +1 -0
- package/dist/cjs/config/jest/web/jest-preset.d.ts.map +1 -1
- package/dist/cjs/config/jest/web/jest-preset.js +27 -0
- package/dist/cjs/config/jest/web/jest.setup.d.ts +0 -1
- package/dist/cjs/config/jest/web/jest.setup.d.ts.map +1 -1
- package/dist/cjs/config/jest/web/jest.setup.js +0 -1
- package/dist/cjs/web/mockRequests.d.ts +60 -18
- package/dist/cjs/web/mockRequests.d.ts.map +1 -1
- package/dist/cjs/web/mockRequests.js +106 -36
- package/dist/config/jest/web/RedwoodWebJestEnv.d.ts +2 -2
- package/dist/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -1
- package/dist/config/jest/web/RedwoodWebJestEnv.js +2 -7
- package/dist/config/jest/web/jest-fixed-jsdom.d.js +0 -0
- package/dist/config/jest/web/jest-preset.d.ts.map +1 -1
- package/dist/config/jest/web/jest-preset.js +27 -0
- package/dist/config/jest/web/jest.setup.d.ts +0 -1
- package/dist/config/jest/web/jest.setup.d.ts.map +1 -1
- package/dist/config/jest/web/jest.setup.js +0 -1
- package/dist/web/mockRequests.d.ts +60 -18
- package/dist/web/mockRequests.d.ts.map +1 -1
- package/dist/web/mockRequests.js +107 -37
- package/package.json +15 -14
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare class RedwoodWebJestEnvironment extends
|
|
1
|
+
import JSDOMEnvironment from 'jest-fixed-jsdom';
|
|
2
|
+
declare class RedwoodWebJestEnvironment extends JSDOMEnvironment {
|
|
3
3
|
setup(): Promise<void>;
|
|
4
4
|
}
|
|
5
5
|
export default RedwoodWebJestEnvironment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedwoodWebJestEnv.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/web/RedwoodWebJestEnv.ts"],"names":[],"mappings":"
|
|
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,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,21 +17,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var RedwoodWebJestEnv_exports = {};
|
|
20
30
|
__export(RedwoodWebJestEnv_exports, {
|
|
21
31
|
default: () => RedwoodWebJestEnv_default
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(RedwoodWebJestEnv_exports);
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
class RedwoodWebJestEnvironment extends import_jest_environment_jsdom.TestEnvironment {
|
|
34
|
+
var import_jest_fixed_jsdom = __toESM(require("jest-fixed-jsdom"), 1);
|
|
35
|
+
class RedwoodWebJestEnvironment extends import_jest_fixed_jsdom.default {
|
|
27
36
|
async setup() {
|
|
28
37
|
await super.setup();
|
|
29
|
-
if (typeof this.global.TextEncoder === "undefined") {
|
|
30
|
-
this.global.TextEncoder = import_node_util.TextEncoder;
|
|
31
|
-
this.global.TextDecoder = import_node_util.TextDecoder;
|
|
32
|
-
}
|
|
33
38
|
if (typeof this.global.crypto.subtle === "undefined") {
|
|
34
39
|
this.global.crypto.subtle = {};
|
|
35
40
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/web/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAOlC,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/web/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAOlC,QAAA,MAAM,MAAM,EAAE,MAkHb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -40,6 +40,9 @@ const config = {
|
|
|
40
40
|
// use correct path, for example, coverageDirectory
|
|
41
41
|
rootDir: cedarPaths.base,
|
|
42
42
|
roots: [import_node_path.default.join(cedarPaths.web.src)],
|
|
43
|
+
// Opting out of jsdom's browser-style export condition resolution (needed to
|
|
44
|
+
// resolve `msw/node`) is handled by the environment itself, via
|
|
45
|
+
// jest-fixed-jsdom
|
|
43
46
|
testEnvironment: import_node_path.default.join(__dirname, "./RedwoodWebJestEnv.js"),
|
|
44
47
|
displayName: {
|
|
45
48
|
color: "blueBright",
|
|
@@ -109,6 +112,23 @@ const config = {
|
|
|
109
112
|
"^(\\.{1,2}/.*)\\.js$": "$1"
|
|
110
113
|
},
|
|
111
114
|
transform: {
|
|
115
|
+
// MSW's CommonJS build `require`s ESM-only packages (`rettime`,
|
|
116
|
+
// `@open-draft/deferred-promise` and `until-async`, which ships ESM in
|
|
117
|
+
// plain `.js` files). Node supports require(esm), but Jest's runtime
|
|
118
|
+
// doesn't, so compile any `.mjs` file that gets pulled in from
|
|
119
|
+
// node_modules (plus until-async) to CommonJS. This needs its own
|
|
120
|
+
// transform entry (with the config inlined) because the web babel config
|
|
121
|
+
// ignores node_modules
|
|
122
|
+
"[/\\\\]node_modules[/\\\\](?:.+\\.mjs|until-async[/\\\\].+\\.js)$": [
|
|
123
|
+
"babel-jest",
|
|
124
|
+
{
|
|
125
|
+
babelrc: false,
|
|
126
|
+
configFile: false,
|
|
127
|
+
presets: [
|
|
128
|
+
[require.resolve("@babel/preset-env"), { targets: { node: "20" } }]
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
],
|
|
112
132
|
"\\.[jt]sx?$": [
|
|
113
133
|
"babel-jest",
|
|
114
134
|
// When jest runs tests in parallel, it serializes the config before passing down options to babel
|
|
@@ -118,6 +138,13 @@ const config = {
|
|
|
118
138
|
}
|
|
119
139
|
]
|
|
120
140
|
},
|
|
141
|
+
// Jest's default is to not transform anything in node_modules, but `.mjs`
|
|
142
|
+
// files (and until-async) have to be compiled to CommonJS (see the
|
|
143
|
+
// transform above)
|
|
144
|
+
transformIgnorePatterns: [
|
|
145
|
+
"[/\\\\]node_modules[/\\\\](?!.*\\.mjs$)(?!until-async[/\\\\])",
|
|
146
|
+
"\\.pnp\\.[^\\\\/]+$"
|
|
147
|
+
],
|
|
121
148
|
resolver: import_node_path.default.resolve(__dirname, "./resolver.js"),
|
|
122
149
|
testPathIgnorePatterns: [".(stories|mock).[jt]sx?$"]
|
|
123
150
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest.setup.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/web/jest.setup.ts"],"names":[],"mappings":"AAEA,OAAO,2BAA2B,CAAA;
|
|
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"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var import_jest_dom = require("@testing-library/jest-dom");
|
|
3
|
-
var import_whatwg_fetch = require("whatwg-fetch");
|
|
4
3
|
var import_findCellMocks = require("@cedarjs/testing/dist/cjs/web/findCellMocks.js");
|
|
5
4
|
var import_mockRequests = require("@cedarjs/testing/dist/cjs/web/mockRequests.js");
|
|
6
5
|
global.mockGraphQLQuery = import_mockRequests.mockGraphQLQuery;
|
|
@@ -5,7 +5,7 @@ import { getPaths } from "@cedarjs/project-config";
|
|
|
5
5
|
import { getPackageManager } from "@cedarjs/project-config/packageManager";
|
|
6
6
|
const CedarApiVitestEnvironment = {
|
|
7
7
|
name: "cedar-api",
|
|
8
|
-
|
|
8
|
+
viteEnvironment: "ssr",
|
|
9
9
|
async setup() {
|
|
10
10
|
if (process.env.SKIP_DB_PUSH === "1") {
|
|
11
11
|
return {
|
|
@@ -16,13 +16,13 @@ function cedarVitestApiConfigPlugin() {
|
|
|
16
16
|
},
|
|
17
17
|
test: {
|
|
18
18
|
environment: path.join(import.meta.dirname, "CedarApiVitestEnv.js"),
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
|
|
19
|
+
// All api test files share a single test database, so they can't
|
|
20
|
+
// run in parallel. In Vitest 3 project-level fileParallelism didn't
|
|
21
|
+
// work (https://github.com/vitest-dev/vitest/discussions/7416) and
|
|
22
|
+
// we used the now-removed `poolOptions: { forks: { singleFork:
|
|
23
|
+
// true } }` as a workaround. Vitest 4 removed `poolOptions` and
|
|
24
|
+
// supports `fileParallelism` in project configs.
|
|
25
|
+
fileParallelism: false,
|
|
26
26
|
setupFiles: [path.join(import.meta.dirname, "vitest-api.setup.js")]
|
|
27
27
|
}
|
|
28
28
|
};
|
|
@@ -60,8 +60,8 @@ function buildScenario(itFunc) {
|
|
|
60
60
|
} else {
|
|
61
61
|
throw new Error("scenario() requires 2 or 3 arguments");
|
|
62
62
|
}
|
|
63
|
-
return itFunc(testName, async (
|
|
64
|
-
const testPath =
|
|
63
|
+
return itFunc(testName, async ({ task }) => {
|
|
64
|
+
const testPath = task.file.filepath;
|
|
65
65
|
const { scenario } = await loadScenarios(testPath, scenarioName);
|
|
66
66
|
const scenarioData = await seedScenario(scenario);
|
|
67
67
|
try {
|
|
@@ -89,8 +89,8 @@ function buildDescribeScenario(describeFunc) {
|
|
|
89
89
|
}
|
|
90
90
|
return describeFunc(describeBlockName, () => {
|
|
91
91
|
let scenarioData;
|
|
92
|
-
beforeAll(async (
|
|
93
|
-
const testPath =
|
|
92
|
+
beforeAll(async ({}, suite) => {
|
|
93
|
+
const testPath = suite.file.filepath;
|
|
94
94
|
const { scenario } = await loadScenarios(testPath, scenarioName);
|
|
95
95
|
scenarioData = await seedScenario(scenario);
|
|
96
96
|
});
|
|
@@ -38,7 +38,7 @@ var import_project_config = require("@cedarjs/project-config");
|
|
|
38
38
|
var import_packageManager = require("@cedarjs/project-config/packageManager");
|
|
39
39
|
const CedarApiVitestEnvironment = {
|
|
40
40
|
name: "cedar-api",
|
|
41
|
-
|
|
41
|
+
viteEnvironment: "ssr",
|
|
42
42
|
async setup() {
|
|
43
43
|
if (process.env.SKIP_DB_PUSH === "1") {
|
|
44
44
|
return {
|
|
@@ -50,13 +50,13 @@ function cedarVitestApiConfigPlugin() {
|
|
|
50
50
|
},
|
|
51
51
|
test: {
|
|
52
52
|
environment: import_node_path.default.join(import_meta.dirname, "CedarApiVitestEnv.js"),
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
|
|
53
|
+
// All api test files share a single test database, so they can't
|
|
54
|
+
// run in parallel. In Vitest 3 project-level fileParallelism didn't
|
|
55
|
+
// work (https://github.com/vitest-dev/vitest/discussions/7416) and
|
|
56
|
+
// we used the now-removed `poolOptions: { forks: { singleFork:
|
|
57
|
+
// true } }` as a workaround. Vitest 4 removed `poolOptions` and
|
|
58
|
+
// supports `fileParallelism` in project configs.
|
|
59
|
+
fileParallelism: false,
|
|
60
60
|
setupFiles: [import_node_path.default.join(import_meta.dirname, "vitest-api.setup.js")]
|
|
61
61
|
}
|
|
62
62
|
};
|
|
@@ -83,8 +83,8 @@ function buildScenario(itFunc) {
|
|
|
83
83
|
} else {
|
|
84
84
|
throw new Error("scenario() requires 2 or 3 arguments");
|
|
85
85
|
}
|
|
86
|
-
return itFunc(testName, async (
|
|
87
|
-
const testPath =
|
|
86
|
+
return itFunc(testName, async ({ task }) => {
|
|
87
|
+
const testPath = task.file.filepath;
|
|
88
88
|
const { scenario } = await loadScenarios(testPath, scenarioName);
|
|
89
89
|
const scenarioData = await seedScenario(scenario);
|
|
90
90
|
try {
|
|
@@ -112,8 +112,8 @@ function buildDescribeScenario(describeFunc) {
|
|
|
112
112
|
}
|
|
113
113
|
return describeFunc(describeBlockName, () => {
|
|
114
114
|
let scenarioData;
|
|
115
|
-
(0, import_vitest.beforeAll)(async (
|
|
116
|
-
const testPath =
|
|
115
|
+
(0, import_vitest.beforeAll)(async ({}, suite) => {
|
|
116
|
+
const testPath = suite.file.filepath;
|
|
117
117
|
const { scenario } = await loadScenarios(testPath, scenarioName);
|
|
118
118
|
scenarioData = await seedScenario(scenario);
|
|
119
119
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare class RedwoodWebJestEnvironment extends
|
|
1
|
+
import JSDOMEnvironment from 'jest-fixed-jsdom';
|
|
2
|
+
declare class RedwoodWebJestEnvironment extends JSDOMEnvironment {
|
|
3
3
|
setup(): Promise<void>;
|
|
4
4
|
}
|
|
5
5
|
export default RedwoodWebJestEnvironment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedwoodWebJestEnv.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/web/RedwoodWebJestEnv.ts"],"names":[],"mappings":"
|
|
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,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,21 +17,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var RedwoodWebJestEnv_exports = {};
|
|
20
30
|
__export(RedwoodWebJestEnv_exports, {
|
|
21
31
|
default: () => RedwoodWebJestEnv_default
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(RedwoodWebJestEnv_exports);
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
class RedwoodWebJestEnvironment extends import_jest_environment_jsdom.TestEnvironment {
|
|
34
|
+
var import_jest_fixed_jsdom = __toESM(require("jest-fixed-jsdom"), 1);
|
|
35
|
+
class RedwoodWebJestEnvironment extends import_jest_fixed_jsdom.default {
|
|
27
36
|
async setup() {
|
|
28
37
|
await super.setup();
|
|
29
|
-
if (typeof this.global.TextEncoder === "undefined") {
|
|
30
|
-
this.global.TextEncoder = import_node_util.TextEncoder;
|
|
31
|
-
this.global.TextDecoder = import_node_util.TextDecoder;
|
|
32
|
-
}
|
|
33
38
|
if (typeof this.global.crypto.subtle === "undefined") {
|
|
34
39
|
this.global.crypto.subtle = {};
|
|
35
40
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/web/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAOlC,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/web/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAOlC,QAAA,MAAM,MAAM,EAAE,MAkHb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -40,6 +40,9 @@ const config = {
|
|
|
40
40
|
// use correct path, for example, coverageDirectory
|
|
41
41
|
rootDir: cedarPaths.base,
|
|
42
42
|
roots: [import_node_path.default.join(cedarPaths.web.src)],
|
|
43
|
+
// Opting out of jsdom's browser-style export condition resolution (needed to
|
|
44
|
+
// resolve `msw/node`) is handled by the environment itself, via
|
|
45
|
+
// jest-fixed-jsdom
|
|
43
46
|
testEnvironment: import_node_path.default.join(__dirname, "./RedwoodWebJestEnv.js"),
|
|
44
47
|
displayName: {
|
|
45
48
|
color: "blueBright",
|
|
@@ -109,6 +112,23 @@ const config = {
|
|
|
109
112
|
"^(\\.{1,2}/.*)\\.js$": "$1"
|
|
110
113
|
},
|
|
111
114
|
transform: {
|
|
115
|
+
// MSW's CommonJS build `require`s ESM-only packages (`rettime`,
|
|
116
|
+
// `@open-draft/deferred-promise` and `until-async`, which ships ESM in
|
|
117
|
+
// plain `.js` files). Node supports require(esm), but Jest's runtime
|
|
118
|
+
// doesn't, so compile any `.mjs` file that gets pulled in from
|
|
119
|
+
// node_modules (plus until-async) to CommonJS. This needs its own
|
|
120
|
+
// transform entry (with the config inlined) because the web babel config
|
|
121
|
+
// ignores node_modules
|
|
122
|
+
"[/\\\\]node_modules[/\\\\](?:.+\\.mjs|until-async[/\\\\].+\\.js)$": [
|
|
123
|
+
"babel-jest",
|
|
124
|
+
{
|
|
125
|
+
babelrc: false,
|
|
126
|
+
configFile: false,
|
|
127
|
+
presets: [
|
|
128
|
+
[require.resolve("@babel/preset-env"), { targets: { node: "20" } }]
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
],
|
|
112
132
|
"\\.[jt]sx?$": [
|
|
113
133
|
"babel-jest",
|
|
114
134
|
// When jest runs tests in parallel, it serializes the config before passing down options to babel
|
|
@@ -118,6 +138,13 @@ const config = {
|
|
|
118
138
|
}
|
|
119
139
|
]
|
|
120
140
|
},
|
|
141
|
+
// Jest's default is to not transform anything in node_modules, but `.mjs`
|
|
142
|
+
// files (and until-async) have to be compiled to CommonJS (see the
|
|
143
|
+
// transform above)
|
|
144
|
+
transformIgnorePatterns: [
|
|
145
|
+
"[/\\\\]node_modules[/\\\\](?!.*\\.mjs$)(?!until-async[/\\\\])",
|
|
146
|
+
"\\.pnp\\.[^\\\\/]+$"
|
|
147
|
+
],
|
|
121
148
|
resolver: import_node_path.default.resolve(__dirname, "./resolver.js"),
|
|
122
149
|
testPathIgnorePatterns: [".(stories|mock).[jt]sx?$"]
|
|
123
150
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest.setup.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/web/jest.setup.ts"],"names":[],"mappings":"AAEA,OAAO,2BAA2B,CAAA;
|
|
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"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var import_jest_dom = require("@testing-library/jest-dom");
|
|
3
|
-
var import_whatwg_fetch = require("whatwg-fetch");
|
|
4
3
|
var import_findCellMocks = require("../../../web/findCellMocks.js");
|
|
5
4
|
var import_mockRequests = require("../../../web/mockRequests.js");
|
|
6
5
|
global.mockGraphQLQuery = import_mockRequests.mockGraphQLQuery;
|
|
@@ -1,25 +1,67 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import type { RequestHandler, SharedOptions } from 'msw';
|
|
2
|
+
import type { StartOptions as StartMSWWorkerOptions } from 'msw/browser';
|
|
3
|
+
interface MockServerCommonApi {
|
|
4
|
+
use(...handlers: any[]): void;
|
|
5
|
+
resetHandlers(): void;
|
|
6
|
+
}
|
|
7
|
+
type MockWorkerInstance = MockServerCommonApi & {
|
|
8
|
+
stop(): void;
|
|
9
|
+
};
|
|
10
|
+
type MockServerInstance = MockServerCommonApi & {
|
|
11
|
+
listen(options?: Partial<SharedOptions>): void;
|
|
12
|
+
close(): void;
|
|
13
|
+
};
|
|
14
|
+
type StartOptions<Target> = Target extends 'browsers' ? StartMSWWorkerOptions : Partial<SharedOptions>;
|
|
15
|
+
export declare const startMSW: <Target extends "node" | "browsers">(target: Target, options?: StartOptions<Target>) => Promise<MockWorkerInstance | MockServerInstance>;
|
|
10
16
|
export declare const setupRequestHandlers: () => void;
|
|
11
17
|
export declare const closeServer: () => void;
|
|
12
18
|
export declare const registerHandler: (handler: RequestHandler) => void;
|
|
19
|
+
/**
|
|
20
|
+
* The `ctx` object passed to mock-data functions. It mirrors the API of MSW
|
|
21
|
+
* v1's GraphQL context so that existing Cedar mocks keep working with MSW v2,
|
|
22
|
+
* where the `(req, res, ctx)` resolver signature no longer exists.
|
|
23
|
+
*/
|
|
24
|
+
export interface MockGraphQLContext {
|
|
25
|
+
/** Set the http response status code (and optionally status text) */
|
|
26
|
+
status(code: number, text?: string): void;
|
|
27
|
+
/** Delay the response by the given number of milliseconds */
|
|
28
|
+
delay(durationMs: number): void;
|
|
29
|
+
/** Return GraphQL errors in the response */
|
|
30
|
+
errors(errorList: Record<string, unknown>[]): void;
|
|
31
|
+
/** Set a response header. Accepts a name/value pair or an object */
|
|
32
|
+
set(name: string | Record<string, string>, value?: string): void;
|
|
33
|
+
/** Set a response cookie */
|
|
34
|
+
cookie(name: string, value: string): void;
|
|
35
|
+
/** Set the `extensions` field of the GraphQL response */
|
|
36
|
+
extensions(extensions: Record<string, unknown>): void;
|
|
37
|
+
/** Set an arbitrary field on the GraphQL response body */
|
|
38
|
+
field(fieldName: string, value: unknown): void;
|
|
39
|
+
/** Set the `data` field of the response. Overrides the returned mock-data */
|
|
40
|
+
data(data: Record<string, unknown>): void;
|
|
41
|
+
/** Perform a request that bypasses any mock handlers */
|
|
42
|
+
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Information about the intercepted GraphQL request, passed to mock-data
|
|
46
|
+
* functions as `req`
|
|
47
|
+
*/
|
|
48
|
+
export interface MockGraphQLRequest {
|
|
49
|
+
/** The intercepted Fetch API `Request` */
|
|
50
|
+
request: Request;
|
|
51
|
+
/** The GraphQL query document string */
|
|
52
|
+
query: string;
|
|
53
|
+
operationName: string;
|
|
54
|
+
variables: Record<string, any>;
|
|
55
|
+
cookies: Record<string, string>;
|
|
56
|
+
url: URL;
|
|
57
|
+
headers: Headers;
|
|
58
|
+
method: string;
|
|
59
|
+
}
|
|
13
60
|
export type DataFunction<Query extends Record<string, unknown> = Record<string, unknown>, QueryVariables = Record<string, any>> = (variables: QueryVariables, { req, ctx, }: {
|
|
14
|
-
req:
|
|
15
|
-
ctx:
|
|
16
|
-
}) => Query | void
|
|
17
|
-
type
|
|
18
|
-
type ResponseEnhancers = {
|
|
19
|
-
once: ResponseFunction<any>;
|
|
20
|
-
networkError: (message: string) => void;
|
|
21
|
-
};
|
|
22
|
-
type ResponseEnhancer = keyof ResponseEnhancers;
|
|
61
|
+
req: MockGraphQLRequest;
|
|
62
|
+
ctx: MockGraphQLContext;
|
|
63
|
+
}) => Query | void | Promise<Query | void>;
|
|
64
|
+
type ResponseEnhancer = 'once' | 'networkError';
|
|
23
65
|
export declare const mockGraphQLQuery: <Query extends Record<string, unknown> = Record<string, unknown>, QueryVariables = Record<string, any>>(operation: string, data: DataFunction<Query, QueryVariables> | Query, responseEnhancer?: ResponseEnhancer) => Record<string, any> | DataFunction<Record<string, unknown>, Record<string, any>>;
|
|
24
66
|
export declare const mockGraphQLMutation: <Query extends Record<string, unknown> = Record<string, unknown>, QueryVariables = Record<string, any>>(operation: string, data: DataFunction<Query, QueryVariables> | Query, responseEnhancer?: ResponseEnhancer) => Record<string, any> | DataFunction<Record<string, unknown>, Record<string, any>>;
|
|
25
67
|
export declare const mockedUserMeta: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockRequests.d.ts","sourceRoot":"","sources":["../../../src/web/mockRequests.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3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
|
|
44
|
+
const MSW_NODE_SPECIFIER = "msw/node";
|
|
44
45
|
const startMSW = async (target, options) => {
|
|
45
46
|
if (SERVER_INSTANCE) {
|
|
46
47
|
return SERVER_INSTANCE;
|
|
47
48
|
}
|
|
48
49
|
if (target === "browsers") {
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
const { setupWorker } = require("msw/browser");
|
|
51
|
+
const worker = setupWorker();
|
|
52
|
+
SERVER_INSTANCE = worker;
|
|
53
|
+
await worker.start(options);
|
|
51
54
|
} else {
|
|
52
|
-
const { setupServer } = require(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const { setupServer } = require(
|
|
56
|
+
/* @vite-ignore */
|
|
57
|
+
MSW_NODE_SPECIFIER
|
|
58
|
+
);
|
|
59
|
+
const server = setupServer();
|
|
60
|
+
SERVER_INSTANCE = server;
|
|
61
|
+
server.listen(options);
|
|
55
62
|
}
|
|
56
63
|
return SERVER_INSTANCE;
|
|
57
64
|
};
|
|
58
65
|
const setupRequestHandlers = () => {
|
|
59
|
-
SERVER_INSTANCE
|
|
66
|
+
SERVER_INSTANCE?.resetHandlers();
|
|
60
67
|
for (const handler of REQUEST_HANDLER_QUEUE) {
|
|
61
|
-
SERVER_INSTANCE
|
|
68
|
+
SERVER_INSTANCE?.use(handler);
|
|
62
69
|
}
|
|
63
70
|
};
|
|
64
71
|
const closeServer = () => {
|
|
65
|
-
SERVER_INSTANCE
|
|
72
|
+
if (!SERVER_INSTANCE) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if ("close" in SERVER_INSTANCE) {
|
|
76
|
+
SERVER_INSTANCE.close();
|
|
77
|
+
} else {
|
|
78
|
+
SERVER_INSTANCE.stop();
|
|
79
|
+
}
|
|
66
80
|
};
|
|
67
81
|
const registerHandler = (handler) => {
|
|
68
82
|
if (!SERVER_INSTANCE) {
|
|
@@ -72,39 +86,95 @@ const registerHandler = (handler) => {
|
|
|
72
86
|
}
|
|
73
87
|
};
|
|
74
88
|
const mockGraphQL = (type, operation, data, responseEnhancer) => {
|
|
75
|
-
const resolver = (
|
|
76
|
-
|
|
77
|
-
|
|
89
|
+
const resolver = async ({
|
|
90
|
+
request,
|
|
91
|
+
query,
|
|
92
|
+
operationName,
|
|
93
|
+
variables,
|
|
94
|
+
cookies
|
|
95
|
+
}) => {
|
|
96
|
+
let d = void 0;
|
|
97
|
+
let status = 200;
|
|
98
|
+
let statusText;
|
|
99
|
+
let delayDurationMs;
|
|
100
|
+
let errorList;
|
|
101
|
+
let extensions;
|
|
102
|
+
let explicitData;
|
|
103
|
+
const extraFields = {};
|
|
104
|
+
const headers = new Headers();
|
|
78
105
|
if (typeof data === "function") {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
106
|
+
const ctx = {
|
|
107
|
+
status: (code, text) => {
|
|
108
|
+
status = code;
|
|
109
|
+
statusText = text;
|
|
110
|
+
},
|
|
111
|
+
delay: (durationMs) => {
|
|
112
|
+
delayDurationMs = durationMs;
|
|
113
|
+
},
|
|
114
|
+
errors: (errors) => {
|
|
115
|
+
errorList = errors;
|
|
116
|
+
},
|
|
117
|
+
set: (name, value) => {
|
|
118
|
+
if (typeof name === "object") {
|
|
119
|
+
for (const [headerName, headerValue] of Object.entries(name)) {
|
|
120
|
+
headers.set(headerName, headerValue);
|
|
121
|
+
}
|
|
122
|
+
} else if (typeof value !== "undefined") {
|
|
123
|
+
headers.set(name, value);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
cookie: (name, value) => {
|
|
127
|
+
headers.append("Set-Cookie", `${name}=${value}`);
|
|
128
|
+
},
|
|
129
|
+
extensions: (ext) => {
|
|
130
|
+
extensions = ext;
|
|
131
|
+
},
|
|
132
|
+
field: (fieldName, value) => {
|
|
133
|
+
extraFields[fieldName] = value;
|
|
134
|
+
},
|
|
135
|
+
data: (dataValue) => {
|
|
136
|
+
explicitData = dataValue;
|
|
137
|
+
},
|
|
138
|
+
fetch: (input, init) => fetch((0, import_msw.bypass)(input, init))
|
|
85
139
|
};
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
field: captureTransform(ctx.field)
|
|
140
|
+
const req = {
|
|
141
|
+
request,
|
|
142
|
+
query,
|
|
143
|
+
operationName,
|
|
144
|
+
variables,
|
|
145
|
+
cookies,
|
|
146
|
+
url: new URL(request.url),
|
|
147
|
+
headers: request.headers,
|
|
148
|
+
method: request.method
|
|
96
149
|
};
|
|
97
|
-
d = data(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
150
|
+
d = await data(variables, { req, ctx });
|
|
151
|
+
} else {
|
|
152
|
+
d = data;
|
|
101
153
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
)
|
|
154
|
+
if (responseEnhancer === "networkError") {
|
|
155
|
+
return import_msw.HttpResponse.error();
|
|
156
|
+
}
|
|
157
|
+
if (typeof delayDurationMs !== "undefined") {
|
|
158
|
+
await (0, import_msw.delay)(delayDurationMs);
|
|
159
|
+
}
|
|
160
|
+
const body = { ...extraFields };
|
|
161
|
+
const bodyData = explicitData ?? d;
|
|
162
|
+
if (typeof bodyData !== "undefined") {
|
|
163
|
+
body.data = bodyData;
|
|
164
|
+
}
|
|
165
|
+
if (typeof errorList !== "undefined") {
|
|
166
|
+
body.errors = errorList;
|
|
167
|
+
}
|
|
168
|
+
if (typeof extensions !== "undefined") {
|
|
169
|
+
body.extensions = extensions;
|
|
170
|
+
}
|
|
171
|
+
return import_msw.HttpResponse.json(body, { status, statusText, headers });
|
|
106
172
|
};
|
|
107
|
-
registerHandler(
|
|
173
|
+
registerHandler(
|
|
174
|
+
import_msw.graphql[type](operation, resolver, {
|
|
175
|
+
once: responseEnhancer === "once"
|
|
176
|
+
})
|
|
177
|
+
);
|
|
108
178
|
return data;
|
|
109
179
|
};
|
|
110
180
|
const mockGraphQLQuery = (operation, data, responseEnhancer) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare class RedwoodWebJestEnvironment extends
|
|
1
|
+
import JSDOMEnvironment from 'jest-fixed-jsdom';
|
|
2
|
+
declare class RedwoodWebJestEnvironment extends JSDOMEnvironment {
|
|
3
3
|
setup(): Promise<void>;
|
|
4
4
|
}
|
|
5
5
|
export default RedwoodWebJestEnvironment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedwoodWebJestEnv.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/web/RedwoodWebJestEnv.ts"],"names":[],"mappings":"
|
|
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,12 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
class RedwoodWebJestEnvironment extends TestEnvironment {
|
|
1
|
+
import JSDOMEnvironment from "jest-fixed-jsdom";
|
|
2
|
+
class RedwoodWebJestEnvironment extends JSDOMEnvironment {
|
|
4
3
|
async setup() {
|
|
5
4
|
await super.setup();
|
|
6
|
-
if (typeof this.global.TextEncoder === "undefined") {
|
|
7
|
-
this.global.TextEncoder = TextEncoder;
|
|
8
|
-
this.global.TextDecoder = TextDecoder;
|
|
9
|
-
}
|
|
10
5
|
if (typeof this.global.crypto.subtle === "undefined") {
|
|
11
6
|
this.global.crypto.subtle = {};
|
|
12
7
|
}
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/web/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAOlC,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/web/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAOlC,QAAA,MAAM,MAAM,EAAE,MAkHb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -7,6 +7,9 @@ const config = {
|
|
|
7
7
|
// use correct path, for example, coverageDirectory
|
|
8
8
|
rootDir: cedarPaths.base,
|
|
9
9
|
roots: [path.join(cedarPaths.web.src)],
|
|
10
|
+
// Opting out of jsdom's browser-style export condition resolution (needed to
|
|
11
|
+
// resolve `msw/node`) is handled by the environment itself, via
|
|
12
|
+
// jest-fixed-jsdom
|
|
10
13
|
testEnvironment: path.join(__dirname, "./RedwoodWebJestEnv.js"),
|
|
11
14
|
displayName: {
|
|
12
15
|
color: "blueBright",
|
|
@@ -76,6 +79,23 @@ const config = {
|
|
|
76
79
|
"^(\\.{1,2}/.*)\\.js$": "$1"
|
|
77
80
|
},
|
|
78
81
|
transform: {
|
|
82
|
+
// MSW's CommonJS build `require`s ESM-only packages (`rettime`,
|
|
83
|
+
// `@open-draft/deferred-promise` and `until-async`, which ships ESM in
|
|
84
|
+
// plain `.js` files). Node supports require(esm), but Jest's runtime
|
|
85
|
+
// doesn't, so compile any `.mjs` file that gets pulled in from
|
|
86
|
+
// node_modules (plus until-async) to CommonJS. This needs its own
|
|
87
|
+
// transform entry (with the config inlined) because the web babel config
|
|
88
|
+
// ignores node_modules
|
|
89
|
+
"[/\\\\]node_modules[/\\\\](?:.+\\.mjs|until-async[/\\\\].+\\.js)$": [
|
|
90
|
+
"babel-jest",
|
|
91
|
+
{
|
|
92
|
+
babelrc: false,
|
|
93
|
+
configFile: false,
|
|
94
|
+
presets: [
|
|
95
|
+
[require.resolve("@babel/preset-env"), { targets: { node: "20" } }]
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
],
|
|
79
99
|
"\\.[jt]sx?$": [
|
|
80
100
|
"babel-jest",
|
|
81
101
|
// When jest runs tests in parallel, it serializes the config before passing down options to babel
|
|
@@ -85,6 +105,13 @@ const config = {
|
|
|
85
105
|
}
|
|
86
106
|
]
|
|
87
107
|
},
|
|
108
|
+
// Jest's default is to not transform anything in node_modules, but `.mjs`
|
|
109
|
+
// files (and until-async) have to be compiled to CommonJS (see the
|
|
110
|
+
// transform above)
|
|
111
|
+
transformIgnorePatterns: [
|
|
112
|
+
"[/\\\\]node_modules[/\\\\](?!.*\\.mjs$)(?!until-async[/\\\\])",
|
|
113
|
+
"\\.pnp\\.[^\\\\/]+$"
|
|
114
|
+
],
|
|
88
115
|
resolver: path.resolve(__dirname, "./resolver.js"),
|
|
89
116
|
testPathIgnorePatterns: [".(stories|mock).[jt]sx?$"]
|
|
90
117
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest.setup.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/web/jest.setup.ts"],"names":[],"mappings":"AAEA,OAAO,2BAA2B,CAAA;
|
|
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"}
|
|
@@ -1,25 +1,67 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import type { RequestHandler, SharedOptions } from 'msw';
|
|
2
|
+
import type { StartOptions as StartMSWWorkerOptions } from 'msw/browser';
|
|
3
|
+
interface MockServerCommonApi {
|
|
4
|
+
use(...handlers: any[]): void;
|
|
5
|
+
resetHandlers(): void;
|
|
6
|
+
}
|
|
7
|
+
type MockWorkerInstance = MockServerCommonApi & {
|
|
8
|
+
stop(): void;
|
|
9
|
+
};
|
|
10
|
+
type MockServerInstance = MockServerCommonApi & {
|
|
11
|
+
listen(options?: Partial<SharedOptions>): void;
|
|
12
|
+
close(): void;
|
|
13
|
+
};
|
|
14
|
+
type StartOptions<Target> = Target extends 'browsers' ? StartMSWWorkerOptions : Partial<SharedOptions>;
|
|
15
|
+
export declare const startMSW: <Target extends "node" | "browsers">(target: Target, options?: StartOptions<Target>) => Promise<MockWorkerInstance | MockServerInstance>;
|
|
10
16
|
export declare const setupRequestHandlers: () => void;
|
|
11
17
|
export declare const closeServer: () => void;
|
|
12
18
|
export declare const registerHandler: (handler: RequestHandler) => void;
|
|
19
|
+
/**
|
|
20
|
+
* The `ctx` object passed to mock-data functions. It mirrors the API of MSW
|
|
21
|
+
* v1's GraphQL context so that existing Cedar mocks keep working with MSW v2,
|
|
22
|
+
* where the `(req, res, ctx)` resolver signature no longer exists.
|
|
23
|
+
*/
|
|
24
|
+
export interface MockGraphQLContext {
|
|
25
|
+
/** Set the http response status code (and optionally status text) */
|
|
26
|
+
status(code: number, text?: string): void;
|
|
27
|
+
/** Delay the response by the given number of milliseconds */
|
|
28
|
+
delay(durationMs: number): void;
|
|
29
|
+
/** Return GraphQL errors in the response */
|
|
30
|
+
errors(errorList: Record<string, unknown>[]): void;
|
|
31
|
+
/** Set a response header. Accepts a name/value pair or an object */
|
|
32
|
+
set(name: string | Record<string, string>, value?: string): void;
|
|
33
|
+
/** Set a response cookie */
|
|
34
|
+
cookie(name: string, value: string): void;
|
|
35
|
+
/** Set the `extensions` field of the GraphQL response */
|
|
36
|
+
extensions(extensions: Record<string, unknown>): void;
|
|
37
|
+
/** Set an arbitrary field on the GraphQL response body */
|
|
38
|
+
field(fieldName: string, value: unknown): void;
|
|
39
|
+
/** Set the `data` field of the response. Overrides the returned mock-data */
|
|
40
|
+
data(data: Record<string, unknown>): void;
|
|
41
|
+
/** Perform a request that bypasses any mock handlers */
|
|
42
|
+
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Information about the intercepted GraphQL request, passed to mock-data
|
|
46
|
+
* functions as `req`
|
|
47
|
+
*/
|
|
48
|
+
export interface MockGraphQLRequest {
|
|
49
|
+
/** The intercepted Fetch API `Request` */
|
|
50
|
+
request: Request;
|
|
51
|
+
/** The GraphQL query document string */
|
|
52
|
+
query: string;
|
|
53
|
+
operationName: string;
|
|
54
|
+
variables: Record<string, any>;
|
|
55
|
+
cookies: Record<string, string>;
|
|
56
|
+
url: URL;
|
|
57
|
+
headers: Headers;
|
|
58
|
+
method: string;
|
|
59
|
+
}
|
|
13
60
|
export type DataFunction<Query extends Record<string, unknown> = Record<string, unknown>, QueryVariables = Record<string, any>> = (variables: QueryVariables, { req, ctx, }: {
|
|
14
|
-
req:
|
|
15
|
-
ctx:
|
|
16
|
-
}) => Query | void
|
|
17
|
-
type
|
|
18
|
-
type ResponseEnhancers = {
|
|
19
|
-
once: ResponseFunction<any>;
|
|
20
|
-
networkError: (message: string) => void;
|
|
21
|
-
};
|
|
22
|
-
type ResponseEnhancer = keyof ResponseEnhancers;
|
|
61
|
+
req: MockGraphQLRequest;
|
|
62
|
+
ctx: MockGraphQLContext;
|
|
63
|
+
}) => Query | void | Promise<Query | void>;
|
|
64
|
+
type ResponseEnhancer = 'once' | 'networkError';
|
|
23
65
|
export declare const mockGraphQLQuery: <Query extends Record<string, unknown> = Record<string, unknown>, QueryVariables = Record<string, any>>(operation: string, data: DataFunction<Query, QueryVariables> | Query, responseEnhancer?: ResponseEnhancer) => Record<string, any> | DataFunction<Record<string, unknown>, Record<string, any>>;
|
|
24
66
|
export declare const mockGraphQLMutation: <Query extends Record<string, unknown> = Record<string, unknown>, QueryVariables = Record<string, any>>(operation: string, data: DataFunction<Query, QueryVariables> | Query, responseEnhancer?: ResponseEnhancer) => Record<string, any> | DataFunction<Record<string, unknown>, Record<string, any>>;
|
|
25
67
|
export declare const mockedUserMeta: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockRequests.d.ts","sourceRoot":"","sources":["../../src/web/mockRequests.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"mockRequests.d.ts","sourceRoot":"","sources":["../../src/web/mockRequests.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,IAAI,qBAAqB,EAAE,MAAM,aAAa,CAAA;AASxE,UAAU,mBAAmB;IAC3B,GAAG,CAAC,GAAG,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IAC7B,aAAa,IAAI,IAAI,CAAA;CACtB;AACD,KAAK,kBAAkB,GAAG,mBAAmB,GAAG;IAAE,IAAI,IAAI,IAAI,CAAA;CAAE,CAAA;AAChE,KAAK,kBAAkB,GAAG,mBAAmB,GAAG;IAC9C,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAA;IAC9C,KAAK,IAAI,IAAI,CAAA;CACd,CAAA;AAmBD,KAAK,YAAY,CAAC,MAAM,IAAI,MAAM,SAAS,UAAU,GACjD,qBAAqB,GACrB,OAAO,CAAC,aAAa,CAAC,CAAA;AAC1B,eAAO,MAAM,QAAQ,GAAU,MAAM,SAAS,MAAM,GAAG,UAAU,EAC/D,QAAQ,MAAM,EACd,UAAU,YAAY,CAAC,MAAM,CAAC,qDA4B/B,CAAA;AAED,eAAO,MAAM,oBAAoB,YAMhC,CAAA;AAED,eAAO,MAAM,WAAW,YAUvB,CAAA;AAED,eAAO,MAAM,eA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,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;CAEzE,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,SASnE,CAAA"}
|
package/dist/web/mockRequests.js
CHANGED
|
@@ -1,28 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bypass, delay, graphql, HttpResponse } from "msw";
|
|
2
2
|
let REQUEST_HANDLER_QUEUE = [];
|
|
3
3
|
let SERVER_INSTANCE;
|
|
4
|
+
const MSW_NODE_SPECIFIER = "msw/node";
|
|
4
5
|
const startMSW = async (target, options) => {
|
|
5
6
|
if (SERVER_INSTANCE) {
|
|
6
7
|
return SERVER_INSTANCE;
|
|
7
8
|
}
|
|
8
9
|
if (target === "browsers") {
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
const { setupWorker } = await import("msw/browser");
|
|
11
|
+
const worker = setupWorker();
|
|
12
|
+
SERVER_INSTANCE = worker;
|
|
13
|
+
await worker.start(options);
|
|
11
14
|
} else {
|
|
12
|
-
const { setupServer } = await import(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const { setupServer } = await import(
|
|
16
|
+
/* @vite-ignore */
|
|
17
|
+
MSW_NODE_SPECIFIER
|
|
18
|
+
);
|
|
19
|
+
const server = setupServer();
|
|
20
|
+
SERVER_INSTANCE = server;
|
|
21
|
+
server.listen(options);
|
|
15
22
|
}
|
|
16
23
|
return SERVER_INSTANCE;
|
|
17
24
|
};
|
|
18
25
|
const setupRequestHandlers = () => {
|
|
19
|
-
SERVER_INSTANCE
|
|
26
|
+
SERVER_INSTANCE?.resetHandlers();
|
|
20
27
|
for (const handler of REQUEST_HANDLER_QUEUE) {
|
|
21
|
-
SERVER_INSTANCE
|
|
28
|
+
SERVER_INSTANCE?.use(handler);
|
|
22
29
|
}
|
|
23
30
|
};
|
|
24
31
|
const closeServer = () => {
|
|
25
|
-
SERVER_INSTANCE
|
|
32
|
+
if (!SERVER_INSTANCE) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if ("close" in SERVER_INSTANCE) {
|
|
36
|
+
SERVER_INSTANCE.close();
|
|
37
|
+
} else {
|
|
38
|
+
SERVER_INSTANCE.stop();
|
|
39
|
+
}
|
|
26
40
|
};
|
|
27
41
|
const registerHandler = (handler) => {
|
|
28
42
|
if (!SERVER_INSTANCE) {
|
|
@@ -32,39 +46,95 @@ const registerHandler = (handler) => {
|
|
|
32
46
|
}
|
|
33
47
|
};
|
|
34
48
|
const mockGraphQL = (type, operation, data, responseEnhancer) => {
|
|
35
|
-
const resolver = (
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
const resolver = async ({
|
|
50
|
+
request,
|
|
51
|
+
query,
|
|
52
|
+
operationName,
|
|
53
|
+
variables,
|
|
54
|
+
cookies
|
|
55
|
+
}) => {
|
|
56
|
+
let d = void 0;
|
|
57
|
+
let status = 200;
|
|
58
|
+
let statusText;
|
|
59
|
+
let delayDurationMs;
|
|
60
|
+
let errorList;
|
|
61
|
+
let extensions;
|
|
62
|
+
let explicitData;
|
|
63
|
+
const extraFields = {};
|
|
64
|
+
const headers = new Headers();
|
|
38
65
|
if (typeof data === "function") {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
66
|
+
const ctx = {
|
|
67
|
+
status: (code, text) => {
|
|
68
|
+
status = code;
|
|
69
|
+
statusText = text;
|
|
70
|
+
},
|
|
71
|
+
delay: (durationMs) => {
|
|
72
|
+
delayDurationMs = durationMs;
|
|
73
|
+
},
|
|
74
|
+
errors: (errors) => {
|
|
75
|
+
errorList = errors;
|
|
76
|
+
},
|
|
77
|
+
set: (name, value) => {
|
|
78
|
+
if (typeof name === "object") {
|
|
79
|
+
for (const [headerName, headerValue] of Object.entries(name)) {
|
|
80
|
+
headers.set(headerName, headerValue);
|
|
81
|
+
}
|
|
82
|
+
} else if (typeof value !== "undefined") {
|
|
83
|
+
headers.set(name, value);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
cookie: (name, value) => {
|
|
87
|
+
headers.append("Set-Cookie", `${name}=${value}`);
|
|
88
|
+
},
|
|
89
|
+
extensions: (ext) => {
|
|
90
|
+
extensions = ext;
|
|
91
|
+
},
|
|
92
|
+
field: (fieldName, value) => {
|
|
93
|
+
extraFields[fieldName] = value;
|
|
94
|
+
},
|
|
95
|
+
data: (dataValue) => {
|
|
96
|
+
explicitData = dataValue;
|
|
97
|
+
},
|
|
98
|
+
fetch: (input, init) => fetch(bypass(input, init))
|
|
45
99
|
};
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
field: captureTransform(ctx.field)
|
|
100
|
+
const req = {
|
|
101
|
+
request,
|
|
102
|
+
query,
|
|
103
|
+
operationName,
|
|
104
|
+
variables,
|
|
105
|
+
cookies,
|
|
106
|
+
url: new URL(request.url),
|
|
107
|
+
headers: request.headers,
|
|
108
|
+
method: request.method
|
|
56
109
|
};
|
|
57
|
-
d = data(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
110
|
+
d = await data(variables, { req, ctx });
|
|
111
|
+
} else {
|
|
112
|
+
d = data;
|
|
61
113
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
)
|
|
114
|
+
if (responseEnhancer === "networkError") {
|
|
115
|
+
return HttpResponse.error();
|
|
116
|
+
}
|
|
117
|
+
if (typeof delayDurationMs !== "undefined") {
|
|
118
|
+
await delay(delayDurationMs);
|
|
119
|
+
}
|
|
120
|
+
const body = { ...extraFields };
|
|
121
|
+
const bodyData = explicitData ?? d;
|
|
122
|
+
if (typeof bodyData !== "undefined") {
|
|
123
|
+
body.data = bodyData;
|
|
124
|
+
}
|
|
125
|
+
if (typeof errorList !== "undefined") {
|
|
126
|
+
body.errors = errorList;
|
|
127
|
+
}
|
|
128
|
+
if (typeof extensions !== "undefined") {
|
|
129
|
+
body.extensions = extensions;
|
|
130
|
+
}
|
|
131
|
+
return HttpResponse.json(body, { status, statusText, headers });
|
|
66
132
|
};
|
|
67
|
-
registerHandler(
|
|
133
|
+
registerHandler(
|
|
134
|
+
graphql[type](operation, resolver, {
|
|
135
|
+
once: responseEnhancer === "once"
|
|
136
|
+
})
|
|
137
|
+
);
|
|
68
138
|
return data;
|
|
69
139
|
};
|
|
70
140
|
const mockGraphQLQuery = (operation, data, responseEnhancer) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/testing",
|
|
3
|
-
"version": "6.0.0-canary.
|
|
3
|
+
"version": "6.0.0-canary.2675",
|
|
4
4
|
"description": "Tools, wrappers and configuration for testing a Cedar project.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -116,10 +116,11 @@
|
|
|
116
116
|
"test:watch": "vitest watch"
|
|
117
117
|
},
|
|
118
118
|
"dependencies": {
|
|
119
|
-
"@
|
|
120
|
-
"@cedarjs/
|
|
121
|
-
"@cedarjs/
|
|
122
|
-
"@cedarjs/
|
|
119
|
+
"@babel/preset-env": "7.29.7",
|
|
120
|
+
"@cedarjs/babel-config": "6.0.0-canary.2675",
|
|
121
|
+
"@cedarjs/context": "6.0.0-canary.2675",
|
|
122
|
+
"@cedarjs/graphql-server": "6.0.0-canary.2675",
|
|
123
|
+
"@cedarjs/project-config": "6.0.0-canary.2675",
|
|
123
124
|
"@testing-library/dom": "10.4.1",
|
|
124
125
|
"@testing-library/jest-dom": "6.9.1",
|
|
125
126
|
"@testing-library/react": "16.3.2",
|
|
@@ -133,29 +134,29 @@
|
|
|
133
134
|
"fast-glob": "3.3.3",
|
|
134
135
|
"jest": "29.7.0",
|
|
135
136
|
"jest-environment-jsdom": "29.7.0",
|
|
137
|
+
"jest-fixed-jsdom": "0.0.11",
|
|
136
138
|
"jest-watch-typeahead": "2.2.2",
|
|
137
|
-
"msw": "
|
|
139
|
+
"msw": "2.15.0",
|
|
138
140
|
"ts-toolbelt": "9.6.0",
|
|
139
|
-
"unplugin-auto-import": "19.3.0"
|
|
140
|
-
"whatwg-fetch": "3.6.20"
|
|
141
|
+
"unplugin-auto-import": "19.3.0"
|
|
141
142
|
},
|
|
142
143
|
"devDependencies": {
|
|
143
144
|
"@arethetypeswrong/cli": "0.18.5",
|
|
144
|
-
"@cedarjs/auth": "6.0.0-canary.
|
|
145
|
-
"@cedarjs/framework-tools": "6.0.0-canary.
|
|
146
|
-
"@cedarjs/router": "6.0.0-canary.
|
|
147
|
-
"@cedarjs/web": "6.0.0-canary.
|
|
145
|
+
"@cedarjs/auth": "6.0.0-canary.2675",
|
|
146
|
+
"@cedarjs/framework-tools": "6.0.0-canary.2675",
|
|
147
|
+
"@cedarjs/router": "6.0.0-canary.2675",
|
|
148
|
+
"@cedarjs/web": "6.0.0-canary.2675",
|
|
148
149
|
"concurrently": "9.2.1",
|
|
149
150
|
"jsdom": "27.4.0",
|
|
150
151
|
"publint": "0.3.21",
|
|
151
152
|
"typescript": "5.9.3",
|
|
152
|
-
"vitest": "
|
|
153
|
+
"vitest": "4.1.10"
|
|
153
154
|
},
|
|
154
155
|
"peerDependencies": {
|
|
155
156
|
"@cedarjs/auth": "workspace:*",
|
|
156
157
|
"@cedarjs/router": "workspace:*",
|
|
157
158
|
"@cedarjs/web": "workspace:*",
|
|
158
|
-
"vitest": "
|
|
159
|
+
"vitest": "4.1.10"
|
|
159
160
|
},
|
|
160
161
|
"peerDependenciesMeta": {
|
|
161
162
|
"vitest": {
|