@vanrot/testing 0.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.
@@ -0,0 +1,9 @@
1
+ import { type ComponentType } from '@vanrot/runtime';
2
+ import { type Screen } from './screen.js';
3
+ export type ComponentTestBody = (screen: Screen) => void | Promise<void>;
4
+ export interface ComponentTestBuilder {
5
+ can(description: string, body: ComponentTestBody): void;
6
+ }
7
+ export declare function testComponent(Component: ComponentType): ComponentTestBuilder;
8
+ export declare function runComponentTest(Component: ComponentType, body: ComponentTestBody): Promise<void>;
9
+ //# sourceMappingURL=component-test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-test.d.ts","sourceRoot":"","sources":["../src/component-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzE,MAAM,WAAW,oBAAoB;IACnC,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAAC;CACzD;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,aAAa,GAAG,oBAAoB,CAQ5E;AAED,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,aAAa,EACxB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,IAAI,CAAC,CAWf"}
@@ -0,0 +1,25 @@
1
+ import { mount } from '@vanrot/runtime';
2
+ import { test } from 'vitest';
3
+ import { createScreen } from './screen.js';
4
+ export function testComponent(Component) {
5
+ return {
6
+ can(description, body) {
7
+ test(description, async function () {
8
+ await runComponentTest(Component, body);
9
+ });
10
+ },
11
+ };
12
+ }
13
+ export async function runComponentTest(Component, body) {
14
+ const target = document.createElement('div');
15
+ document.body.append(target);
16
+ const app = mount(Component, target);
17
+ try {
18
+ await body(createScreen(target));
19
+ }
20
+ finally {
21
+ app.destroy();
22
+ target.remove();
23
+ }
24
+ }
25
+ //# sourceMappingURL=component-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-test.js","sourceRoot":"","sources":["../src/component-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAsB,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAe,MAAM,aAAa,CAAC;AAQxD,MAAM,UAAU,aAAa,CAAC,SAAwB;IACpD,OAAO;QACL,GAAG,CAAC,WAAmB,EAAE,IAAuB;YAC9C,IAAI,CAAC,WAAW,EAAE,KAAK;gBACrB,MAAM,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,SAAwB,EACxB,IAAuB;IAEvB,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC7C,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7B,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAErC,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IACnC,CAAC;YAAS,CAAC;QACT,GAAG,CAAC,OAAO,EAAE,CAAC;QACd,MAAM,CAAC,MAAM,EAAE,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export type { ComponentTestBody, ComponentTestBuilder, } from './component-test.js';
2
+ export { testComponent } from './component-test.js';
3
+ export type { Screen } from './screen.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { testComponent } from './component-test.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,10 @@
1
+ export interface Screen {
2
+ click: {
3
+ button(label: string): Promise<void>;
4
+ };
5
+ expect: {
6
+ text(value: string): void;
7
+ };
8
+ }
9
+ export declare function createScreen(target: Element): Screen;
10
+ //# sourceMappingURL=screen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen.d.ts","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE;QACL,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACtC,CAAC;IACF,MAAM,EAAE;QACN,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;KAC3B,CAAC;CACH;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAmBpD"}
package/dist/screen.js ADDED
@@ -0,0 +1,24 @@
1
+ import { expect } from 'vitest';
2
+ export function createScreen(target) {
3
+ return {
4
+ click: {
5
+ async button(label) {
6
+ const button = findButtonByLabel(target, label);
7
+ if (button === null) {
8
+ throw new Error(`Button not found: ${label}`);
9
+ }
10
+ button.click();
11
+ },
12
+ },
13
+ expect: {
14
+ text(value) {
15
+ expect(target.textContent ?? '').toContain(value);
16
+ },
17
+ },
18
+ };
19
+ }
20
+ function findButtonByLabel(target, label) {
21
+ const buttons = Array.from(target.querySelectorAll('button'));
22
+ return buttons.find((button) => button.textContent?.trim() === label) ?? null;
23
+ }
24
+ //# sourceMappingURL=screen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen.js","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAWhC,MAAM,UAAU,YAAY,CAAC,MAAe;IAC1C,OAAO;QACL,KAAK,EAAE;YACL,KAAK,CAAC,MAAM,CAAC,KAAa;gBACxB,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;gBAEhD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;oBACpB,MAAM,IAAI,KAAK,CAAC,qBAAqB,KAAK,EAAE,CAAC,CAAC;gBAChD,CAAC;gBAED,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,CAAC;SACF;QACD,MAAM,EAAE;YACN,IAAI,CAAC,KAAa;gBAChB,MAAM,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YACpD,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAe,EAAE,KAAa;IACvD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE9D,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,KAAK,CAAC,IAAI,IAAI,CAAC;AAChF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@vanrot/testing",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "engines": {
6
+ "node": ">=22.14.0"
7
+ },
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "@vanrot/runtime": "0.0.0"
22
+ },
23
+ "peerDependencies": {
24
+ "vitest": "^4.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "vitest": "^4.0.14"
28
+ },
29
+ "scripts": {
30
+ "prebuild": "pnpm --filter @vanrot/runtime build",
31
+ "build": "tsc -p tsconfig.json",
32
+ "pretypecheck": "pnpm --filter @vanrot/runtime build",
33
+ "typecheck": "tsc -p tsconfig.json --noEmit",
34
+ "pretest": "pnpm --filter @vanrot/runtime build",
35
+ "test": "vitest run",
36
+ "clean": "node -e \"import('node:fs').then(({ rmSync }) => rmSync('dist', { recursive: true, force: true }))\""
37
+ },
38
+ "packageManager": "pnpm@11.1.3+sha512.c85357fe17ca12dd23dd7071822666dfd7e3cb76fe214e3370b5ea2fb34f2a231185509b63e717f3cd0acb38dd3f8d82bcd5e8172400ae678b70ea4fbed0896d"
39
+ }