@ember-marquetry/test-support 0.0.0-stage → 1.0.0
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/CHANGELOG.md +26 -0
- package/LICENSE.md +21 -0
- package/NOTICE +13 -0
- package/README.md +34 -2
- package/addon-main.cjs +4 -0
- package/dist/confirm.d.ts +33 -0
- package/dist/confirm.d.ts.map +1 -0
- package/dist/confirm.js +57 -0
- package/dist/harness.d.ts +43 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +55 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/render.d.ts +37 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +60 -0
- package/dist/stream.d.ts +34 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +68 -0
- package/package.json +62 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @ember-marquetry/test-support
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 8f2790b: The first release of Marquetry: generative UI for Ember.
|
|
8
|
+
|
|
9
|
+
- `core`: the spec format, the JSONL patch stream, expressions, actions, the catalog, agent events, chat threads and stream replay.
|
|
10
|
+
- `ember`: the `<Render>` component and the `Generation` state machine.
|
|
11
|
+
- `joinery`: a catalog of 69 Joinery components, with layout templates and the chart, data table and code block add-ons. The `/a2ui` subpath is the A2UI v0.9.1 basic catalog on Joinery components, for the specs of `a2ui`.
|
|
12
|
+
- `chat`: a chat thread on Joinery components, with streamed markdown, agent surfaces, tool calls, approvals and MCP Apps.
|
|
13
|
+
- `formwright`: forms with validation from a JSON Schema, field rules and named validators.
|
|
14
|
+
- `inspector`: a dev panel for `<Render>` that shows the spec, the patches with their line numbers, the state and the problems.
|
|
15
|
+
- `ai-sdk`, `ag-ui`, `a2ui` and `sse`: adapters and chat transports for the AI SDK, AG-UI 1.0, A2UI v0.9.1 and plain JSONL or SSE endpoints.
|
|
16
|
+
- `markdown`: a streamed markdown parser that makes no HTML.
|
|
17
|
+
- `mcp-apps`: a host for MCP Apps in a sandbox frame on a second origin.
|
|
18
|
+
- `eslint-plugin`, `skills`, `test-support` and the `ember-marquetry` CLI: tools for catalog authors and app developers.
|
|
19
|
+
|
|
20
|
+
Safety defaults in 1.0:
|
|
21
|
+
|
|
22
|
+
- `joinery`: a URL that the browser loads with no click (the `src` of `Image` and `Avatar`, the `image` of `Attachment`, and the `url` of the A2UI `Image`, `Video` and `AudioPlayer`) must be relative, unless `urls.mediaHosts` lists its host. `isSafeMediaUrl` is the check. `urls.hosts` applies only to links.
|
|
23
|
+
- `markdown` and `chat`: an image must pass `isSafeImageUrl` (`<Chat @isSafeImageUrl>`, `<Markdown @isSafeImageUrl>`). The default, `isRelativeUrl`, accepts only a relative URL. A block of more than 20,000 characters is plain text.
|
|
24
|
+
- `chat`: `<McpApp>` and `McpAppsConfig` have `approveDomain`. Without it, the app gets no domain that it declares in its CSP. An app cannot call a tool that needs the approval of the user (`@needsApproval`).
|
|
25
|
+
- `mcp-apps`: the proxy puts the CSP meta at offset 0 of the app HTML, and gives its own page a `frame-src` with only the approved frame domains.
|
|
26
|
+
- `ai-sdk` and `ag-ui`: a problem in one item is a `data` event named `stream-error`, and a value that the reader does not convert is a `data` event named `unconverted`. `error` is only for a failed run.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joe Gaudet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Marquetry
|
|
2
|
+
Copyright (c) 2026 Joe Gaudet. MIT licensed; see LICENSE.md.
|
|
3
|
+
|
|
4
|
+
Marquetry is an original design. Two projects gave it ideas and formats, and Marquetry copies
|
|
5
|
+
no code from them:
|
|
6
|
+
|
|
7
|
+
- json-render (Vercel, Apache 2.0): the idea of a catalog that limits a model, a flat element
|
|
8
|
+
map, and a spec that streams as JSON Lines of RFC 6902 patches.
|
|
9
|
+
- A2UI (Google, Apache 2.0): the v0.9 message format that @ember-marquetry/a2ui reads.
|
|
10
|
+
|
|
11
|
+
@ember-marquetry/ag-ui reads the event format of the AG-UI protocol, and
|
|
12
|
+
@ember-marquetry/ai-sdk reads the UI message stream format of the Vercel AI SDK. Marquetry
|
|
13
|
+
depends on neither package.
|
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ember-marquetry/test-support
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Test harnesses for Marquetry, and a stream that a test controls. No test needs a model or the
|
|
4
|
+
network.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { RenderHarness, scriptedStream } from '@ember-marquetry/test-support'
|
|
8
|
+
|
|
9
|
+
const stream = scriptedStream()
|
|
10
|
+
generation.run(stream)
|
|
11
|
+
stream.push({ op: 'add', path: '/root', value: 'main' })
|
|
12
|
+
stream.end()
|
|
13
|
+
await settled()
|
|
14
|
+
|
|
15
|
+
const harness = new RenderHarness()
|
|
16
|
+
assert.dom(harness.find('main')).exists()
|
|
17
|
+
assert.deepEqual(harness.fallbacks, [])
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Harnesses
|
|
21
|
+
|
|
22
|
+
- `RenderHarness`: `find(id)`, `findAll(id)`, `has(id)`, `fallbacks`, `fallback(id)`,
|
|
23
|
+
`skeletons`, `skeleton(id)`, `isConfirmOpen`, `confirmDialog`, `confirm()`, `cancel()`.
|
|
24
|
+
- `ConfirmHarness`: `isOpen`, `element`, `title`, `description`, `confirmButton`,
|
|
25
|
+
`cancelButton`, `confirm()`, `cancel()`, `pressEscape()`.
|
|
26
|
+
|
|
27
|
+
Each harness takes `{ within }` to look in one element. The default is the root of the test.
|
|
28
|
+
The harnesses use the `data-test-mq-*` attributes, which `attributes` lists.
|
|
29
|
+
|
|
30
|
+
## Streams
|
|
31
|
+
|
|
32
|
+
- `scriptedStream()`: `push(line | object)`, `pushRaw(text)`, `end()`, `fail(error)` and
|
|
33
|
+
`aborted`. Pass it to `Generation.run`. Before `end()`, use `waitUntil()` or `rerender()`:
|
|
34
|
+
`settled()` waits for the end of the stream.
|
|
35
|
+
- `streamOf(lines, { chunkSize })`: a complete stream in small chunks.
|
package/addon-main.cjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Harness } from './harness.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Controls the confirm dialog that `<Render>` shows before an action with `confirm`.
|
|
4
|
+
*
|
|
5
|
+
* const confirm = new ConfirmHarness()
|
|
6
|
+
* assert.strictEqual(confirm.title, 'Delete the item?')
|
|
7
|
+
* await confirm.confirm()
|
|
8
|
+
*
|
|
9
|
+
* A component that you pass as `@Confirm` gets `data-test-mq-confirm` through `...attributes`.
|
|
10
|
+
* Its buttons need `data-test-mq-confirm-accept` and `data-test-mq-confirm-cancel` for
|
|
11
|
+
* `confirm()` and `cancel()`.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ConfirmHarness extends Harness {
|
|
14
|
+
#private;
|
|
15
|
+
/** True while the dialog shows. */
|
|
16
|
+
get isOpen(): boolean;
|
|
17
|
+
/** The root of the dialog. Throws when the dialog does not show. */
|
|
18
|
+
get element(): HTMLElement;
|
|
19
|
+
get title(): string | null;
|
|
20
|
+
get description(): string | null;
|
|
21
|
+
get confirmButton(): HTMLElement;
|
|
22
|
+
get cancelButton(): HTMLElement;
|
|
23
|
+
/** Clicks the confirm button. */
|
|
24
|
+
confirm(): Promise<void>;
|
|
25
|
+
/** Clicks the cancel button. */
|
|
26
|
+
cancel(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Does what the browser does when the user presses Escape in a modal dialog: a `keydown`
|
|
29
|
+
* event, then a `cancel` event on the dialog. A script cannot make the browser do this.
|
|
30
|
+
*/
|
|
31
|
+
pressEscape(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=confirm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm.d.ts","sourceRoot":"","sources":["../src/confirm.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,OAAO,EAAY,MAAM,cAAc,CAAA;AAE5D;;;;;;;;;;GAUG;AACH,qBAAa,cAAe,SAAQ,OAAO;;IACzC,mCAAmC;IACnC,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,oEAAoE;IACpE,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAE/B;IAED,IAAI,aAAa,IAAI,WAAW,CAE/B;IAED,IAAI,YAAY,IAAI,WAAW,CAE9B;IAED,iCAAiC;IAC3B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,gCAAgC;IAC1B,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAUnC"}
|
package/dist/confirm.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { click, triggerEvent, triggerKeyEvent } from '@ember/test-helpers';
|
|
2
|
+
import { attributes, Harness, selector } from "./harness.js";
|
|
3
|
+
/**
|
|
4
|
+
* Controls the confirm dialog that `<Render>` shows before an action with `confirm`.
|
|
5
|
+
*
|
|
6
|
+
* const confirm = new ConfirmHarness()
|
|
7
|
+
* assert.strictEqual(confirm.title, 'Delete the item?')
|
|
8
|
+
* await confirm.confirm()
|
|
9
|
+
*
|
|
10
|
+
* A component that you pass as `@Confirm` gets `data-test-mq-confirm` through `...attributes`.
|
|
11
|
+
* Its buttons need `data-test-mq-confirm-accept` and `data-test-mq-confirm-cancel` for
|
|
12
|
+
* `confirm()` and `cancel()`.
|
|
13
|
+
*/
|
|
14
|
+
export class ConfirmHarness extends Harness {
|
|
15
|
+
/** True while the dialog shows. */
|
|
16
|
+
get isOpen() {
|
|
17
|
+
return this.queryAll(selector(attributes.confirm)).length > 0;
|
|
18
|
+
}
|
|
19
|
+
/** The root of the dialog. Throws when the dialog does not show. */
|
|
20
|
+
get element() {
|
|
21
|
+
return this.query(selector(attributes.confirm), 'confirm dialog');
|
|
22
|
+
}
|
|
23
|
+
get title() {
|
|
24
|
+
return this.#text(attributes.confirmTitle);
|
|
25
|
+
}
|
|
26
|
+
get description() {
|
|
27
|
+
return this.#text(attributes.confirmDescription);
|
|
28
|
+
}
|
|
29
|
+
get confirmButton() {
|
|
30
|
+
return this.query(selector(attributes.confirmAccept), 'confirm button');
|
|
31
|
+
}
|
|
32
|
+
get cancelButton() {
|
|
33
|
+
return this.query(selector(attributes.confirmCancel), 'cancel button');
|
|
34
|
+
}
|
|
35
|
+
/** Clicks the confirm button. */
|
|
36
|
+
async confirm() {
|
|
37
|
+
await click(this.confirmButton);
|
|
38
|
+
}
|
|
39
|
+
/** Clicks the cancel button. */
|
|
40
|
+
async cancel() {
|
|
41
|
+
await click(this.cancelButton);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Does what the browser does when the user presses Escape in a modal dialog: a `keydown`
|
|
45
|
+
* event, then a `cancel` event on the dialog. A script cannot make the browser do this.
|
|
46
|
+
*/
|
|
47
|
+
async pressEscape() {
|
|
48
|
+
const element = this.element;
|
|
49
|
+
await triggerKeyEvent(element, 'keydown', 'Escape');
|
|
50
|
+
if (this.isOpen)
|
|
51
|
+
await triggerEvent(element, 'cancel', { cancelable: true, bubbles: false });
|
|
52
|
+
}
|
|
53
|
+
#text(attribute) {
|
|
54
|
+
const element = this.element.querySelector(selector(attribute));
|
|
55
|
+
return element ? (element.textContent ?? '').trim() : null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `data-test-mq-*` attributes that Marquetry renders. They are public API: the harnesses
|
|
3
|
+
* find the parts with them, and your tests can use them too.
|
|
4
|
+
*
|
|
5
|
+
* data-test-mq-element="<id>" the root of a registered component, when it has `...attributes`
|
|
6
|
+
* data-test-mq-fallback="<id>" the fallback for an element that cannot render
|
|
7
|
+
* data-test-mq-skeleton="<id>" the skeleton for an element that did not arrive yet
|
|
8
|
+
* data-test-mq-confirm the confirm dialog, and its parts `-title`, `-description`,
|
|
9
|
+
* `-accept` and `-cancel`
|
|
10
|
+
*/
|
|
11
|
+
export declare const attributes: {
|
|
12
|
+
readonly element: "data-test-mq-element";
|
|
13
|
+
readonly fallback: "data-test-mq-fallback";
|
|
14
|
+
readonly skeleton: "data-test-mq-skeleton";
|
|
15
|
+
readonly confirm: "data-test-mq-confirm";
|
|
16
|
+
readonly confirmTitle: "data-test-mq-confirm-title";
|
|
17
|
+
readonly confirmDescription: "data-test-mq-confirm-description";
|
|
18
|
+
readonly confirmAccept: "data-test-mq-confirm-accept";
|
|
19
|
+
readonly confirmCancel: "data-test-mq-confirm-cancel";
|
|
20
|
+
};
|
|
21
|
+
/** A CSS selector for an attribute, with an optional value. */
|
|
22
|
+
export declare function selector(attribute: string, value?: string): string;
|
|
23
|
+
export interface HarnessOptions {
|
|
24
|
+
/** Where the harness looks. Default: the root element of the test. */
|
|
25
|
+
within?: Element;
|
|
26
|
+
}
|
|
27
|
+
/** Thrown when a harness finds nothing. */
|
|
28
|
+
export declare class NotFoundError extends Error {
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The base of each Marquetry harness. A harness does a new lookup on each read, so one harness
|
|
33
|
+
* stays valid after a render.
|
|
34
|
+
*/
|
|
35
|
+
export declare class Harness {
|
|
36
|
+
#private;
|
|
37
|
+
constructor(options?: HarnessOptions);
|
|
38
|
+
/** The element that the harness looks in. */
|
|
39
|
+
get scope(): Element;
|
|
40
|
+
protected queryAll(css: string): HTMLElement[];
|
|
41
|
+
protected query(css: string, description: string): HTMLElement;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=harness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../src/harness.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU;;;;;;;;;CASb,CAAA;AAEV,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,MAAM,WAAW,cAAc;IAC7B,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,2CAA2C;AAC3C,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AAED;;;GAGG;AACH,qBAAa,OAAO;;gBAGN,OAAO,GAAE,cAAmB;IAIxC,6CAA6C;IAC7C,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,EAAE;IAI9C,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,WAAW;CAK/D"}
|
package/dist/harness.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { getRootElement } from '@ember/test-helpers';
|
|
2
|
+
/**
|
|
3
|
+
* The `data-test-mq-*` attributes that Marquetry renders. They are public API: the harnesses
|
|
4
|
+
* find the parts with them, and your tests can use them too.
|
|
5
|
+
*
|
|
6
|
+
* data-test-mq-element="<id>" the root of a registered component, when it has `...attributes`
|
|
7
|
+
* data-test-mq-fallback="<id>" the fallback for an element that cannot render
|
|
8
|
+
* data-test-mq-skeleton="<id>" the skeleton for an element that did not arrive yet
|
|
9
|
+
* data-test-mq-confirm the confirm dialog, and its parts `-title`, `-description`,
|
|
10
|
+
* `-accept` and `-cancel`
|
|
11
|
+
*/
|
|
12
|
+
export const attributes = {
|
|
13
|
+
element: 'data-test-mq-element',
|
|
14
|
+
fallback: 'data-test-mq-fallback',
|
|
15
|
+
skeleton: 'data-test-mq-skeleton',
|
|
16
|
+
confirm: 'data-test-mq-confirm',
|
|
17
|
+
confirmTitle: 'data-test-mq-confirm-title',
|
|
18
|
+
confirmDescription: 'data-test-mq-confirm-description',
|
|
19
|
+
confirmAccept: 'data-test-mq-confirm-accept',
|
|
20
|
+
confirmCancel: 'data-test-mq-confirm-cancel',
|
|
21
|
+
};
|
|
22
|
+
/** A CSS selector for an attribute, with an optional value. */
|
|
23
|
+
export function selector(attribute, value) {
|
|
24
|
+
return value === undefined ? `[${attribute}]` : `[${attribute}="${CSS.escape(value)}"]`;
|
|
25
|
+
}
|
|
26
|
+
/** Thrown when a harness finds nothing. */
|
|
27
|
+
export class NotFoundError extends Error {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
super(`Marquetry harness: ${message}`);
|
|
30
|
+
this.name = 'NotFoundError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The base of each Marquetry harness. A harness does a new lookup on each read, so one harness
|
|
35
|
+
* stays valid after a render.
|
|
36
|
+
*/
|
|
37
|
+
export class Harness {
|
|
38
|
+
#within;
|
|
39
|
+
constructor(options = {}) {
|
|
40
|
+
this.#within = options.within;
|
|
41
|
+
}
|
|
42
|
+
/** The element that the harness looks in. */
|
|
43
|
+
get scope() {
|
|
44
|
+
return this.#within ?? getRootElement();
|
|
45
|
+
}
|
|
46
|
+
queryAll(css) {
|
|
47
|
+
return [...this.scope.querySelectorAll(css)];
|
|
48
|
+
}
|
|
49
|
+
query(css, description) {
|
|
50
|
+
const element = this.scope.querySelector(css);
|
|
51
|
+
if (!element)
|
|
52
|
+
throw new NotFoundError(`found no ${description}`);
|
|
53
|
+
return element;
|
|
54
|
+
}
|
|
55
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ConfirmHarness } from './confirm.ts';
|
|
2
|
+
export { attributes, Harness, NotFoundError, selector, type HarnessOptions } from './harness.ts';
|
|
3
|
+
export { RenderHarness } from './render.ts';
|
|
4
|
+
export { scriptedStream, streamOf, type ScriptedStream } from './stream.ts';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAChG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
ADDED
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ConfirmHarness } from './confirm.ts';
|
|
2
|
+
import { Harness } from './harness.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Reads what a `<Render>` shows.
|
|
5
|
+
*
|
|
6
|
+
* const harness = new RenderHarness()
|
|
7
|
+
* assert.dom(harness.find('title')).hasText('Orders')
|
|
8
|
+
* assert.deepEqual(harness.fallbacks, [])
|
|
9
|
+
*
|
|
10
|
+
* `find` needs the registered component to put `...attributes` on its root element.
|
|
11
|
+
*/
|
|
12
|
+
export declare class RenderHarness extends Harness {
|
|
13
|
+
#private;
|
|
14
|
+
/** The root element of the component for the spec element `id`. Throws when there is none. */
|
|
15
|
+
find(id: string): HTMLElement;
|
|
16
|
+
/** Each root element for the spec element `id`. A `repeat` renders an element many times. */
|
|
17
|
+
findAll(id: string): HTMLElement[];
|
|
18
|
+
/** True when the spec element `id` shows. */
|
|
19
|
+
has(id: string): boolean;
|
|
20
|
+
/** The ids of the elements that show a fallback, in document order. */
|
|
21
|
+
get fallbacks(): string[];
|
|
22
|
+
/** The fallback for the spec element `id`. */
|
|
23
|
+
fallback(id: string): HTMLElement;
|
|
24
|
+
/** The ids of the elements that show a skeleton, in document order. */
|
|
25
|
+
get skeletons(): string[];
|
|
26
|
+
/** The skeleton for the spec element `id`. */
|
|
27
|
+
skeleton(id: string): HTMLElement;
|
|
28
|
+
/** The harness of the confirm dialog. */
|
|
29
|
+
get confirmDialog(): ConfirmHarness;
|
|
30
|
+
/** True while a confirm dialog shows. */
|
|
31
|
+
get isConfirmOpen(): boolean;
|
|
32
|
+
/** Agrees in the confirm dialog. */
|
|
33
|
+
confirm(): Promise<void>;
|
|
34
|
+
/** Refuses in the confirm dialog. */
|
|
35
|
+
cancel(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAc,OAAO,EAAY,MAAM,cAAc,CAAA;AAE5D;;;;;;;;GAQG;AACH,qBAAa,aAAc,SAAQ,OAAO;;IACxC,8FAA8F;IAC9F,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW;IAI7B,6FAA6F;IAC7F,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,EAAE;IAIlC,6CAA6C;IAC7C,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIxB,uEAAuE;IACvE,IAAI,SAAS,IAAI,MAAM,EAAE,CAExB;IAED,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW;IAIjC,uEAAuE;IACvE,IAAI,SAAS,IAAI,MAAM,EAAE,CAExB;IAED,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW;IAIjC,yCAAyC;IACzC,IAAI,aAAa,IAAI,cAAc,CAElC;IAED,yCAAyC;IACzC,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,oCAAoC;IAC9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,qCAAqC;IAC/B,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAO9B"}
|
package/dist/render.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ConfirmHarness } from "./confirm.js";
|
|
2
|
+
import { attributes, Harness, selector } from "./harness.js";
|
|
3
|
+
/**
|
|
4
|
+
* Reads what a `<Render>` shows.
|
|
5
|
+
*
|
|
6
|
+
* const harness = new RenderHarness()
|
|
7
|
+
* assert.dom(harness.find('title')).hasText('Orders')
|
|
8
|
+
* assert.deepEqual(harness.fallbacks, [])
|
|
9
|
+
*
|
|
10
|
+
* `find` needs the registered component to put `...attributes` on its root element.
|
|
11
|
+
*/
|
|
12
|
+
export class RenderHarness extends Harness {
|
|
13
|
+
/** The root element of the component for the spec element `id`. Throws when there is none. */
|
|
14
|
+
find(id) {
|
|
15
|
+
return this.query(selector(attributes.element, id), `element "${id}"`);
|
|
16
|
+
}
|
|
17
|
+
/** Each root element for the spec element `id`. A `repeat` renders an element many times. */
|
|
18
|
+
findAll(id) {
|
|
19
|
+
return this.queryAll(selector(attributes.element, id));
|
|
20
|
+
}
|
|
21
|
+
/** True when the spec element `id` shows. */
|
|
22
|
+
has(id) {
|
|
23
|
+
return this.findAll(id).length > 0;
|
|
24
|
+
}
|
|
25
|
+
/** The ids of the elements that show a fallback, in document order. */
|
|
26
|
+
get fallbacks() {
|
|
27
|
+
return this.#ids(attributes.fallback);
|
|
28
|
+
}
|
|
29
|
+
/** The fallback for the spec element `id`. */
|
|
30
|
+
fallback(id) {
|
|
31
|
+
return this.query(selector(attributes.fallback, id), `fallback for "${id}"`);
|
|
32
|
+
}
|
|
33
|
+
/** The ids of the elements that show a skeleton, in document order. */
|
|
34
|
+
get skeletons() {
|
|
35
|
+
return this.#ids(attributes.skeleton);
|
|
36
|
+
}
|
|
37
|
+
/** The skeleton for the spec element `id`. */
|
|
38
|
+
skeleton(id) {
|
|
39
|
+
return this.query(selector(attributes.skeleton, id), `skeleton for "${id}"`);
|
|
40
|
+
}
|
|
41
|
+
/** The harness of the confirm dialog. */
|
|
42
|
+
get confirmDialog() {
|
|
43
|
+
return new ConfirmHarness({ within: this.scope });
|
|
44
|
+
}
|
|
45
|
+
/** True while a confirm dialog shows. */
|
|
46
|
+
get isConfirmOpen() {
|
|
47
|
+
return this.confirmDialog.isOpen;
|
|
48
|
+
}
|
|
49
|
+
/** Agrees in the confirm dialog. */
|
|
50
|
+
async confirm() {
|
|
51
|
+
await this.confirmDialog.confirm();
|
|
52
|
+
}
|
|
53
|
+
/** Refuses in the confirm dialog. */
|
|
54
|
+
async cancel() {
|
|
55
|
+
await this.confirmDialog.cancel();
|
|
56
|
+
}
|
|
57
|
+
#ids(attribute) {
|
|
58
|
+
return this.queryAll(selector(attribute)).map(element => element.getAttribute(attribute) ?? '');
|
|
59
|
+
}
|
|
60
|
+
}
|
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** A stream that a test controls. It is a source for `Generation.run`. */
|
|
2
|
+
export interface ScriptedStream {
|
|
3
|
+
(signal?: AbortSignal): AsyncIterable<string>;
|
|
4
|
+
/** Sends one line. An object becomes one JSON line. */
|
|
5
|
+
push(line: string | object): void;
|
|
6
|
+
/** Sends text as it is, with no newline, so a test can cut a line in two chunks. */
|
|
7
|
+
pushRaw(text: string): void;
|
|
8
|
+
/** Closes the stream. */
|
|
9
|
+
end(): void;
|
|
10
|
+
/** Makes the stream throw `error` after the chunks that wait. */
|
|
11
|
+
fail(error: unknown): void;
|
|
12
|
+
/** True after the signal of a reader aborted. */
|
|
13
|
+
readonly aborted: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Makes a stream that a test controls. No model and no network are necessary.
|
|
17
|
+
*
|
|
18
|
+
* const stream = scriptedStream()
|
|
19
|
+
* generation.run(stream)
|
|
20
|
+
* stream.push({ op: 'add', path: '/root', value: 'main' })
|
|
21
|
+
* stream.end()
|
|
22
|
+
* await settled()
|
|
23
|
+
*
|
|
24
|
+
* `settled()` waits for the end of the stream. Before the end, use `waitUntil()` or `rerender()`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function scriptedStream(): ScriptedStream;
|
|
27
|
+
/**
|
|
28
|
+
* A complete stream of `lines`, sent in small chunks. An object becomes one JSON line.
|
|
29
|
+
* `chunkSize` is the number of characters in each chunk. Default: 16.
|
|
30
|
+
*/
|
|
31
|
+
export declare function streamOf(lines: readonly (string | object)[], { chunkSize }?: {
|
|
32
|
+
chunkSize?: number;
|
|
33
|
+
}): AsyncGenerator<string>;
|
|
34
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,MAAM,WAAW,cAAc;IAC7B,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IAC7C,uDAAuD;IACvD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACjC,oFAAoF;IACpF,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,yBAAyB;IACzB,GAAG,IAAI,IAAI,CAAA;IACX,iEAAiE;IACjE,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAA;IAC1B,iDAAiD;IACjD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,IAAI,cAAc,CA8C/C;AAED;;;GAGG;AACH,wBAAuB,QAAQ,CAC7B,KAAK,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EACnC,EAAE,SAAc,EAAE,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAC9C,cAAc,CAAC,MAAM,CAAC,CAQxB"}
|
package/dist/stream.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes a stream that a test controls. No model and no network are necessary.
|
|
3
|
+
*
|
|
4
|
+
* const stream = scriptedStream()
|
|
5
|
+
* generation.run(stream)
|
|
6
|
+
* stream.push({ op: 'add', path: '/root', value: 'main' })
|
|
7
|
+
* stream.end()
|
|
8
|
+
* await settled()
|
|
9
|
+
*
|
|
10
|
+
* `settled()` waits for the end of the stream. Before the end, use `waitUntil()` or `rerender()`.
|
|
11
|
+
*/
|
|
12
|
+
export function scriptedStream() {
|
|
13
|
+
const queue = [];
|
|
14
|
+
let wake;
|
|
15
|
+
let aborted = false;
|
|
16
|
+
const add = (item) => {
|
|
17
|
+
queue.push(item);
|
|
18
|
+
wake?.();
|
|
19
|
+
};
|
|
20
|
+
async function* read(signal) {
|
|
21
|
+
while (!signal?.aborted) {
|
|
22
|
+
const item = queue.shift();
|
|
23
|
+
if (!item) {
|
|
24
|
+
await new Promise(resolve => (wake = resolve));
|
|
25
|
+
wake = undefined;
|
|
26
|
+
}
|
|
27
|
+
else if ('chunk' in item)
|
|
28
|
+
yield item.chunk;
|
|
29
|
+
else if ('error' in item)
|
|
30
|
+
throw item.error;
|
|
31
|
+
else
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// The listener starts with the call, not with the first read: an abort can come before it.
|
|
36
|
+
function start(signal) {
|
|
37
|
+
const onAbort = () => {
|
|
38
|
+
aborted = true;
|
|
39
|
+
wake?.();
|
|
40
|
+
};
|
|
41
|
+
if (signal?.aborted)
|
|
42
|
+
onAbort();
|
|
43
|
+
else
|
|
44
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
45
|
+
return read(signal);
|
|
46
|
+
}
|
|
47
|
+
return Object.defineProperty(Object.assign(start, {
|
|
48
|
+
push: (line) => add({ chunk: (typeof line === 'string' ? line : JSON.stringify(line)) + '\n' }),
|
|
49
|
+
pushRaw: (text) => add({ chunk: text }),
|
|
50
|
+
end: () => add({ done: true }),
|
|
51
|
+
fail: (error) => add({ error }),
|
|
52
|
+
// The getter below replaces this value.
|
|
53
|
+
aborted: false,
|
|
54
|
+
}), 'aborted', { get: () => aborted });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A complete stream of `lines`, sent in small chunks. An object becomes one JSON line.
|
|
58
|
+
* `chunkSize` is the number of characters in each chunk. Default: 16.
|
|
59
|
+
*/
|
|
60
|
+
export async function* streamOf(lines, { chunkSize = 16 } = {}) {
|
|
61
|
+
const text = lines
|
|
62
|
+
.map(line => (typeof line === 'string' ? line : JSON.stringify(line)))
|
|
63
|
+
.join('\n');
|
|
64
|
+
for (let at = 0; at < text.length; at += chunkSize) {
|
|
65
|
+
// Each chunk comes in its own microtask, as chunks from a network do.
|
|
66
|
+
yield await Promise.resolve(text.slice(at, at + chunkSize));
|
|
67
|
+
}
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-marquetry/test-support",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Test harnesses for Marquetry, and a scripted stream that a test controls.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ember-addon",
|
|
7
|
+
"ember",
|
|
8
|
+
"testing",
|
|
9
|
+
"harness",
|
|
10
|
+
"marquetry"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Joe Gaudet <joe@joegaudet.com>",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/joegaudet/ember-marquetry.git",
|
|
17
|
+
"directory": "packages/test-support"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://joegaudet.com/ember-marquetry/",
|
|
20
|
+
"bugs": "https://github.com/joegaudet/ember-marquetry/issues",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./addon-main.js": "./addon-main.cjs"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"addon-main.cjs",
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md",
|
|
33
|
+
"CHANGELOG.md",
|
|
34
|
+
"LICENSE.md",
|
|
35
|
+
"NOTICE"
|
|
36
|
+
],
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@embroider/addon-shim": "^1.10.3"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@ember/test-helpers": ">= 5.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@ember/library-tsconfig": "^3.0.0",
|
|
46
|
+
"@ember/test-helpers": "^5.7.0",
|
|
47
|
+
"ember-source": "~7.3.0",
|
|
48
|
+
"typescript": "~6.0.3"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=22.12.0"
|
|
55
|
+
},
|
|
56
|
+
"ember-addon": {
|
|
57
|
+
"version": 2,
|
|
58
|
+
"type": "addon",
|
|
59
|
+
"main": "addon-main.cjs"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
63
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
64
|
+
}
|
|
6
65
|
}
|