@hozu/testing 0.1.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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 olevatorr
|
|
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/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @hozu/testing
|
|
2
|
+
|
|
3
|
+
Test rendered Hozu pages through the real handler: status, headers, visible text, payload, form posts.
|
|
4
|
+
|
|
5
|
+
Part of [Hozu](https://github.com/olevatorr/Hozu#readme), an AI-first web framework. Most apps start from
|
|
6
|
+
`npm create hozu@latest`, which installs the right packages and sets up Claude Code or `AGENTS.md` agents.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @hozu/testing
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Requires Node 22.18 or newer. Documentation: the [README](https://github.com/olevatorr/Hozu#readme) and the
|
|
13
|
+
agent skill that `create-hozu` writes into each app.
|
|
14
|
+
|
|
15
|
+
MIT © olevatorr
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Json } from '@hozu/core/ir';
|
|
2
|
+
import { type HandlerOptions } from '@hozu/runtime-server';
|
|
3
|
+
export interface TestPage {
|
|
4
|
+
status: number;
|
|
5
|
+
headers: Headers;
|
|
6
|
+
html: string;
|
|
7
|
+
text: string;
|
|
8
|
+
payload: Json | null;
|
|
9
|
+
}
|
|
10
|
+
export interface TestApp {
|
|
11
|
+
get(path: string, init?: RequestInit): Promise<TestPage>;
|
|
12
|
+
post(path: string, form: Record<string, string>, init?: RequestInit): Promise<TestPage>;
|
|
13
|
+
}
|
|
14
|
+
export declare const visibleText: (html: string) => string;
|
|
15
|
+
export declare function testApp(options: HandlerOptions & {
|
|
16
|
+
origin?: string;
|
|
17
|
+
}): TestApp;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAEzE,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,IAAI,GAAG,IAAI,CAAA;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IACxD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CACxF;AAID,eAAO,MAAM,WAAW,SAAU,MAAM,KAAG,MAchC,CAAA;AAEX,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CA4B9E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createHandler } from '@hozu/runtime-server';
|
|
2
|
+
const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', '#39': "'", nbsp: ' ' };
|
|
3
|
+
export const visibleText = (html) => html
|
|
4
|
+
.replace(/<head[\s\S]*?<\/head>/gi, ' ')
|
|
5
|
+
.replace(/<(script|style|template)[\s\S]*?<\/\1>/gi, ' ')
|
|
6
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
7
|
+
.replace(/<[^>]+>/g, ' ')
|
|
8
|
+
.replace(/&(#\d+|#x[0-9a-f]+|\w+);/gi, (all, e) => e.startsWith('#x')
|
|
9
|
+
? String.fromCodePoint(Number.parseInt(e.slice(2), 16))
|
|
10
|
+
: e.startsWith('#') && ENTITIES[e] === undefined
|
|
11
|
+
? String.fromCodePoint(Number(e.slice(1)))
|
|
12
|
+
: (ENTITIES[e] ?? all))
|
|
13
|
+
.replace(/\s+/g, ' ')
|
|
14
|
+
.trim();
|
|
15
|
+
export function testApp(options) {
|
|
16
|
+
const { origin = 'http://localhost', ...rest } = options;
|
|
17
|
+
const handler = createHandler(rest);
|
|
18
|
+
const page = async (response) => {
|
|
19
|
+
const html = await response.text();
|
|
20
|
+
const payload = /<script type="application\/json" id="hozu-payload">([\s\S]*?)<\/script>/.exec(html)?.[1];
|
|
21
|
+
return {
|
|
22
|
+
status: response.status,
|
|
23
|
+
headers: response.headers,
|
|
24
|
+
html,
|
|
25
|
+
text: visibleText(html),
|
|
26
|
+
payload: payload ? JSON.parse(payload) : null,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
get: async (path, init) => page(await handler.fetch(new Request(origin + path, init))),
|
|
31
|
+
post: async (path, form, init) => page(await handler.fetch(new Request(origin + path, {
|
|
32
|
+
...init,
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded', ...(init?.headers ?? {}) },
|
|
35
|
+
body: new URLSearchParams(form).toString(),
|
|
36
|
+
}))),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAuB,MAAM,sBAAsB,CAAA;AAezE,MAAM,QAAQ,GAA2B,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;AAEzG,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAClD,IAAI;KACD,OAAO,CAAC,yBAAyB,EAAE,GAAG,CAAC;KACvC,OAAO,CAAC,0CAA0C,EAAE,GAAG,CAAC;KACxD,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;KAC/B,OAAO,CAAC,UAAU,E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A;IACH,CAAC,CAAA;IACD,OAAO;QACL,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QACtF,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAC/B,IAAI,CACF,MAAM,OAAO,CAAC,KAAK,CACjB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,EAAE;YACzB,GAAG,IAAI;YACP,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,mCAAmC,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,EAAE;YAC1F,IAAI,EAAE,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE;SAC3C,CAAC,CACH,CACF;KACJ,CAAA;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hozu/testing",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Test rendered Hozu pages through the real handler: status, headers, visible text, payload, form posts",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"hozu",
|
|
7
|
+
"framework",
|
|
8
|
+
"ai",
|
|
9
|
+
"agents",
|
|
10
|
+
"ssr",
|
|
11
|
+
"islands",
|
|
12
|
+
"typescript"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/olevatorr/Hozu/tree/main/packages/testing#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/olevatorr/Hozu/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/olevatorr/Hozu.git",
|
|
21
|
+
"directory": "packages/testing"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "olevatorr",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=22.18"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@hozu/core": "0.1.0",
|
|
43
|
+
"@hozu/runtime-server": "0.1.0"
|
|
44
|
+
},
|
|
45
|
+
"sideEffects": false
|
|
46
|
+
}
|