@webjskit/cli 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.
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Example browser test — runs in real Chromium via WTR + Playwright.
3
+ *
4
+ * Run: npx webjs test --browser
5
+ * npx wtr
6
+ *
7
+ * Tests here have full access to real browser APIs: Shadow DOM,
8
+ * adoptedStyleSheets, IntersectionObserver, events, etc.
9
+ */
10
+
11
+ const assert = {
12
+ ok: (v, msg) => { if (!v) throw new Error(msg || `Expected truthy`); },
13
+ equal: (a, b, msg) => { if (a !== b) throw new Error(msg || `Expected ${b}, got ${a}`); },
14
+ };
15
+
16
+ suite('Example browser tests', () => {
17
+ test('DOM is real (not jsdom/linkedom)', () => {
18
+ const el = document.createElement('div');
19
+ document.body.appendChild(el);
20
+ assert.ok(el.isConnected, 'Element should be connected to real DOM');
21
+ el.remove();
22
+ });
23
+
24
+ test('Shadow DOM works', () => {
25
+ const host = document.createElement('div');
26
+ const shadow = host.attachShadow({ mode: 'open' });
27
+ shadow.innerHTML = '<p>inside shadow</p>';
28
+ assert.ok(shadow.querySelector('p'));
29
+ assert.ok(!host.querySelector('p'), 'Shadow content not in light DOM');
30
+ });
31
+
32
+ // Replace with your component tests:
33
+ // test('my-widget renders correctly', () => {
34
+ // import('../../components/my-widget.ts');
35
+ // const el = document.createElement('my-widget');
36
+ // document.body.appendChild(el);
37
+ // assert.ok(el.shadowRoot);
38
+ // el.remove();
39
+ // });
40
+ });
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Example E2E test — replace with tests for your user flows.
3
+ *
4
+ * Run: WEBJS_E2E=1 npx webjs test
5
+ * Or: WEBJS_E2E=1 node --test test/e2e/*.test.ts
6
+ *
7
+ * Requires: puppeteer-core + chromium installed.
8
+ * npm i -D puppeteer-core
9
+ */
10
+ import { test, describe, before, after } from 'node:test';
11
+ import assert from 'node:assert/strict';
12
+ import { spawn } from 'node:child_process';
13
+ import { createServer } from 'node:net';
14
+
15
+ let browser: any, page: any, serverProcess: any, baseUrl: string;
16
+
17
+ function freePort(): Promise<number> {
18
+ return new Promise((resolve, reject) => {
19
+ const srv = createServer();
20
+ srv.listen(0, () => {
21
+ const addr = srv.address();
22
+ const port = typeof addr === 'object' && addr ? addr.port : 0;
23
+ srv.close(() => resolve(port));
24
+ });
25
+ srv.on('error', reject);
26
+ });
27
+ }
28
+
29
+ before(async () => {
30
+ let puppeteer;
31
+ try { puppeteer = (await import('puppeteer-core')).default; }
32
+ catch { console.log('# Skipping: puppeteer-core not installed'); return; }
33
+
34
+ const port = await freePort();
35
+ baseUrl = `http://localhost:${port}`;
36
+
37
+ serverProcess = spawn('npx', ['webjs', 'dev', '--port', String(port)], {
38
+ cwd: process.cwd(),
39
+ env: { ...process.env, __WEBJS_DEV_CHILD: '1' },
40
+ stdio: ['ignore', 'pipe', 'pipe'],
41
+ });
42
+
43
+ await new Promise<void>((resolve, reject) => {
44
+ const onData = (chunk: Buffer) => {
45
+ if (chunk.toString().includes('ready on')) resolve();
46
+ };
47
+ serverProcess.stdout?.on('data', onData);
48
+ serverProcess.stderr?.on('data', onData);
49
+ setTimeout(() => reject(new Error('Server start timeout')), 15000);
50
+ });
51
+
52
+ browser = await puppeteer.launch({
53
+ executablePath: process.env.CHROMIUM_PATH || '/usr/bin/chromium',
54
+ headless: true,
55
+ args: ['--no-sandbox'],
56
+ });
57
+ page = await browser.newPage();
58
+ });
59
+
60
+ after(async () => {
61
+ if (browser) await browser.close();
62
+ if (serverProcess) serverProcess.kill('SIGTERM');
63
+ });
64
+
65
+ describe('E2E: App', {
66
+ skip: !process.env.WEBJS_E2E && 'set WEBJS_E2E=1 to run',
67
+ }, () => {
68
+
69
+ test('homepage loads and renders', async () => {
70
+ await page.goto(baseUrl, { waitUntil: 'domcontentloaded', timeout: 10000 });
71
+ const title = await page.title();
72
+ assert.ok(title, 'Page should have a title');
73
+ });
74
+
75
+ test('no JavaScript errors', async () => {
76
+ const errors: string[] = [];
77
+ page.on('pageerror', (e: Error) => errors.push(e.message));
78
+ await page.goto(baseUrl, { waitUntil: 'domcontentloaded', timeout: 10000 });
79
+ await new Promise(r => setTimeout(r, 2000));
80
+ assert.equal(errors.length, 0, `JS errors: ${errors.join('; ')}`);
81
+ page.removeAllListeners('pageerror');
82
+ });
83
+
84
+ // Add your E2E tests here:
85
+ // test('user can sign up', async () => { ... });
86
+ // test('user can create a post', async () => { ... });
87
+ });
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Example unit test — replace with tests for your modules.
3
+ *
4
+ * Run: npx webjs test
5
+ * Or: node --test test/unit/*.test.ts
6
+ */
7
+ import { test } from 'node:test';
8
+ import assert from 'node:assert/strict';
9
+ import { html, renderToString } from '@webjskit/core';
10
+
11
+ test('html template renders correctly', async () => {
12
+ const result = await renderToString(html`<p>Hello, ${'world'}!</p>`);
13
+ assert.ok(result.includes('Hello, world!'));
14
+ });
15
+
16
+ test('example: your first server action test', async () => {
17
+ // Import your server action:
18
+ // import { createPost } from '../../modules/posts/actions/create-post.server.ts';
19
+ //
20
+ // const result = await createPost({ title: 'Test', body: 'Content' });
21
+ // assert.equal(result.success, true);
22
+ // assert.ok(result.data.id);
23
+ assert.ok(true, 'Replace this with real tests');
24
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Web Test Runner configuration.
3
+ *
4
+ * Runs browser tests (components, directives, interactions) in real
5
+ * Chromium via Playwright. Server tests (actions, queries) use node:test.
6
+ *
7
+ * Run:
8
+ * npx webjs test # runs both server + browser tests
9
+ * npx webjs test --browser # browser tests only
10
+ * npx webjs test --server # server tests only
11
+ */
12
+ import { playwrightLauncher } from '@web/test-runner-playwright';
13
+
14
+ export default {
15
+ files: ['test/browser/**/*.test.js'],
16
+ nodeResolve: true,
17
+ browsers: [
18
+ playwrightLauncher({ product: 'chromium' }),
19
+ ],
20
+ testFramework: {
21
+ config: {
22
+ ui: 'tdd',
23
+ timeout: 10000,
24
+ },
25
+ },
26
+ };