@wandelbots/wandelbots-js-react-components 5.4.2-pr.feat-default-imports.588.3b3ee83 → 5.4.2-pr.feat-default-imports.588.ca72d67

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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=consumer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumer.test.d.ts","sourceRoot":"","sources":["../../src/test/consumer.test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wandelbots/wandelbots-js-react-components",
3
- "version": "5.4.2-pr.feat-default-imports.588.3b3ee83",
3
+ "version": "5.4.2-pr.feat-default-imports.588.ca72d67",
4
4
  "description": "React UI toolkit for building applications on top of the Wandelbots platform",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -50,6 +50,7 @@
50
50
  "test": "test-storybook --url http://127.0.0.1:6006 --index-json --browsers chromium",
51
51
  "test:unit": "vitest --workspace vitest.workspace.ts --project unit",
52
52
  "test:unit:run": "vitest run --workspace vitest.workspace.ts --project unit",
53
+ "test:consumer": "pnpm run build && vitest run --workspace vitest.workspace.ts --project consumer",
53
54
  "ci:test": "run-s ci:test:build ci:test:built",
54
55
  "ci:test:build": "storybook build --quiet --test",
55
56
  "ci:test:built": "run-p --race ci:test:server ci:test:runner",
@@ -0,0 +1,230 @@
1
+ /**
2
+ * Consumer import tests.
3
+ *
4
+ * These tests run against the built dist/ output, exercising the package's
5
+ * `exports` map the same way a real downstream consumer would. They check:
6
+ *
7
+ * 1. Every public subpath resolves via Node's `exports` resolver to a file
8
+ * that actually exists on disk (ESM, CJS, and .d.ts).
9
+ * 2. The wildcard subpath export lets consumers deep-import any module
10
+ * under src/ (including folder-based ones like Timer/CycleTimer that
11
+ * have a sibling barrel).
12
+ * 3. Named exports remain importable AND the MUI-style default export is
13
+ * also available and identical to the named one for primary components.
14
+ *
15
+ * Run via `pnpm test:consumer` (which builds first) or as part of
16
+ * `pnpm test:unit:run` once dist/ exists.
17
+ */
18
+ import { execFileSync } from "node:child_process"
19
+ import {
20
+ existsSync,
21
+ mkdirSync,
22
+ rmSync,
23
+ symlinkSync,
24
+ writeFileSync,
25
+ } from "node:fs"
26
+ import { createRequire } from "node:module"
27
+ import { dirname, resolve } from "node:path"
28
+ import { fileURLToPath } from "node:url"
29
+ import { afterAll, beforeAll, describe, expect, it } from "vitest"
30
+
31
+ const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../..")
32
+ const distDir = resolve(repoRoot, "dist")
33
+ const pkgName = "@wandelbots/wandelbots-js-react-components"
34
+
35
+ // Create a scratch directory outside the repo with a node_modules symlink
36
+ // pointing at the repo, so the Node resolver treats us as if we were
37
+ // installed as a dependency.
38
+ const sandbox = resolve(repoRoot, ".tmp-consumer-test")
39
+ const sandboxReq = createRequire(resolve(sandbox, "consumer.cjs"))
40
+ // A tiny .mjs helper that prints the ESM resolution of `process.argv[2]`.
41
+ // We invoke it as a child Node process because Vite's SSR runtime (used by
42
+ // vitest) strips `import.meta.resolve`, and we specifically want to verify
43
+ // Node's own resolver honours our `exports` map.
44
+ const esmResolverScript = resolve(sandbox, "resolve-esm.mjs")
45
+
46
+ beforeAll(() => {
47
+ if (!existsSync(distDir)) {
48
+ throw new Error(
49
+ "dist/ not found. Run `pnpm build` before running the consumer tests.",
50
+ )
51
+ }
52
+ rmSync(sandbox, { recursive: true, force: true })
53
+ mkdirSync(resolve(sandbox, "node_modules/@wandelbots"), { recursive: true })
54
+ symlinkSync(repoRoot, resolve(sandbox, "node_modules", pkgName), "dir")
55
+ writeFileSync(
56
+ esmResolverScript,
57
+ 'import { fileURLToPath } from "node:url"\n' +
58
+ "process.stdout.write(fileURLToPath(import.meta.resolve(process.argv[2])))\n",
59
+ )
60
+ })
61
+
62
+ afterAll(() => {
63
+ rmSync(sandbox, { recursive: true, force: true })
64
+ })
65
+
66
+ function resolveEsm(spec: string): string {
67
+ return execFileSync(process.execPath, [esmResolverScript, spec], {
68
+ encoding: "utf8",
69
+ cwd: sandbox,
70
+ })
71
+ }
72
+
73
+ function resolveCjs(spec: string): string {
74
+ return sandboxReq.resolve(spec)
75
+ }
76
+
77
+ // The exports map doesn't advertise a `types` condition, but TypeScript's
78
+ // resolver uses the same path with a `.d.ts` extension. Probe the ESM path
79
+ // and swap the extension.
80
+ function typesFor(esmPath: string): string {
81
+ return esmPath.replace(/\.js$/, ".d.ts")
82
+ }
83
+
84
+ describe("package exports — aggregate entries", () => {
85
+ const entries = [
86
+ { spec: pkgName, esm: "dist/index.js", cjs: "dist/index.cjs" },
87
+ { spec: `${pkgName}/core`, esm: "dist/core.js", cjs: "dist/core.cjs" },
88
+ { spec: `${pkgName}/3d`, esm: "dist/3d.js", cjs: "dist/3d.cjs" },
89
+ {
90
+ spec: `${pkgName}/wb-icons`,
91
+ esm: "dist/wb-icons.js",
92
+ cjs: "dist/wb-icons.cjs",
93
+ },
94
+ ]
95
+
96
+ it.each(entries)("$spec resolves ESM, CJS, and types", ({
97
+ spec,
98
+ esm,
99
+ cjs,
100
+ }) => {
101
+ const esmPath = resolveEsm(spec)
102
+ const cjsPath = resolveCjs(spec)
103
+ expect(esmPath).toBe(resolve(repoRoot, esm))
104
+ expect(cjsPath).toBe(resolve(repoRoot, cjs))
105
+ expect(existsSync(esmPath)).toBe(true)
106
+ expect(existsSync(cjsPath)).toBe(true)
107
+ expect(existsSync(typesFor(esmPath))).toBe(true)
108
+ })
109
+ })
110
+
111
+ describe("package exports — deep component imports", () => {
112
+ const specs = [
113
+ // File-backed modules resolved via the "./*" wildcard.
114
+ "components/DataGrid",
115
+ "components/AppHeader",
116
+ "components/LogPanel",
117
+ "components/ProgramControl",
118
+ "components/RobotCard",
119
+ "components/TabBar",
120
+ "components/VelocitySlider",
121
+ "components/jogging/JoggingPanel",
122
+ "components/jogging/JoggingStore",
123
+ "components/jogging/JoggingCartesianAxisControl",
124
+ "components/safetyBar/SafetyBar",
125
+ "components/3d-viewport/SafetyZonesRenderer",
126
+ "components/3d-viewport/TrajectoryRenderer",
127
+ "components/robots/Robot",
128
+ "components/robots/MotionGroupVisualizer",
129
+ "components/modal/NoMotionGroupModal",
130
+ "lib/ConnectedMotionGroup",
131
+ "lib/JoggerConnection",
132
+ "lib/MotionStreamConnection",
133
+ "themes/createDarkTheme",
134
+ // Directory-backed modules that have a sibling barrel so the wildcard
135
+ // subpath still resolves. Regression test for copilot review comment.
136
+ "components/Timer",
137
+ "components/CycleTimer",
138
+ ]
139
+
140
+ it.each(specs)("%s resolves ESM, CJS, and types", (sub) => {
141
+ const spec = `${pkgName}/${sub}`
142
+ const esmPath = resolveEsm(spec)
143
+ const cjsPath = resolveCjs(spec)
144
+ expect(esmPath).toMatch(/\.js$/)
145
+ expect(cjsPath).toMatch(/\.cjs$/)
146
+ expect(existsSync(esmPath)).toBe(true)
147
+ expect(existsSync(cjsPath)).toBe(true)
148
+ expect(existsSync(typesFor(esmPath))).toBe(true)
149
+ })
150
+ })
151
+
152
+ describe("MUI-style default + named exports", () => {
153
+ // These modules are the primary public "one-component-per-file" entries
154
+ // that downstream apps will import directly. Each must expose both a
155
+ // named export (preserving the existing API) and a matching `default`
156
+ // export (the MUI-style convention introduced by this PR).
157
+ const cases = [
158
+ { sub: "components/DataGrid", name: "WandelbotsDataGrid" },
159
+ { sub: "components/AppHeader", name: "AppHeader" },
160
+ { sub: "components/TabBar", name: "TabBar" },
161
+ { sub: "components/ProgramControl", name: "ProgramControl" },
162
+ { sub: "components/RobotCard", name: "RobotCard" },
163
+ { sub: "components/VelocitySlider", name: "VelocitySlider" },
164
+ { sub: "components/jogging/JoggingPanel", name: "JoggingPanel" },
165
+ { sub: "components/jogging/JoggingStore", name: "JoggingStore" },
166
+ { sub: "components/safetyBar/SafetyBar", name: "SafetyBar" },
167
+ { sub: "components/Timer", name: "Timer" },
168
+ { sub: "components/CycleTimer", name: "CycleTimer" },
169
+ { sub: "lib/ConnectedMotionGroup", name: "ConnectedMotionGroup" },
170
+ { sub: "lib/JoggerConnection", name: "JoggerConnection" },
171
+ { sub: "lib/MotionStreamConnection", name: "MotionStreamConnection" },
172
+ ]
173
+
174
+ it.each(cases)("$sub exposes $name as both named and default", async ({
175
+ sub,
176
+ name,
177
+ }) => {
178
+ const mod = (await import(`${pkgName}/${sub}`)) as Record<string, unknown>
179
+ expect(mod[name], `missing named export ${name}`).toBeDefined()
180
+ expect(mod.default, "missing default export").toBeDefined()
181
+ expect(mod.default).toBe(mod[name])
182
+ })
183
+ })
184
+
185
+ describe("aggregate barrel preserves named exports", () => {
186
+ it("@wandelbots/.../core re-exports the same symbols as deep imports", async () => {
187
+ const core = await import(`${pkgName}/core`)
188
+ const deep = await import(`${pkgName}/components/DataGrid`)
189
+ expect(core.WandelbotsDataGrid).toBe(deep.WandelbotsDataGrid)
190
+ })
191
+
192
+ it("@wandelbots/.../3d re-exports the same symbols as deep imports", async () => {
193
+ const agg = await import(`${pkgName}/3d`)
194
+ const deep = await import(`${pkgName}/components/robots/Robot`)
195
+ expect(agg.Robot).toBe(deep.Robot)
196
+ })
197
+ })
198
+
199
+ describe("CJS interop", () => {
200
+ it("require() returns the same symbols as import", async () => {
201
+ const esm = (await import(`${pkgName}/components/DataGrid`)) as Record<
202
+ string,
203
+ unknown
204
+ >
205
+ const cjs = sandboxReq(`${pkgName}/components/DataGrid`) as Record<
206
+ string,
207
+ unknown
208
+ >
209
+ expect(cjs.default).toBe(cjs.WandelbotsDataGrid)
210
+ // Both resolvers must reach a real, loadable module (the identities
211
+ // naturally differ between ESM/CJS, so we compare by exported keys).
212
+ expect(Object.keys(cjs).sort()).toEqual(Object.keys(esm).sort())
213
+ })
214
+
215
+ it('Node can load the CJS output under `"type": "module"`', () => {
216
+ // Sanity check that `.cjs` extension was emitted (not `.cjs.js`) so
217
+ // that Node's CJS loader accepts it despite the package being ESM.
218
+ const output = execFileSync(
219
+ process.execPath,
220
+ [
221
+ "-e",
222
+ "const m = require(process.argv[1]); " +
223
+ "console.log(typeof m.WandelbotsDataGrid);",
224
+ resolve(repoRoot, "dist/components/DataGrid.cjs"),
225
+ ],
226
+ { encoding: "utf8" },
227
+ ).trim()
228
+ expect(output).toBe("function")
229
+ })
230
+ })