@bonsae/nrg 0.17.0 → 0.18.1
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/README.md +48 -36
- package/package.json +21 -3
- package/server/resources/nrg-client.js +3393 -3307
- package/test/client/component/config.js +37 -0
- package/test/client/component/index.js +35 -10
- package/test/client/component/setup.js +10 -0
- package/test/client/e2e/index.js +4 -4
- package/test/client/unit/config.js +26 -0
- package/test/client/unit/index.js +28 -7
- package/test/client/unit/setup.js +10 -0
- package/test/server/unit/config.js +15 -0
- package/test/server/unit/index.js +16 -2
- package/types/client.d.ts +66 -0
- package/types/server.d.ts +7 -2
- package/types/shims/form/components/node-red-config-input.vue.d.ts +3 -1
- package/types/shims/form/components/node-red-editor-input.vue.d.ts +4 -1
- package/types/shims/form/components/node-red-json-schema-form.vue.d.ts +38 -10
- package/types/shims/form/components/node-red-select-input.vue.d.ts +3 -1
- package/types/shims/form/components/node-red-typed-input.vue.d.ts +28 -7
- package/types/test-client-component.d.ts +94 -9
- package/types/test-client-unit.d.ts +89 -5
- package/types/test-server-unit.d.ts +7 -0
- package/vite/index.js +10 -6
package/README.md
CHANGED
|
@@ -19,12 +19,15 @@ Build Node-RED nodes with Vue 3, TypeScript, JSON Schema validations, Vite and V
|
|
|
19
19
|
| --- | --- |
|
|
20
20
|
| `@bonsae/nrg` | Root entry — `defineRuntimeSettings` |
|
|
21
21
|
| `@bonsae/nrg/server` | Server node classes, schema utilities, validation (`IONode`, `ConfigNode`, `defineIONode`, `defineConfigNode`, `defineModule`, `SchemaType`, `defineSchema`, `Infer`) |
|
|
22
|
-
| `@bonsae/nrg/client` | Client-side registration (`registerTypes`, `defineNode`) |
|
|
22
|
+
| `@bonsae/nrg/client` | Client-side registration (`registerTypes`, `defineNode`, `useFormNode`, `Infer`) |
|
|
23
23
|
| `@bonsae/nrg/vite` | Vite plugin for building and developing Node-RED packages |
|
|
24
24
|
| `@bonsae/nrg/test/server/unit` | Server unit test helpers (`createNode`, `createRED`, `MockRED`) |
|
|
25
|
-
| `@bonsae/nrg/test/
|
|
25
|
+
| `@bonsae/nrg/test/server/unit/config` | Server unit test default vitest config (`defaultConfig`) |
|
|
26
|
+
| `@bonsae/nrg/test/client/unit` | Client unit test mocks (`createRED`, `createJQuery`, `useFormNode`) |
|
|
27
|
+
| `@bonsae/nrg/test/client/unit/config` | Client unit test default vitest config (`defaultConfig`) |
|
|
26
28
|
| `@bonsae/nrg/test/client/unit/setup` | Setup file that installs `RED` and `$` mocks on `window` |
|
|
27
|
-
| `@bonsae/nrg/test/client/component` | Client component test helpers (`createNode`, `
|
|
29
|
+
| `@bonsae/nrg/test/client/component` | Client component test helpers (`createNode`, `createRED`, `createJQuery`, `useFormNode`) |
|
|
30
|
+
| `@bonsae/nrg/test/client/component/config` | Client component test default vitest config (`defaultConfig`) |
|
|
28
31
|
| `@bonsae/nrg/test/client/component/setup` | Setup file that installs `RED` and `$` mocks on `window` with Vue i18n |
|
|
29
32
|
| `@bonsae/nrg/test/client/e2e` | Browser E2E test helpers (`NodeRedEditor`, `NodeRedField`, `setup`, `teardown`) |
|
|
30
33
|
| `@bonsae/nrg/tsconfig/base.json` | Base TypeScript configuration |
|
|
@@ -106,7 +109,7 @@ type Config = Infer<typeof ConfigsSchema>;
|
|
|
106
109
|
type Input = Infer<typeof InputSchema>;
|
|
107
110
|
type Output = Infer<typeof OutputSchema>;
|
|
108
111
|
|
|
109
|
-
export default class MyNode extends IONode<Config,
|
|
112
|
+
export default class MyNode extends IONode<Config, never, Input, Output> {
|
|
110
113
|
static readonly type = "my-node";
|
|
111
114
|
static readonly category = "function";
|
|
112
115
|
static readonly color: `#${string}` = "#ffffff";
|
|
@@ -142,7 +145,13 @@ See the [consumer template](https://github.com/AllanOricil/node-red-vue-template
|
|
|
142
145
|
|
|
143
146
|
## Testing
|
|
144
147
|
|
|
145
|
-
NRG provides four test libraries
|
|
148
|
+
NRG provides four test libraries and bundles all test infrastructure (happy-dom, Playwright, Vue plugin, browser utilities) as direct dependencies. The only package you need to install yourself is `vitest`:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
pnpm add -D vitest
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Coverage providers are optional peer dependencies — install `@vitest/coverage-v8` or `@vitest/coverage-istanbul` only if you run with `--coverage`.
|
|
146
155
|
|
|
147
156
|
- `@bonsae/nrg/test/server/unit` — server-side unit tests
|
|
148
157
|
- `@bonsae/nrg/test/client/unit` — client-side unit tests (TypeScript logic)
|
|
@@ -174,15 +183,15 @@ describe("my-node", () => {
|
|
|
174
183
|
Test client-side TypeScript logic (validation, utilities) with mocked `RED` and `$` globals:
|
|
175
184
|
|
|
176
185
|
```typescript
|
|
177
|
-
// vitest.config.ts
|
|
178
|
-
import { defineConfig } from "vitest/config";
|
|
179
|
-
import { defaultConfig } from "@bonsae/nrg/test/client/unit";
|
|
186
|
+
// vitest.client.unit.config.ts
|
|
187
|
+
import { defineConfig, mergeConfig } from "vitest/config";
|
|
188
|
+
import { defaultConfig } from "@bonsae/nrg/test/client/unit/config";
|
|
180
189
|
|
|
181
|
-
export default defineConfig({
|
|
190
|
+
export default mergeConfig(defaultConfig, defineConfig({
|
|
182
191
|
test: {
|
|
183
|
-
|
|
192
|
+
include: ["tests/client/unit/**/*.test.ts"],
|
|
184
193
|
},
|
|
185
|
-
});
|
|
194
|
+
}));
|
|
186
195
|
```
|
|
187
196
|
|
|
188
197
|
```typescript
|
|
@@ -199,46 +208,49 @@ describe("myUtil", () => {
|
|
|
199
208
|
|
|
200
209
|
### Client Component Tests
|
|
201
210
|
|
|
202
|
-
Test your Vue editor components with mocked Node-RED globals:
|
|
211
|
+
Test your Vue editor components with mocked Node-RED globals. Components that use `useFormNode()` receive their node data via Vue's `provide`/`inject` — use `createNode().provide` to supply it in tests:
|
|
203
212
|
|
|
204
213
|
```typescript
|
|
205
|
-
// vitest.config.ts
|
|
206
|
-
import { defineConfig } from "vitest/config";
|
|
207
|
-
import {
|
|
208
|
-
import vue from "@vitejs/plugin-vue";
|
|
209
|
-
import { defaultConfig } from "@bonsae/nrg/test/client/component";
|
|
214
|
+
// vitest.client.component.config.ts
|
|
215
|
+
import { defineConfig, mergeConfig } from "vitest/config";
|
|
216
|
+
import { defaultConfig } from "@bonsae/nrg/test/client/component/config";
|
|
210
217
|
|
|
211
|
-
export default defineConfig({
|
|
212
|
-
plugins: [vue()],
|
|
218
|
+
export default mergeConfig(defaultConfig, defineConfig({
|
|
213
219
|
test: {
|
|
214
|
-
|
|
215
|
-
browser: {
|
|
216
|
-
...defaultConfig.browser,
|
|
217
|
-
provider: playwright(),
|
|
218
|
-
},
|
|
220
|
+
include: ["tests/client/component/**/*.test.ts"],
|
|
219
221
|
},
|
|
220
|
-
});
|
|
222
|
+
}));
|
|
221
223
|
```
|
|
222
224
|
|
|
223
225
|
```typescript
|
|
224
|
-
// tests/client/component/my-
|
|
226
|
+
// tests/client/component/my-form.test.ts
|
|
225
227
|
import { describe, test, expect, vi } from "vitest";
|
|
226
228
|
import { render } from "vitest-browser-vue";
|
|
227
229
|
import { createNode } from "@bonsae/nrg/test/client/component";
|
|
228
|
-
import
|
|
230
|
+
import MyForm from "../src/client/components/my-form.vue";
|
|
231
|
+
|
|
232
|
+
describe("MyForm", () => {
|
|
233
|
+
test("renders fields from injected node", async () => {
|
|
234
|
+
const { provide } = createNode({ name: "test", url: "https://example.com" });
|
|
235
|
+
const screen = render(MyForm, {
|
|
236
|
+
global: { provide },
|
|
237
|
+
});
|
|
238
|
+
await expect.element(screen.getByDisplayValue("test")).toBeInTheDocument();
|
|
239
|
+
});
|
|
229
240
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
241
|
+
test("accesses node id for API calls", async () => {
|
|
242
|
+
const fetchSpy = vi.fn().mockResolvedValue({ ok: true, json: () => ({}) });
|
|
243
|
+
vi.stubGlobal("fetch", fetchSpy);
|
|
244
|
+
const { node, provide } = createNode({ name: "test" });
|
|
245
|
+
render(MyForm, { global: { provide } });
|
|
246
|
+
await vi.waitFor(() => {
|
|
247
|
+
expect(fetchSpy).toHaveBeenCalledWith(`my-api/${node.id}`);
|
|
235
248
|
});
|
|
236
|
-
await expect.element(screen.getByText("test")).toBeInTheDocument();
|
|
237
249
|
});
|
|
238
250
|
|
|
239
|
-
test("
|
|
240
|
-
const {
|
|
241
|
-
render(
|
|
251
|
+
test("asserts RED.editor API calls", async () => {
|
|
252
|
+
const { RED, provide } = createNode();
|
|
253
|
+
render(MyForm, { global: { provide } });
|
|
242
254
|
expect(RED.editor.createEditor).toHaveBeenCalled();
|
|
243
255
|
});
|
|
244
256
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonsae/nrg",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "NRG framework — build Node-RED nodes with Vue 3, TypeScript, and JSON Schema",
|
|
5
5
|
"author": "Allan Oricil <allanoricil@duck.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,15 +51,18 @@
|
|
|
51
51
|
"types": "./types/test-server-unit.d.ts",
|
|
52
52
|
"default": "./test/server/unit/index.js"
|
|
53
53
|
},
|
|
54
|
+
"./test/server/unit/config": "./test/server/unit/config.js",
|
|
54
55
|
"./test/client/component": {
|
|
55
56
|
"types": "./types/test-client-component.d.ts",
|
|
56
57
|
"default": "./test/client/component/index.js"
|
|
57
58
|
},
|
|
59
|
+
"./test/client/component/config": "./test/client/component/config.js",
|
|
58
60
|
"./test/client/component/setup": "./test/client/component/setup.js",
|
|
59
61
|
"./test/client/unit": {
|
|
60
62
|
"types": "./types/test-client-unit.d.ts",
|
|
61
63
|
"default": "./test/client/unit/index.js"
|
|
62
64
|
},
|
|
65
|
+
"./test/client/unit/config": "./test/client/unit/config.js",
|
|
63
66
|
"./test/client/unit/setup": "./test/client/unit/setup.js",
|
|
64
67
|
"./test/client/e2e": {
|
|
65
68
|
"types": "./types/test-client-e2e.d.ts",
|
|
@@ -75,7 +78,18 @@
|
|
|
75
78
|
},
|
|
76
79
|
"peerDependencies": {
|
|
77
80
|
"vite": "^6.0.0",
|
|
78
|
-
"
|
|
81
|
+
"vitest": "^4.0.0",
|
|
82
|
+
"vue": "^3.5.14",
|
|
83
|
+
"@vitest/coverage-istanbul": "^4.0.0",
|
|
84
|
+
"@vitest/coverage-v8": "^4.0.0"
|
|
85
|
+
},
|
|
86
|
+
"peerDependenciesMeta": {
|
|
87
|
+
"@vitest/coverage-istanbul": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"@vitest/coverage-v8": {
|
|
91
|
+
"optional": true
|
|
92
|
+
}
|
|
79
93
|
},
|
|
80
94
|
"dependencies": {
|
|
81
95
|
"@clack/prompts": "^1.0.1",
|
|
@@ -95,6 +109,10 @@
|
|
|
95
109
|
"typescript": "^5.8.3",
|
|
96
110
|
"vite-plugin-dts": "^4.5.4",
|
|
97
111
|
"vite-plugin-static-copy": "^3.1.0",
|
|
98
|
-
"vue": "^3.5.14"
|
|
112
|
+
"vue": "^3.5.14",
|
|
113
|
+
"@vitest/browser-playwright": "^4.1.5",
|
|
114
|
+
"happy-dom": "^20.10.2",
|
|
115
|
+
"playwright": "^1.60.0",
|
|
116
|
+
"vitest-browser-vue": "^2.1.0"
|
|
99
117
|
}
|
|
100
118
|
}
|