From 57ff90dfc3e759901a03becdfca0e51b2673a175 Mon Sep 17 00:00:00 2001 From: bowenliang123 Date: Sun, 23 Aug 2026 05:11:27 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20unify=20the=20repo=20on=20TypeScript?= =?UTF-8?q?=20=E2=80=94=20tests,=20vitest=20config,=20and=20the=20social-p?= =?UTF-8?q?review=20generator=20move=20from=20.mjs=20to=20.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vitest (esbuild) and Node 24 type stripping run the .ts files directly; helper imports go extensionless like src. Typecheck stays scoped to src/ as before. --- docs/social-preview/{generate.mjs => generate.ts} | 2 +- package.json | 2 +- ...istant-blocks.spec.mjs => assistant-blocks.spec.ts} | 2 +- ...wser-autoload.spec.mjs => browser-autoload.spec.ts} | 2 +- tests/{browser.spec.mjs => browser.spec.ts} | 2 +- tests/{chart.spec.mjs => chart.spec.ts} | 2 +- tests/{client.spec.mjs => client.spec.ts} | 2 +- ...position-link.spec.mjs => composition-link.spec.ts} | 2 +- tests/{diff-fold.mjs => diff-fold.ts} | 4 ++-- tests/helpers/{viewBed.mjs => viewBed.ts} | 0 ...afety.client.spec.mjs => hmr-safety.client.spec.ts} | 2 +- tests/{host.spec.mjs => host.spec.ts} | 0 tests/{image-tokens.spec.mjs => image-tokens.spec.ts} | 0 tests/{images.spec.mjs => images.spec.ts} | 2 +- tests/{linkage.spec.mjs => linkage.spec.ts} | 2 +- tests/{modal.spec.mjs => modal.spec.ts} | 2 +- tests/{multimodal.spec.mjs => multimodal.spec.ts} | 0 ...react.client.spec.mjs => real-react.client.spec.ts} | 0 tests/{resilience.spec.mjs => resilience.spec.ts} | 2 +- ...l-chip-bridge.spec.mjs => tool-chip-bridge.spec.ts} | 2 +- vitest.config.mjs | 10 ---------- vitest.config.ts | 10 ++++++++++ 22 files changed, 26 insertions(+), 26 deletions(-) rename docs/social-preview/{generate.mjs => generate.ts} (96%) rename tests/{assistant-blocks.spec.mjs => assistant-blocks.spec.ts} (99%) rename tests/{browser-autoload.spec.mjs => browser-autoload.spec.ts} (97%) rename tests/{browser.spec.mjs => browser.spec.ts} (99%) rename tests/{chart.spec.mjs => chart.spec.ts} (99%) rename tests/{client.spec.mjs => client.spec.ts} (99%) rename tests/{composition-link.spec.mjs => composition-link.spec.ts} (99%) rename tests/{diff-fold.mjs => diff-fold.ts} (97%) rename tests/helpers/{viewBed.mjs => viewBed.ts} (100%) rename tests/{hmr-safety.client.spec.mjs => hmr-safety.client.spec.ts} (98%) rename tests/{host.spec.mjs => host.spec.ts} (100%) rename tests/{image-tokens.spec.mjs => image-tokens.spec.ts} (100%) rename tests/{images.spec.mjs => images.spec.ts} (98%) rename tests/{linkage.spec.mjs => linkage.spec.ts} (97%) rename tests/{modal.spec.mjs => modal.spec.ts} (98%) rename tests/{multimodal.spec.mjs => multimodal.spec.ts} (100%) rename tests/{real-react.client.spec.mjs => real-react.client.spec.ts} (100%) rename tests/{resilience.spec.mjs => resilience.spec.ts} (98%) rename tests/{tool-chip-bridge.spec.mjs => tool-chip-bridge.spec.ts} (98%) delete mode 100644 vitest.config.mjs create mode 100644 vitest.config.ts diff --git a/docs/social-preview/generate.mjs b/docs/social-preview/generate.ts similarity index 96% rename from docs/social-preview/generate.mjs rename to docs/social-preview/generate.ts index 7b021ca..e434d62 100644 --- a/docs/social-preview/generate.mjs +++ b/docs/social-preview/generate.ts @@ -1,7 +1,7 @@ // Renders social-preview.html to docs/social-preview.png (exactly 1280x640). // Renders at 2x (2560x1280) first, then downsamples via Chromium's high-quality // image smoothing, so text and the embedded screenshot stay sharp. -// Usage: node docs/social-preview/generate.mjs (or: npm run social-preview) +// Usage: node docs/social-preview/generate.ts (or: npm run social-preview) import { chromium } from 'playwright-core'; import { homedir } from 'node:os'; import { fileURLToPath, pathToFileURL } from 'node:url'; diff --git a/package.json b/package.json index 404e145..d1bda28 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "test": "npm run typecheck && vitest run", "release": "bash scripts/publish.sh", "hooks": "bash scripts/install-hooks.sh", - "social-preview": "node docs/social-preview/generate.mjs" + "social-preview": "node docs/social-preview/generate.ts" }, "dsh": { "bundle": { diff --git a/tests/assistant-blocks.spec.mjs b/tests/assistant-blocks.spec.ts similarity index 99% rename from tests/assistant-blocks.spec.mjs rename to tests/assistant-blocks.spec.ts index ba52b83..98b25cb 100644 --- a/tests/assistant-blocks.spec.mjs +++ b/tests/assistant-blocks.spec.ts @@ -9,7 +9,7 @@ */ import assert from 'node:assert/strict' import { test } from 'vitest' -import { bootViewBed, byClass, textOf } from './helpers/viewBed.mjs' +import { bootViewBed, byClass, textOf } from './helpers/viewBed' const bed = await bootViewBed() const { renderView, snapshot } = bed diff --git a/tests/browser-autoload.spec.mjs b/tests/browser-autoload.spec.ts similarity index 97% rename from tests/browser-autoload.spec.mjs rename to tests/browser-autoload.spec.ts index 1bdb563..a432c8a 100644 --- a/tests/browser-autoload.spec.mjs +++ b/tests/browser-autoload.spec.ts @@ -5,7 +5,7 @@ */ import assert from 'node:assert/strict' import { test } from 'vitest' -import { bootViewBed, byClass, textOf } from './helpers/viewBed.mjs' +import { bootViewBed, byClass, textOf } from './helpers/viewBed' const bed = await bootViewBed() const { renderView, snapshot } = bed diff --git a/tests/browser.spec.mjs b/tests/browser.spec.ts similarity index 99% rename from tests/browser.spec.mjs rename to tests/browser.spec.ts index 95e94d3..1a165de 100644 --- a/tests/browser.spec.mjs +++ b/tests/browser.spec.ts @@ -6,7 +6,7 @@ */ import assert from 'node:assert/strict' import { test } from 'vitest' -import { bootViewBed, byClass, catRowOf, textOf } from './helpers/viewBed.mjs' +import { bootViewBed, byClass, catRowOf, textOf } from './helpers/viewBed' const bed = await bootViewBed() const { hookStates, renderView, snapshot } = bed diff --git a/tests/chart.spec.mjs b/tests/chart.spec.ts similarity index 99% rename from tests/chart.spec.mjs rename to tests/chart.spec.ts index d9ba5db..94ef490 100644 --- a/tests/chart.spec.mjs +++ b/tests/chart.spec.ts @@ -7,7 +7,7 @@ import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import { test } from 'vitest' -import { bootViewBed, byClass, plainText, textOf } from './helpers/viewBed.mjs' +import { bootViewBed, byClass, plainText, textOf } from './helpers/viewBed' const bed = await bootViewBed() const { hookStates, renderView, snapshot } = bed diff --git a/tests/client.spec.mjs b/tests/client.spec.ts similarity index 99% rename from tests/client.spec.mjs rename to tests/client.spec.ts index fe490c5..e704d33 100644 --- a/tests/client.spec.mjs +++ b/tests/client.spec.ts @@ -8,7 +8,7 @@ import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import { test } from 'vitest' -import { bootViewBed, FAKE_PRIMITIVES, makeFakeDoc } from './helpers/viewBed.mjs' +import { bootViewBed, FAKE_PRIMITIVES, makeFakeDoc } from './helpers/viewBed' const bundle = await readFile(new URL('../lib/client.js', import.meta.url), 'utf8') diff --git a/tests/composition-link.spec.mjs b/tests/composition-link.spec.ts similarity index 99% rename from tests/composition-link.spec.mjs rename to tests/composition-link.spec.ts index c69651f..3db838e 100644 --- a/tests/composition-link.spec.mjs +++ b/tests/composition-link.spec.ts @@ -5,7 +5,7 @@ */ import assert from 'node:assert/strict' import { test } from 'vitest' -import { bootViewBed, byClass, catRowOf, textOf } from './helpers/viewBed.mjs' +import { bootViewBed, byClass, catRowOf, textOf } from './helpers/viewBed' const bed = await bootViewBed() const { renderView, snapshot } = bed diff --git a/tests/diff-fold.mjs b/tests/diff-fold.ts similarity index 97% rename from tests/diff-fold.mjs rename to tests/diff-fold.ts index 106bc27..1b13c2a 100644 --- a/tests/diff-fold.mjs +++ b/tests/diff-fold.ts @@ -25,7 +25,7 @@ * canonicalHeader is identity — stored headers are already canonical). * * Usage: - * bun tests/diff-fold.mjs [more.jsonl...] + * bun tests/diff-fold.ts [more.jsonl...] * zstd -dc ~/.dsh/sessions///session.jsonl.zstd > /tmp/s.jsonl * * Exit code 0 when every log matches, 1 otherwise. @@ -89,7 +89,7 @@ function imageDeltaOf(blocks) { const files = process.argv.slice(2) if (files.length === 0) { - console.error('usage: bun tests/diff-fold.mjs [...]') + console.error('usage: bun tests/diff-fold.ts [...]') process.exit(2) } diff --git a/tests/helpers/viewBed.mjs b/tests/helpers/viewBed.ts similarity index 100% rename from tests/helpers/viewBed.mjs rename to tests/helpers/viewBed.ts diff --git a/tests/hmr-safety.client.spec.mjs b/tests/hmr-safety.client.spec.ts similarity index 98% rename from tests/hmr-safety.client.spec.mjs rename to tests/hmr-safety.client.spec.ts index 79cd693..bd16cad 100644 --- a/tests/hmr-safety.client.spec.mjs +++ b/tests/hmr-safety.client.spec.ts @@ -11,7 +11,7 @@ import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import { join } from 'node:path' import { test } from 'vitest' -import { FAKE_PRIMITIVES } from './helpers/viewBed.mjs' +import { FAKE_PRIMITIVES } from './helpers/viewBed' test('client HMR safety: fiber dispose removes every registration', async () => { const bundle = await readFile(join(process.cwd(), 'lib/client.js'), 'utf8') diff --git a/tests/host.spec.mjs b/tests/host.spec.ts similarity index 100% rename from tests/host.spec.mjs rename to tests/host.spec.ts diff --git a/tests/image-tokens.spec.mjs b/tests/image-tokens.spec.ts similarity index 100% rename from tests/image-tokens.spec.mjs rename to tests/image-tokens.spec.ts diff --git a/tests/images.spec.mjs b/tests/images.spec.ts similarity index 98% rename from tests/images.spec.mjs rename to tests/images.spec.ts index c33301f..5f2fa44 100644 --- a/tests/images.spec.mjs +++ b/tests/images.spec.ts @@ -5,7 +5,7 @@ */ import assert from 'node:assert/strict' import { test } from 'vitest' -import { bootViewBed, byClass, textOf } from './helpers/viewBed.mjs' +import { bootViewBed, byClass, textOf } from './helpers/viewBed' const bed = await bootViewBed() const { hookStates, renderView, snapshot } = bed diff --git a/tests/linkage.spec.mjs b/tests/linkage.spec.ts similarity index 97% rename from tests/linkage.spec.mjs rename to tests/linkage.spec.ts index f31a393..77d9900 100644 --- a/tests/linkage.spec.mjs +++ b/tests/linkage.spec.ts @@ -5,7 +5,7 @@ */ import assert from 'node:assert/strict' import { test } from 'vitest' -import { bootViewBed, byClass, textOf } from './helpers/viewBed.mjs' +import { bootViewBed, byClass, textOf } from './helpers/viewBed' const bed = await bootViewBed() const { renderView, snapshot } = bed diff --git a/tests/modal.spec.mjs b/tests/modal.spec.ts similarity index 98% rename from tests/modal.spec.mjs rename to tests/modal.spec.ts index fd71a2c..04980df 100644 --- a/tests/modal.spec.mjs +++ b/tests/modal.spec.ts @@ -5,7 +5,7 @@ */ import assert from 'node:assert/strict' import { test } from 'vitest' -import { bootViewBed, byClass, textOf } from './helpers/viewBed.mjs' +import { bootViewBed, byClass, textOf } from './helpers/viewBed' const bed = await bootViewBed() const { bailCalls, evaluate, modalComponent, modalSource, snapshot } = bed diff --git a/tests/multimodal.spec.mjs b/tests/multimodal.spec.ts similarity index 100% rename from tests/multimodal.spec.mjs rename to tests/multimodal.spec.ts diff --git a/tests/real-react.client.spec.mjs b/tests/real-react.client.spec.ts similarity index 100% rename from tests/real-react.client.spec.mjs rename to tests/real-react.client.spec.ts diff --git a/tests/resilience.spec.mjs b/tests/resilience.spec.ts similarity index 98% rename from tests/resilience.spec.mjs rename to tests/resilience.spec.ts index 7a0ddad..b3ba62c 100644 --- a/tests/resilience.spec.mjs +++ b/tests/resilience.spec.ts @@ -6,7 +6,7 @@ */ import assert from 'node:assert/strict' import { test } from 'vitest' -import { bootViewBed, byClass, textOf } from './helpers/viewBed.mjs' +import { bootViewBed, byClass, textOf } from './helpers/viewBed' const bed = await bootViewBed() const { classInstances, evaluate, modalComponent, renderView, snapshot, viewComponent } = bed diff --git a/tests/tool-chip-bridge.spec.mjs b/tests/tool-chip-bridge.spec.ts similarity index 98% rename from tests/tool-chip-bridge.spec.mjs rename to tests/tool-chip-bridge.spec.ts index a4bc617..b90ba60 100644 --- a/tests/tool-chip-bridge.spec.mjs +++ b/tests/tool-chip-bridge.spec.ts @@ -5,7 +5,7 @@ */ import assert from 'node:assert/strict' import { test } from 'vitest' -import { bootViewBed, byClass, textOf } from './helpers/viewBed.mjs' +import { bootViewBed, byClass, textOf } from './helpers/viewBed' const bed = await bootViewBed() const { renderView, snapshot } = bed diff --git a/vitest.config.mjs b/vitest.config.mjs deleted file mode 100644 index 2eab4b0..0000000 --- a/vitest.config.mjs +++ /dev/null @@ -1,10 +0,0 @@ -import { defineConfig } from 'vitest/config' - -export default defineConfig({ - test: { - // Specs exercise the BUILT artifacts (lib/), so `pnpm run build` first. - // `*.client.spec.mjs` is the browser lane (jsdom pragma per file); the - // plain `*.spec.mjs` files run in node with their own fakes. - include: ['tests/**/*.spec.mjs'], - }, -}) diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..b1c5120 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + // Specs exercise the BUILT artifacts (lib/), so `pnpm run build` first. + // `*.client.spec.ts` is the browser lane (jsdom pragma per file); the + // plain `*.spec.ts` files run in node with their own fakes. + include: ['tests/**/*.spec.ts'], + }, +})