@cedarjs/testing 6.0.0-canary.2691 → 6.0.0-canary.2692

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.
@@ -1 +1 @@
1
- {"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AASlC,QAAA,MAAM,MAAM,EAAE,MA0Db,CAAA;AAED,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAkClC,QAAA,MAAM,MAAM,EAAE,MA0Db,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -35,8 +35,17 @@ var import_node_path = __toESM(require("node:path"), 1);
35
35
  var import_babel_config = require("@cedarjs/babel-config");
36
36
  var import_project_config = require("@cedarjs/project-config");
37
37
  const rwjsPaths = (0, import_project_config.getPaths)();
38
- const NODE_MODULES_PATH = import_node_path.default.join(rwjsPaths.base, "node_modules");
39
38
  const { babelrc } = (0, import_babel_config.getApiSideDefaultBabelConfig)({ forJest: true });
39
+ function resolveSubpath(specifier) {
40
+ try {
41
+ return require.resolve(specifier, {
42
+ paths: [rwjsPaths.api.base, rwjsPaths.base]
43
+ });
44
+ } catch {
45
+ return void 0;
46
+ }
47
+ }
48
+ const testingApiPath = resolveSubpath("@cedarjs/testing/api");
40
49
  const config = {
41
50
  // To make sure other config option which depends on rootDir use
42
51
  // correct path, for example, coverageDirectory
@@ -77,7 +86,7 @@ const config = {
77
86
  "^src/(.*)$": import_node_path.default.join(rwjsPaths.api.src, "$1"),
78
87
  // @NOTE: Import @cedarjs/testing in api tests, and it automatically remaps to the api side only
79
88
  // This is to prevent web stuff leaking into api, and vice versa
80
- "^@cedarjs/testing$": import_node_path.default.join(NODE_MODULES_PATH, "@cedarjs/testing/api"),
89
+ ...testingApiPath ? { "^@cedarjs/testing$": testingApiPath } : {},
81
90
  // Support for importing files with extensions (like you'd do in ESM projects)
82
91
  "^(\\.{1,2}/.*)\\.js$": "$1"
83
92
  },
@@ -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,MAyHb,CAAA;AAED,eAAe,MAAM,CAAA"}
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,MAwHb,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -31,10 +31,60 @@ __export(jest_preset_exports, {
31
31
  default: () => jest_preset_default
32
32
  });
33
33
  module.exports = __toCommonJS(jest_preset_exports);
34
+ var import_node_fs = __toESM(require("node:fs"), 1);
34
35
  var import_node_path = __toESM(require("node:path"), 1);
35
36
  var import_project_config = require("@cedarjs/project-config");
36
37
  const cedarPaths = (0, import_project_config.getPaths)();
37
- const NODE_MODULES_PATH = import_node_path.default.join(cedarPaths.base, "node_modules");
38
+ const RESOLVE_FROM = [cedarPaths.web.base, cedarPaths.base];
39
+ function resolvePackageDir(packageName, resolveFrom = RESOLVE_FROM) {
40
+ try {
41
+ return import_node_path.default.dirname(
42
+ require.resolve(`${packageName}/package.json`, { paths: resolveFrom })
43
+ );
44
+ } catch {
45
+ }
46
+ try {
47
+ let dir = import_node_path.default.dirname(require.resolve(packageName, { paths: resolveFrom }));
48
+ for (; ; ) {
49
+ const manifestPath = import_node_path.default.join(dir, "package.json");
50
+ if (import_node_fs.default.existsSync(manifestPath)) {
51
+ const manifest = JSON.parse(
52
+ import_node_fs.default.readFileSync(manifestPath, "utf-8")
53
+ );
54
+ if (manifest && typeof manifest === "object" && "name" in manifest && manifest.name === packageName) {
55
+ return dir;
56
+ }
57
+ }
58
+ const parent = import_node_path.default.dirname(dir);
59
+ if (parent === dir) {
60
+ return void 0;
61
+ }
62
+ dir = parent;
63
+ }
64
+ } catch {
65
+ return void 0;
66
+ }
67
+ }
68
+ function packagePath(packageName, relativePath = "", resolveFrom = RESOLVE_FROM) {
69
+ const packageDir = resolvePackageDir(packageName, resolveFrom);
70
+ return packageDir && import_node_path.default.join(packageDir, relativePath);
71
+ }
72
+ function resolveSubpath(specifier, resolveFrom = RESOLVE_FROM) {
73
+ try {
74
+ return require.resolve(specifier, { paths: resolveFrom });
75
+ } catch {
76
+ return void 0;
77
+ }
78
+ }
79
+ const cedarWebDir = resolvePackageDir("@cedarjs/web");
80
+ const cedarWebResolveFrom = cedarWebDir ? [cedarWebDir, ...RESOLVE_FROM] : RESOLVE_FROM;
81
+ function definedEntries(mappings) {
82
+ return Object.fromEntries(
83
+ Object.entries(mappings).filter(
84
+ (entry) => entry[1] !== void 0
85
+ )
86
+ );
87
+ }
38
88
  const config = {
39
89
  // To make sure other config option which depends on rootDir always
40
90
  // use correct path, for example, coverageDirectory
@@ -72,42 +122,41 @@ const config = {
72
122
  ],
73
123
  setupFilesAfterEnv: [import_node_path.default.resolve(__dirname, "./jest.setup.js")],
74
124
  moduleNameMapper: {
75
- /**
76
- * Make sure modules that require different versions of these
77
- * dependencies end up using the same one.
78
- */
79
- "^react$": import_node_path.default.join(NODE_MODULES_PATH, "react"),
80
- "^react-dom$": import_node_path.default.join(NODE_MODULES_PATH, "react-dom"),
81
- // Point straight at Apollo Client's CJS build. Mapping to the package
82
- // directory would bypass its `exports` map and land on the ESM build,
83
- // and `require.resolve` can't be used either because Node 22+ resolves
84
- // it through the `module-sync` condition (also ESM) both of which Jest
85
- // can't parse
86
- "^@apollo/client/react$": import_node_path.default.join(
87
- NODE_MODULES_PATH,
88
- "@apollo/client/__cjs/react/index.cjs"
89
- ),
90
- // We replace imports to "@cedarjs/router" with our own "mock" implementation.
91
- "^@cedarjs/router$": import_node_path.default.join(
92
- NODE_MODULES_PATH,
93
- "@cedarjs/testing/dist/cjs/web/MockRouter.js"
94
- ),
95
- "^@cedarjs/web$": import_node_path.default.join(NODE_MODULES_PATH, "@cedarjs/web/dist/cjs"),
96
- // This allows us to mock `createAuthentication` which is used by auth
97
- // clients, which in turn lets us mock `useAuth` in tests
98
- "^@cedarjs/auth$": import_node_path.default.join(
99
- NODE_MODULES_PATH,
100
- "@cedarjs/testing/dist/cjs/web/mockAuth.js"
101
- ),
102
- // @NOTE: Import @cedarjs/testing in web tests, and it automatically remaps to the web side only
103
- // This is to prevent web stuff leaking into api, and vice versa
104
- "^@cedarjs/testing$": import_node_path.default.join(NODE_MODULES_PATH, "@cedarjs/testing/web"),
125
+ ...definedEntries({
126
+ /**
127
+ * Make sure modules that require different versions of these
128
+ * dependencies end up using the same one.
129
+ */
130
+ "^react$": resolveSubpath("react"),
131
+ "^react-dom$": resolveSubpath("react-dom"),
132
+ // Point straight at Apollo Client's CJS build. Resolving the subpath
133
+ // would go through its `exports` map and land on the ESM build (Node 22+
134
+ // picks the `module-sync` condition), which Jest can't parse.
135
+ // Resolved starting from `@cedarjs/web` because that's what depends on
136
+ // Apollo — a project doesn't declare it itself, so under pnpm it isn't
137
+ // reachable from the web side at all, and searching from there finds
138
+ // either nothing or some unrelated copy pulled in by another dependency
139
+ "^@apollo/client/react$": packagePath(
140
+ "@apollo/client",
141
+ "__cjs/react/index.cjs",
142
+ cedarWebResolveFrom
143
+ ),
144
+ // We replace imports to "@cedarjs/router" with our own "mock" implementation.
145
+ "^@cedarjs/router$": resolveSubpath("@cedarjs/testing/web/MockRouter.js"),
146
+ "^@cedarjs/web$": resolveSubpath("@cedarjs/web"),
147
+ // This allows us to mock `createAuthentication` which is used by auth
148
+ // clients, which in turn lets us mock `useAuth` in tests
149
+ "^@cedarjs/auth$": resolveSubpath("@cedarjs/testing/auth"),
150
+ // @NOTE: Import @cedarjs/testing in web tests, and it automatically remaps to the web side only
151
+ // This is to prevent web stuff leaking into api, and vice versa
152
+ "^@cedarjs/testing$": resolveSubpath("@cedarjs/testing/web"),
153
+ /**
154
+ * Mock out files that aren't particularly useful in tests. See fileMock.js for more info.
155
+ */
156
+ "\\.(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")
157
+ }),
105
158
  "~__CEDAR__USER_ROUTES_FOR_MOCK": cedarPaths.web.routes,
106
159
  "~__CEDAR__USER_AUTH_FOR_MOCK": import_node_path.default.join(cedarPaths.web.src, "auth"),
107
- /**
108
- * Mock out files that aren't particularly useful in tests. See fileMock.js for more info.
109
- */
110
- "\\.(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",
111
160
  // Support for importing files with extensions (like you'd do in ESM projects)
112
161
  "^(\\.{1,2}/.*)\\.js$": "$1"
113
162
  },
@@ -1 +1 @@
1
- {"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AASlC,QAAA,MAAM,MAAM,EAAE,MA0Db,CAAA;AAED,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAkClC,QAAA,MAAM,MAAM,EAAE,MA0Db,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -35,8 +35,17 @@ var import_node_path = __toESM(require("node:path"), 1);
35
35
  var import_babel_config = require("@cedarjs/babel-config");
36
36
  var import_project_config = require("@cedarjs/project-config");
37
37
  const rwjsPaths = (0, import_project_config.getPaths)();
38
- const NODE_MODULES_PATH = import_node_path.default.join(rwjsPaths.base, "node_modules");
39
38
  const { babelrc } = (0, import_babel_config.getApiSideDefaultBabelConfig)({ forJest: true });
39
+ function resolveSubpath(specifier) {
40
+ try {
41
+ return require.resolve(specifier, {
42
+ paths: [rwjsPaths.api.base, rwjsPaths.base]
43
+ });
44
+ } catch {
45
+ return void 0;
46
+ }
47
+ }
48
+ const testingApiPath = resolveSubpath("@cedarjs/testing/api");
40
49
  const config = {
41
50
  // To make sure other config option which depends on rootDir use
42
51
  // correct path, for example, coverageDirectory
@@ -77,7 +86,7 @@ const config = {
77
86
  "^src/(.*)$": import_node_path.default.join(rwjsPaths.api.src, "$1"),
78
87
  // @NOTE: Import @cedarjs/testing in api tests, and it automatically remaps to the api side only
79
88
  // This is to prevent web stuff leaking into api, and vice versa
80
- "^@cedarjs/testing$": import_node_path.default.join(NODE_MODULES_PATH, "@cedarjs/testing/api"),
89
+ ...testingApiPath ? { "^@cedarjs/testing$": testingApiPath } : {},
81
90
  // Support for importing files with extensions (like you'd do in ESM projects)
82
91
  "^(\\.{1,2}/.*)\\.js$": "$1"
83
92
  },
@@ -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,MAyHb,CAAA;AAED,eAAe,MAAM,CAAA"}
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,MAwHb,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -31,10 +31,60 @@ __export(jest_preset_exports, {
31
31
  default: () => jest_preset_default
32
32
  });
33
33
  module.exports = __toCommonJS(jest_preset_exports);
34
+ var import_node_fs = __toESM(require("node:fs"), 1);
34
35
  var import_node_path = __toESM(require("node:path"), 1);
35
36
  var import_project_config = require("@cedarjs/project-config");
36
37
  const cedarPaths = (0, import_project_config.getPaths)();
37
- const NODE_MODULES_PATH = import_node_path.default.join(cedarPaths.base, "node_modules");
38
+ const RESOLVE_FROM = [cedarPaths.web.base, cedarPaths.base];
39
+ function resolvePackageDir(packageName, resolveFrom = RESOLVE_FROM) {
40
+ try {
41
+ return import_node_path.default.dirname(
42
+ require.resolve(`${packageName}/package.json`, { paths: resolveFrom })
43
+ );
44
+ } catch {
45
+ }
46
+ try {
47
+ let dir = import_node_path.default.dirname(require.resolve(packageName, { paths: resolveFrom }));
48
+ for (; ; ) {
49
+ const manifestPath = import_node_path.default.join(dir, "package.json");
50
+ if (import_node_fs.default.existsSync(manifestPath)) {
51
+ const manifest = JSON.parse(
52
+ import_node_fs.default.readFileSync(manifestPath, "utf-8")
53
+ );
54
+ if (manifest && typeof manifest === "object" && "name" in manifest && manifest.name === packageName) {
55
+ return dir;
56
+ }
57
+ }
58
+ const parent = import_node_path.default.dirname(dir);
59
+ if (parent === dir) {
60
+ return void 0;
61
+ }
62
+ dir = parent;
63
+ }
64
+ } catch {
65
+ return void 0;
66
+ }
67
+ }
68
+ function packagePath(packageName, relativePath = "", resolveFrom = RESOLVE_FROM) {
69
+ const packageDir = resolvePackageDir(packageName, resolveFrom);
70
+ return packageDir && import_node_path.default.join(packageDir, relativePath);
71
+ }
72
+ function resolveSubpath(specifier, resolveFrom = RESOLVE_FROM) {
73
+ try {
74
+ return require.resolve(specifier, { paths: resolveFrom });
75
+ } catch {
76
+ return void 0;
77
+ }
78
+ }
79
+ const cedarWebDir = resolvePackageDir("@cedarjs/web");
80
+ const cedarWebResolveFrom = cedarWebDir ? [cedarWebDir, ...RESOLVE_FROM] : RESOLVE_FROM;
81
+ function definedEntries(mappings) {
82
+ return Object.fromEntries(
83
+ Object.entries(mappings).filter(
84
+ (entry) => entry[1] !== void 0
85
+ )
86
+ );
87
+ }
38
88
  const config = {
39
89
  // To make sure other config option which depends on rootDir always
40
90
  // use correct path, for example, coverageDirectory
@@ -72,42 +122,41 @@ const config = {
72
122
  ],
73
123
  setupFilesAfterEnv: [import_node_path.default.resolve(__dirname, "./jest.setup.js")],
74
124
  moduleNameMapper: {
75
- /**
76
- * Make sure modules that require different versions of these
77
- * dependencies end up using the same one.
78
- */
79
- "^react$": import_node_path.default.join(NODE_MODULES_PATH, "react"),
80
- "^react-dom$": import_node_path.default.join(NODE_MODULES_PATH, "react-dom"),
81
- // Point straight at Apollo Client's CJS build. Mapping to the package
82
- // directory would bypass its `exports` map and land on the ESM build,
83
- // and `require.resolve` can't be used either because Node 22+ resolves
84
- // it through the `module-sync` condition (also ESM) both of which Jest
85
- // can't parse
86
- "^@apollo/client/react$": import_node_path.default.join(
87
- NODE_MODULES_PATH,
88
- "@apollo/client/__cjs/react/index.cjs"
89
- ),
90
- // We replace imports to "@cedarjs/router" with our own "mock" implementation.
91
- "^@cedarjs/router$": import_node_path.default.join(
92
- NODE_MODULES_PATH,
93
- "@cedarjs/testing/dist/cjs/web/MockRouter.js"
94
- ),
95
- "^@cedarjs/web$": import_node_path.default.join(NODE_MODULES_PATH, "@cedarjs/web/dist/cjs"),
96
- // This allows us to mock `createAuthentication` which is used by auth
97
- // clients, which in turn lets us mock `useAuth` in tests
98
- "^@cedarjs/auth$": import_node_path.default.join(
99
- NODE_MODULES_PATH,
100
- "@cedarjs/testing/dist/cjs/web/mockAuth.js"
101
- ),
102
- // @NOTE: Import @cedarjs/testing in web tests, and it automatically remaps to the web side only
103
- // This is to prevent web stuff leaking into api, and vice versa
104
- "^@cedarjs/testing$": import_node_path.default.join(NODE_MODULES_PATH, "@cedarjs/testing/web"),
125
+ ...definedEntries({
126
+ /**
127
+ * Make sure modules that require different versions of these
128
+ * dependencies end up using the same one.
129
+ */
130
+ "^react$": resolveSubpath("react"),
131
+ "^react-dom$": resolveSubpath("react-dom"),
132
+ // Point straight at Apollo Client's CJS build. Resolving the subpath
133
+ // would go through its `exports` map and land on the ESM build (Node 22+
134
+ // picks the `module-sync` condition), which Jest can't parse.
135
+ // Resolved starting from `@cedarjs/web` because that's what depends on
136
+ // Apollo — a project doesn't declare it itself, so under pnpm it isn't
137
+ // reachable from the web side at all, and searching from there finds
138
+ // either nothing or some unrelated copy pulled in by another dependency
139
+ "^@apollo/client/react$": packagePath(
140
+ "@apollo/client",
141
+ "__cjs/react/index.cjs",
142
+ cedarWebResolveFrom
143
+ ),
144
+ // We replace imports to "@cedarjs/router" with our own "mock" implementation.
145
+ "^@cedarjs/router$": resolveSubpath("@cedarjs/testing/web/MockRouter.js"),
146
+ "^@cedarjs/web$": resolveSubpath("@cedarjs/web"),
147
+ // This allows us to mock `createAuthentication` which is used by auth
148
+ // clients, which in turn lets us mock `useAuth` in tests
149
+ "^@cedarjs/auth$": resolveSubpath("@cedarjs/testing/auth"),
150
+ // @NOTE: Import @cedarjs/testing in web tests, and it automatically remaps to the web side only
151
+ // This is to prevent web stuff leaking into api, and vice versa
152
+ "^@cedarjs/testing$": resolveSubpath("@cedarjs/testing/web"),
153
+ /**
154
+ * Mock out files that aren't particularly useful in tests. See fileMock.js for more info.
155
+ */
156
+ "\\.(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")
157
+ }),
105
158
  "~__CEDAR__USER_ROUTES_FOR_MOCK": cedarPaths.web.routes,
106
159
  "~__CEDAR__USER_AUTH_FOR_MOCK": import_node_path.default.join(cedarPaths.web.src, "auth"),
107
- /**
108
- * Mock out files that aren't particularly useful in tests. See fileMock.js for more info.
109
- */
110
- "\\.(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",
111
160
  // Support for importing files with extensions (like you'd do in ESM projects)
112
161
  "^(\\.{1,2}/.*)\\.js$": "$1"
113
162
  },
@@ -1 +1 @@
1
- {"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AASlC,QAAA,MAAM,MAAM,EAAE,MA0Db,CAAA;AAED,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"jest-preset.d.ts","sourceRoot":"","sources":["../../../../src/config/jest/api/jest-preset.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAkClC,QAAA,MAAM,MAAM,EAAE,MA0Db,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -2,8 +2,17 @@ import path from "node:path";
2
2
  import { getApiSideDefaultBabelConfig } from "@cedarjs/babel-config";
3
3
  import { getPaths } from "@cedarjs/project-config";
4
4
  const rwjsPaths = getPaths();
5
- const NODE_MODULES_PATH = path.join(rwjsPaths.base, "node_modules");
6
5
  const { babelrc } = getApiSideDefaultBabelConfig({ forJest: true });
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");
7
16
  const config = {
8
17
  // To make sure other config option which depends on rootDir use
9
18
  // correct path, for example, coverageDirectory
@@ -44,7 +53,7 @@ const config = {
44
53
  "^src/(.*)$": path.join(rwjsPaths.api.src, "$1"),
45
54
  // @NOTE: Import @cedarjs/testing in api tests, and it automatically remaps to the api side only
46
55
  // This is to prevent web stuff leaking into api, and vice versa
47
- "^@cedarjs/testing$": path.join(NODE_MODULES_PATH, "@cedarjs/testing/api"),
56
+ ...testingApiPath ? { "^@cedarjs/testing$": testingApiPath } : {},
48
57
  // Support for importing files with extensions (like you'd do in ESM projects)
49
58
  "^(\\.{1,2}/.*)\\.js$": "$1"
50
59
  },
@@ -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,MAyHb,CAAA;AAED,eAAe,MAAM,CAAA"}
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,MAwHb,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -1,7 +1,57 @@
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
@@ -39,42 +89,41 @@ const config = {
39
89
  ],
40
90
  setupFilesAfterEnv: [path.resolve(__dirname, "./jest.setup.js")],
41
91
  moduleNameMapper: {
42
- /**
43
- * Make sure modules that require different versions of these
44
- * dependencies end up using the same one.
45
- */
46
- "^react$": path.join(NODE_MODULES_PATH, "react"),
47
- "^react-dom$": path.join(NODE_MODULES_PATH, "react-dom"),
48
- // Point straight at Apollo Client's CJS build. Mapping to the package
49
- // directory would bypass its `exports` map and land on the ESM build,
50
- // and `require.resolve` can't be used either because Node 22+ resolves
51
- // it through the `module-sync` condition (also ESM) both of which Jest
52
- // can't parse
53
- "^@apollo/client/react$": path.join(
54
- NODE_MODULES_PATH,
55
- "@apollo/client/__cjs/react/index.cjs"
56
- ),
57
- // We replace imports to "@cedarjs/router" with our own "mock" implementation.
58
- "^@cedarjs/router$": path.join(
59
- NODE_MODULES_PATH,
60
- "@cedarjs/testing/dist/cjs/web/MockRouter.js"
61
- ),
62
- "^@cedarjs/web$": path.join(NODE_MODULES_PATH, "@cedarjs/web/dist/cjs"),
63
- // This allows us to mock `createAuthentication` which is used by auth
64
- // clients, which in turn lets us mock `useAuth` in tests
65
- "^@cedarjs/auth$": path.join(
66
- NODE_MODULES_PATH,
67
- "@cedarjs/testing/dist/cjs/web/mockAuth.js"
68
- ),
69
- // @NOTE: Import @cedarjs/testing in web tests, and it automatically remaps to the web side only
70
- // This is to prevent web stuff leaking into api, and vice versa
71
- "^@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
+ }),
72
125
  "~__CEDAR__USER_ROUTES_FOR_MOCK": cedarPaths.web.routes,
73
126
  "~__CEDAR__USER_AUTH_FOR_MOCK": path.join(cedarPaths.web.src, "auth"),
74
- /**
75
- * Mock out files that aren't particularly useful in tests. See fileMock.js for more info.
76
- */
77
- "\\.(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",
78
127
  // Support for importing files with extensions (like you'd do in ESM projects)
79
128
  "^(\\.{1,2}/.*)\\.js$": "$1"
80
129
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/testing",
3
- "version": "6.0.0-canary.2691",
3
+ "version": "6.0.0-canary.2692",
4
4
  "description": "Tools, wrappers and configuration for testing a Cedar project.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -117,10 +117,10 @@
117
117
  },
118
118
  "dependencies": {
119
119
  "@babel/preset-env": "7.29.7",
120
- "@cedarjs/babel-config": "6.0.0-canary.2691",
121
- "@cedarjs/context": "6.0.0-canary.2691",
122
- "@cedarjs/graphql-server": "6.0.0-canary.2691",
123
- "@cedarjs/project-config": "6.0.0-canary.2691",
120
+ "@cedarjs/babel-config": "6.0.0-canary.2692",
121
+ "@cedarjs/context": "6.0.0-canary.2692",
122
+ "@cedarjs/graphql-server": "6.0.0-canary.2692",
123
+ "@cedarjs/project-config": "6.0.0-canary.2692",
124
124
  "@testing-library/dom": "10.4.1",
125
125
  "@testing-library/jest-dom": "6.9.1",
126
126
  "@testing-library/react": "16.3.2",
@@ -142,10 +142,10 @@
142
142
  },
143
143
  "devDependencies": {
144
144
  "@arethetypeswrong/cli": "0.18.5",
145
- "@cedarjs/auth": "6.0.0-canary.2691",
146
- "@cedarjs/framework-tools": "6.0.0-canary.2691",
147
- "@cedarjs/router": "6.0.0-canary.2691",
148
- "@cedarjs/web": "6.0.0-canary.2691",
145
+ "@cedarjs/auth": "6.0.0-canary.2692",
146
+ "@cedarjs/framework-tools": "6.0.0-canary.2692",
147
+ "@cedarjs/router": "6.0.0-canary.2692",
148
+ "@cedarjs/web": "6.0.0-canary.2692",
149
149
  "concurrently": "9.2.1",
150
150
  "jsdom": "27.4.0",
151
151
  "publint": "0.3.21",