@cedarjs/testing 5.0.6 → 5.0.7-next.219

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.
Files changed (103) hide show
  1. package/config/jest/api/apiBabelConfig.d.ts.map +1 -1
  2. package/config/jest/api/apiBabelConfig.js +1 -3
  3. package/config/jest/api/globalSetup.d.ts.map +1 -1
  4. package/config/jest/api/globalSetup.js +9 -0
  5. package/config/jest/api/jest-preset.d.ts.map +1 -1
  6. package/config/jest/api/jest-preset.js +38 -3
  7. package/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -1
  8. package/config/jest/babelPlugins/babel-plugin-redwood-cell.js +2 -1
  9. package/config/jest/web/RedwoodWebJestEnv.d.ts +2 -2
  10. package/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -1
  11. package/config/jest/web/RedwoodWebJestEnv.js +12 -7
  12. package/config/jest/web/jest-fixed-jsdom.d.js +1 -0
  13. package/config/jest/web/jest-preset.d.ts.map +1 -1
  14. package/config/jest/web/jest-preset.js +135 -30
  15. package/config/jest/web/jest.setup.d.ts +0 -1
  16. package/config/jest/web/jest.setup.d.ts.map +1 -1
  17. package/config/jest/web/jest.setup.js +0 -1
  18. package/dist/api/checkTestDatabase.d.ts +23 -0
  19. package/dist/api/checkTestDatabase.d.ts.map +1 -0
  20. package/dist/api/checkTestDatabase.js +44 -0
  21. package/dist/api/vitest/CedarApiVitestEnv.d.ts.map +1 -1
  22. package/dist/api/vitest/CedarApiVitestEnv.js +13 -1
  23. package/dist/api/vitest/vite-plugin-cedar-vitest-api-config.js +7 -7
  24. package/dist/api/vitest/vitest-api.setup.js +4 -4
  25. package/dist/cjs/api/checkTestDatabase.d.ts +23 -0
  26. package/dist/cjs/api/checkTestDatabase.d.ts.map +1 -0
  27. package/dist/cjs/api/checkTestDatabase.js +69 -0
  28. package/dist/cjs/api/vitest/CedarApiVitestEnv.js +10 -1
  29. package/dist/cjs/api/vitest/vite-plugin-cedar-vitest-api-config.js +7 -7
  30. package/dist/cjs/api/vitest/vitest-api.setup.js +4 -4
  31. package/dist/cjs/config/jest/api/apiBabelConfig.d.ts.map +1 -1
  32. package/dist/cjs/config/jest/api/apiBabelConfig.js +1 -3
  33. package/dist/cjs/config/jest/api/globalSetup.d.ts.map +1 -1
  34. package/dist/cjs/config/jest/api/globalSetup.js +9 -0
  35. package/dist/cjs/config/jest/api/jest-preset.d.ts.map +1 -1
  36. package/dist/cjs/config/jest/api/jest-preset.js +38 -3
  37. package/dist/cjs/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -1
  38. package/dist/cjs/config/jest/babelPlugins/babel-plugin-redwood-cell.js +2 -1
  39. package/dist/cjs/config/jest/web/RedwoodWebJestEnv.d.ts +2 -2
  40. package/dist/cjs/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -1
  41. package/dist/cjs/config/jest/web/RedwoodWebJestEnv.js +12 -7
  42. package/dist/cjs/config/jest/web/jest-fixed-jsdom.d.js +1 -0
  43. package/dist/cjs/config/jest/web/jest-preset.d.ts.map +1 -1
  44. package/dist/cjs/config/jest/web/jest-preset.js +135 -30
  45. package/dist/cjs/config/jest/web/jest.setup.d.ts +0 -1
  46. package/dist/cjs/config/jest/web/jest.setup.d.ts.map +1 -1
  47. package/dist/cjs/config/jest/web/jest.setup.js +0 -1
  48. package/dist/cjs/web/MockProviders.js +9 -3
  49. package/dist/cjs/web/fileMock.d.ts +5 -4
  50. package/dist/cjs/web/fileMock.d.ts.map +1 -1
  51. package/dist/cjs/web/mockRequests.d.ts +60 -18
  52. package/dist/cjs/web/mockRequests.d.ts.map +1 -1
  53. package/dist/cjs/web/mockRequests.js +107 -36
  54. package/dist/cjs/web/vitest/index.js +3 -0
  55. package/dist/cjs/web/vitest/vite-plugin-cedar-vitest-web-config.js +51 -0
  56. package/dist/cjs/web/vitest/vitest-web.setup.js +19 -0
  57. package/dist/config/jest/api/apiBabelConfig.d.ts.map +1 -1
  58. package/dist/config/jest/api/apiBabelConfig.js +1 -3
  59. package/dist/config/jest/api/globalSetup.d.ts.map +1 -1
  60. package/dist/config/jest/api/globalSetup.js +12 -0
  61. package/dist/config/jest/api/index.js +5 -1
  62. package/dist/config/jest/api/jest-preset.d.ts.map +1 -1
  63. package/dist/config/jest/api/jest-preset.js +38 -3
  64. package/dist/config/jest/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -1
  65. package/dist/config/jest/babelPlugins/babel-plugin-redwood-cell.js +2 -1
  66. package/dist/config/jest/jest-serial-runner.js +5 -1
  67. package/dist/config/jest/web/RedwoodWebJestEnv.d.ts +2 -2
  68. package/dist/config/jest/web/RedwoodWebJestEnv.d.ts.map +1 -1
  69. package/dist/config/jest/web/RedwoodWebJestEnv.js +2 -7
  70. package/dist/config/jest/web/index.js +5 -1
  71. package/dist/config/jest/web/jest-fixed-jsdom.d.js +0 -0
  72. package/dist/config/jest/web/jest-preset.d.ts.map +1 -1
  73. package/dist/config/jest/web/jest-preset.js +135 -30
  74. package/dist/config/jest/web/jest.setup.d.ts +0 -1
  75. package/dist/config/jest/web/jest.setup.d.ts.map +1 -1
  76. package/dist/config/jest/web/jest.setup.js +0 -1
  77. package/dist/config/jest/web/resolver.js +5 -1
  78. package/dist/web/MockProviders.js +9 -3
  79. package/dist/web/fileMock.d.ts +5 -4
  80. package/dist/web/fileMock.d.ts.map +1 -1
  81. package/dist/web/mockRequests.d.ts +60 -18
  82. package/dist/web/mockRequests.d.ts.map +1 -1
  83. package/dist/web/mockRequests.js +108 -37
  84. package/dist/web/vitest/index.d.ts +1 -0
  85. package/dist/web/vitest/index.d.ts.map +1 -1
  86. package/dist/web/vitest/index.js +2 -0
  87. package/dist/web/vitest/vite-plugin-cedar-vitest-web-config.d.ts +12 -0
  88. package/dist/web/vitest/vite-plugin-cedar-vitest-web-config.d.ts.map +1 -0
  89. package/dist/web/vitest/vite-plugin-cedar-vitest-web-config.js +16 -0
  90. package/dist/web/vitest/vite-plugin-cedarjs-router-import-transform.d.ts.map +1 -1
  91. package/dist/web/vitest/vite-plugin-create-auth-import-transform.d.ts.map +1 -1
  92. package/dist/web/vitest/vitest-web.setup.d.ts +2 -0
  93. package/dist/web/vitest/vitest-web.setup.d.ts.map +1 -0
  94. package/dist/web/vitest/vitest-web.setup.js +18 -0
  95. package/package.json +26 -21
  96. package/dist/cjs/web/vitest/index.d.ts +0 -4
  97. package/dist/cjs/web/vitest/index.d.ts.map +0 -1
  98. package/dist/cjs/web/vitest/vite-plugin-auto-import.d.ts +0 -2
  99. package/dist/cjs/web/vitest/vite-plugin-auto-import.d.ts.map +0 -1
  100. package/dist/cjs/web/vitest/vite-plugin-cedarjs-router-import-transform.d.ts +0 -7
  101. package/dist/cjs/web/vitest/vite-plugin-cedarjs-router-import-transform.d.ts.map +0 -1
  102. package/dist/cjs/web/vitest/vite-plugin-create-auth-import-transform.d.ts +0 -3
  103. package/dist/cjs/web/vitest/vite-plugin-create-auth-import-transform.d.ts.map +0 -1
@@ -1,12 +1,65 @@
1
+ import fs from "node:fs";
1
2
  import path from "node:path";
2
3
  import { getPaths } from "@cedarjs/project-config";
3
4
  const cedarPaths = getPaths();
4
- const NODE_MODULES_PATH = path.join(cedarPaths.base, "node_modules");
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
+ }
5
55
  const config = {
6
56
  // To make sure other config option which depends on rootDir always
7
57
  // use correct path, for example, coverageDirectory
8
58
  rootDir: cedarPaths.base,
9
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
10
63
  testEnvironment: path.join(__dirname, "./RedwoodWebJestEnv.js"),
11
64
  displayName: {
12
65
  color: "blueBright",
@@ -36,41 +89,78 @@ const config = {
36
89
  ],
37
90
  setupFilesAfterEnv: [path.resolve(__dirname, "./jest.setup.js")],
38
91
  moduleNameMapper: {
39
- /**
40
- * Make sure modules that require different versions of these
41
- * dependencies end up using the same one.
42
- */
43
- "^react$": path.join(NODE_MODULES_PATH, "react"),
44
- "^react-dom$": path.join(NODE_MODULES_PATH, "react-dom"),
45
- "^@apollo/client/react$": path.join(
46
- NODE_MODULES_PATH,
47
- "@apollo/client/react"
48
- ),
49
- // We replace imports to "@cedarjs/router" with our own "mock" implementation.
50
- "^@cedarjs/router$": path.join(
51
- NODE_MODULES_PATH,
52
- "@cedarjs/testing/dist/cjs/web/MockRouter.js"
53
- ),
54
- "^@cedarjs/web$": path.join(NODE_MODULES_PATH, "@cedarjs/web/dist/cjs"),
55
- // This allows us to mock `createAuthentication` which is used by auth
56
- // clients, which in turn lets us mock `useAuth` in tests
57
- "^@cedarjs/auth$": path.join(
58
- NODE_MODULES_PATH,
59
- "@cedarjs/testing/dist/cjs/web/mockAuth.js"
60
- ),
61
- // @NOTE: Import @cedarjs/testing in web tests, and it automatically remaps to the web side only
62
- // This is to prevent web stuff leaking into api, and vice versa
63
- "^@cedarjs/testing$": path.join(NODE_MODULES_PATH, "@cedarjs/testing/web"),
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
+ }),
64
125
  "~__CEDAR__USER_ROUTES_FOR_MOCK": cedarPaths.web.routes,
65
126
  "~__CEDAR__USER_AUTH_FOR_MOCK": path.join(cedarPaths.web.src, "auth"),
66
- /**
67
- * Mock out files that aren't particularly useful in tests. See fileMock.js for more info.
68
- */
69
- "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|css)$": "@cedarjs/testing/dist/cjs/web/fileMock.js",
70
127
  // Support for importing files with extensions (like you'd do in ESM projects)
71
128
  "^(\\.{1,2}/.*)\\.js$": "$1"
72
129
  },
73
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
+ ],
74
164
  "\\.[jt]sx?$": [
75
165
  "babel-jest",
76
166
  // When jest runs tests in parallel, it serializes the config before passing down options to babel
@@ -80,6 +170,21 @@ const config = {
80
170
  }
81
171
  ]
82
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
+ ],
83
188
  resolver: path.resolve(__dirname, "./resolver.js"),
84
189
  testPathIgnorePatterns: [".(stories|mock).[jt]sx?$"]
85
190
  };
@@ -1,5 +1,4 @@
1
1
  import '@testing-library/jest-dom';
2
- import 'whatwg-fetch';
3
2
  import { mockCurrentUser as _mockCurrentUser } from '../../../web/mockRequests.js';
4
3
  declare global {
5
4
  var __RWJS_TESTROOT_DIR: string;
@@ -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;AAClC,OAAO,cAAc,CAAA;AAGrB,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
+ {"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,5 +1,4 @@
1
1
  import "@testing-library/jest-dom";
2
- import "whatwg-fetch";
3
2
  import { findCellMocks } from "../../../web/findCellMocks.js";
4
3
  import {
5
4
  startMSW,
@@ -1,6 +1,10 @@
1
1
  var __getOwnPropNames = Object.getOwnPropertyNames;
2
2
  var __commonJS = (cb, mod) => function __require() {
3
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
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
+ }
4
8
  };
5
9
  var require_resolver = __commonJS({
6
10
  "src/config/jest/web/resolver.ts"(exports, module) {
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { LocationProvider } from "@cedarjs/router";
3
3
  import { RedwoodProvider } from "@cedarjs/web";
4
- import { RedwoodApolloProvider } from "@cedarjs/web/apollo";
4
+ import { CedarApolloProvider } from "@cedarjs/web/apollo/CedarApolloProvider";
5
5
  import { UserRoutes as VitestUserRoutes } from "./globRoutesImporter.js";
6
6
  import { useAuth } from "./mockAuth.js";
7
7
  import { MockParamsProvider } from "./MockParamsProvider.js";
@@ -16,10 +16,16 @@ try {
16
16
  UserRoutes = () => /* @__PURE__ */ React.createElement(React.Fragment, null);
17
17
  }
18
18
  const MockProviders = ({ children }) => {
19
- return /* @__PURE__ */ React.createElement(RedwoodProvider, { titleTemplate: "%PageTitle | %AppTitle" }, /* @__PURE__ */ React.createElement(RedwoodApolloProvider, { useAuth }, /* @__PURE__ */ React.createElement(UserRoutes, null), /* @__PURE__ */ React.createElement(VitestUserRoutes, null), /* @__PURE__ */ React.createElement(LocationProvider, null, /* @__PURE__ */ React.createElement(MockParamsProvider, null, children))));
19
+ return /* @__PURE__ */ React.createElement(RedwoodProvider, { titleTemplate: "%PageTitle | %AppTitle" }, /* @__PURE__ */ React.createElement(CedarApolloProvider, { useAuth }, /* @__PURE__ */ React.createElement(UserRoutes, null), /* @__PURE__ */ React.createElement(VitestUserRoutes, null), /* @__PURE__ */ React.createElement(LocationProvider, null, /* @__PURE__ */ React.createElement(MockParamsProvider, null, children))));
20
20
  };
21
21
  function isModuleNotFoundError(error, module) {
22
- return !!error && typeof error === "object" && "code" in error && error.code === "MODULE_NOT_FOUND" && "moduleName" in error && error.moduleName === module;
22
+ if (!error || typeof error !== "object" || !("code" in error) || error.code !== "MODULE_NOT_FOUND") {
23
+ return false;
24
+ }
25
+ if ("moduleName" in error) {
26
+ return error.moduleName === module;
27
+ }
28
+ return "message" in error && typeof error.message === "string" && (error.message.includes(`'${module}'`) || error.message.includes(`"${module}"`));
23
29
  }
24
30
  export {
25
31
  MockProviders
@@ -1,8 +1,9 @@
1
1
  /**
2
- * configure Jest to gracefully handle asset files such as stylesheets and images.
3
- * Usually, these files aren't particularly useful in tests so we can safely mock them out.
4
- * See: https://jestjs.io/docs/en/webpack#handling-static-assets
5
- * See: https://github.com/cedarjs/cedar/blob/4637f61d5e6aeb907d4a17217ab643cfb4d4ebe4/packages/testing/config/jest/web/jest-preset.js#L77-L78
2
+ * Lets Jest gracefully handle asset files such as stylesheets and images.
3
+ * Usually, these files aren't particularly useful in tests so we can safely
4
+ * mock them out. Asset imports are mapped to this module by the
5
+ * `moduleNameMapper` config in
6
+ * `packages/testing/src/config/jest/web/jest-preset.ts`.
6
7
  */
7
8
  declare const _default: "fileMock";
8
9
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"fileMock.d.ts","sourceRoot":"","sources":["../../src/web/fileMock.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;wBACY,UAAU;AAAzB,wBAAyB"}
1
+ {"version":3,"file":"fileMock.d.ts","sourceRoot":"","sources":["../../src/web/fileMock.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;wBACY,UAAU;AAAzB,wBAAyB"}
@@ -1,25 +1,67 @@
1
- import type { StartOptions as StartMSWWorkerOptions, SharedOptions as SharedMSWOptions, MockedResponse, DefaultBodyType, RequestHandler, GraphQLContext, GraphQLRequest, ResponseTransformer } from 'msw';
2
- /**
3
- * Plugs fetch for the correct target in order to capture requests.
4
- *
5
- * Request handlers can be registered lazily (via `mockGraphQL<Query|Mutation>`),
6
- * the queue will be drained and used.
7
- */
8
- type StartOptions<Target> = Target extends 'browsers' ? StartMSWWorkerOptions : SharedMSWOptions;
9
- export declare const startMSW: <Target extends "node" | "browsers">(target: Target, options?: StartOptions<Target>) => Promise<any>;
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: GraphQLRequest<any>;
15
- ctx: GraphQLContext<Record<string, any>>;
16
- }) => Query | void;
17
- type ResponseFunction<BodyType extends DefaultBodyType = any> = (...transformers: ResponseTransformer<BodyType>[]) => MockedResponse<BodyType>;
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,EACV,YAAY,IAAI,qBAAqB,EACrC,aAAa,IAAI,gBAAgB,EACjC,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,cAAc,EACd,mBAAmB,EAGpB,MAAM,KAAK,CAAA;AAQZ;;;;;GAKG;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KAAK,EACjD,mBAAmB,gBAAgB,qFAGpC,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAEpC,WAAW,MAAM,EACjB,MAAM,YAAY,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,KAAK,EACjD,mBAAmB,gBAAgB,qFAGpC,CAAA;AAED,eAAO,MAAM,cAAc,EAAE;IAAE,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"}
@@ -1,28 +1,43 @@
1
- import { setupWorker, graphql } from "msw";
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
- SERVER_INSTANCE = setupWorker();
10
- await SERVER_INSTANCE.start(options);
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("msw/node");
13
- SERVER_INSTANCE = setupServer();
14
- await SERVER_INSTANCE.listen(options);
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.resetHandlers();
26
+ SERVER_INSTANCE?.resetHandlers();
20
27
  for (const handler of REQUEST_HANDLER_QUEUE) {
21
- SERVER_INSTANCE.use(handler);
28
+ SERVER_INSTANCE?.use(handler);
22
29
  }
23
30
  };
24
31
  const closeServer = () => {
25
- SERVER_INSTANCE.close();
32
+ if (!SERVER_INSTANCE) {
33
+ return;
34
+ }
35
+ if ("close" in SERVER_INSTANCE) {
36
+ SERVER_INSTANCE.close();
37
+ } else {
38
+ SERVER_INSTANCE.stop();
39
+ }
40
+ SERVER_INSTANCE = void 0;
26
41
  };
27
42
  const registerHandler = (handler) => {
28
43
  if (!SERVER_INSTANCE) {
@@ -32,39 +47,95 @@ const registerHandler = (handler) => {
32
47
  }
33
48
  };
34
49
  const mockGraphQL = (type, operation, data, responseEnhancer) => {
35
- const resolver = (req, res, ctx) => {
36
- let d = data;
37
- let responseTransforms = [];
50
+ const resolver = async ({
51
+ request,
52
+ query,
53
+ operationName,
54
+ variables,
55
+ cookies
56
+ }) => {
57
+ let d = void 0;
58
+ let status = 200;
59
+ let statusText;
60
+ let delayDurationMs;
61
+ let errorList;
62
+ let extensions;
63
+ let explicitData;
64
+ const extraFields = {};
65
+ const headers = new Headers();
38
66
  if (typeof data === "function") {
39
- const captureTransform = (fn) => {
40
- return (...args) => {
41
- const resTransform = fn(...args);
42
- responseTransforms = [...responseTransforms, resTransform];
43
- return resTransform;
44
- };
67
+ const ctx = {
68
+ status: (code, text) => {
69
+ status = code;
70
+ statusText = text;
71
+ },
72
+ delay: (durationMs) => {
73
+ delayDurationMs = durationMs;
74
+ },
75
+ errors: (errors) => {
76
+ errorList = errors;
77
+ },
78
+ set: (name, value) => {
79
+ if (typeof name === "object") {
80
+ for (const [headerName, headerValue] of Object.entries(name)) {
81
+ headers.set(headerName, headerValue);
82
+ }
83
+ } else if (typeof value !== "undefined") {
84
+ headers.set(name, value);
85
+ }
86
+ },
87
+ cookie: (name, value) => {
88
+ headers.append("Set-Cookie", `${name}=${value}`);
89
+ },
90
+ extensions: (ext) => {
91
+ extensions = ext;
92
+ },
93
+ field: (fieldName, value) => {
94
+ extraFields[fieldName] = value;
95
+ },
96
+ data: (dataValue) => {
97
+ explicitData = dataValue;
98
+ },
99
+ fetch: (input, init) => fetch(bypass(input, init))
45
100
  };
46
- const newCtx = {
47
- status: captureTransform(ctx.status),
48
- delay: captureTransform(ctx.delay),
49
- errors: captureTransform(ctx.errors),
50
- set: captureTransform(ctx.set),
51
- fetch: captureTransform(ctx.fetch),
52
- data: captureTransform(ctx.data),
53
- extensions: captureTransform(ctx.extensions),
54
- cookie: captureTransform(ctx.cookie),
55
- field: captureTransform(ctx.field)
101
+ const req = {
102
+ request,
103
+ query,
104
+ operationName,
105
+ variables,
106
+ cookies,
107
+ url: new URL(request.url),
108
+ headers: request.headers,
109
+ method: request.method
56
110
  };
57
- d = data(req.variables, {
58
- req,
59
- ctx: newCtx
60
- });
111
+ d = await data(variables, { req, ctx });
112
+ } else {
113
+ d = data;
61
114
  }
62
- return (responseEnhancer ? res[responseEnhancer] : res)(
63
- ctx.data(d),
64
- ...responseTransforms
65
- );
115
+ if (responseEnhancer === "networkError") {
116
+ return HttpResponse.error();
117
+ }
118
+ if (typeof delayDurationMs !== "undefined") {
119
+ await delay(delayDurationMs);
120
+ }
121
+ const body = { ...extraFields };
122
+ const bodyData = explicitData ?? d;
123
+ if (typeof bodyData !== "undefined") {
124
+ body.data = bodyData;
125
+ }
126
+ if (typeof errorList !== "undefined") {
127
+ body.errors = errorList;
128
+ }
129
+ if (typeof extensions !== "undefined") {
130
+ body.extensions = extensions;
131
+ }
132
+ return HttpResponse.json(body, { status, statusText, headers });
66
133
  };
67
- registerHandler(graphql[type](operation, resolver));
134
+ registerHandler(
135
+ graphql[type](operation, resolver, {
136
+ once: responseEnhancer === "once"
137
+ })
138
+ );
68
139
  return data;
69
140
  };
70
141
  const mockGraphQLQuery = (operation, data, responseEnhancer) => {
@@ -1,4 +1,5 @@
1
1
  export { cedarJsRouterImportTransformPlugin } from './vite-plugin-cedarjs-router-import-transform.js';
2
+ export { cedarVitestWebConfigPlugin } from './vite-plugin-cedar-vitest-web-config.js';
2
3
  export { createAuthImportTransformPlugin } from './vite-plugin-create-auth-import-transform.js';
3
4
  export { autoImportsPlugin } from './vite-plugin-auto-import.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,kDAAkD,CAAA;AACrG,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAA;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,kDAAkD,CAAA;AACrG,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAA;AACrF,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAA;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA"}
@@ -1,8 +1,10 @@
1
1
  import { cedarJsRouterImportTransformPlugin } from "./vite-plugin-cedarjs-router-import-transform.js";
2
+ import { cedarVitestWebConfigPlugin } from "./vite-plugin-cedar-vitest-web-config.js";
2
3
  import { createAuthImportTransformPlugin } from "./vite-plugin-create-auth-import-transform.js";
3
4
  import { autoImportsPlugin } from "./vite-plugin-auto-import.js";
4
5
  export {
5
6
  autoImportsPlugin,
6
7
  cedarJsRouterImportTransformPlugin,
8
+ cedarVitestWebConfigPlugin,
7
9
  createAuthImportTransformPlugin
8
10
  };
@@ -0,0 +1,12 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Contributes web-side Vitest config, most importantly a setup file that
4
+ * starts MSW so that `mockGraphQLQuery`/`mockGraphQLMutation` handlers (and
5
+ * cell mocks) actually intercept GraphQL requests during tests.
6
+ *
7
+ * Vitest resolves its `test` config from Vite plugins, so returning `test`
8
+ * from the `config` hook here merges with the user's own vitest config (the
9
+ * `setupFiles` arrays are concatenated).
10
+ */
11
+ export declare function cedarVitestWebConfigPlugin(): Plugin;
12
+ //# sourceMappingURL=vite-plugin-cedar-vitest-web-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-vitest-web-config.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/vite-plugin-cedar-vitest-web-config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CAWnD"}
@@ -0,0 +1,16 @@
1
+ import path from "node:path";
2
+ function cedarVitestWebConfigPlugin() {
3
+ return {
4
+ name: "cedar-vitest-web-config",
5
+ config: () => {
6
+ return {
7
+ test: {
8
+ setupFiles: [path.join(import.meta.dirname, "vitest-web.setup.js")]
9
+ }
10
+ };
11
+ }
12
+ };
13
+ }
14
+ export {
15
+ cedarVitestWebConfigPlugin
16
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-cedarjs-router-import-transform.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/vite-plugin-cedarjs-router-import-transform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;GAGG;AACH,wBAAgB,kCAAkC,IAAI,YAAY,CAejE"}
1
+ {"version":3,"file":"vite-plugin-cedarjs-router-import-transform.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/vite-plugin-cedarjs-router-import-transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;GAGG;AACH,wBAAgB,kCAAkC,IAAI,YAAY,CAejE"}
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-create-auth-import-transform.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/vite-plugin-create-auth-import-transform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC,wBAAgB,+BAA+B,IAAI,YAAY,CAuB9D"}
1
+ {"version":3,"file":"vite-plugin-create-auth-import-transform.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/vite-plugin-create-auth-import-transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC,wBAAgB,+BAA+B,IAAI,YAAY,CAuB9D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=vitest-web.setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest-web.setup.d.ts","sourceRoot":"","sources":["../../../src/web/vitest/vitest-web.setup.ts"],"names":[],"mappings":""}