Commit Graph

30434 Commits

Author SHA1 Message Date
Samuel Attard
dd93cd1fa9 test: fix linux shard failures (in-app-purchase, browser-view, web-contents-view, modules/esm)
- api-in-app-purchase: wrap in ifdescribe(darwin) instead of early-return,
  which left an empty suite that vitest treats as an error
- api-browser-view: custom afterEach nulls w before defer() callbacks run;
  call runCleanupFunctions() first so defer(() => w.removeBrowserView(...))
  sees a live window
- api-web-contents-view: afterEach used contents.close() without awaiting
  destruction, so the next test's getAllWebContents() count included
  still-closing leftovers; use cleanupWebContents() which awaits 'destroyed'
- modules/esm: run the ESM-vs-CJS key comparison in a child Electron (outside
  vite's alias) via a .mjs fixture, sort both lists, and filter Node's
  CJS-interop 'default'/'module.exports' keys before comparing
2026-04-13 00:59:27 -07:00
Samuel Attard
dc8cd08dc7 perf: reuse a single BrowserWindow per sandbox mode in api-context-bridge
makeBindingWindow now lazily creates one window per describe and swaps
preloads via session.registerPreloadScript/unregisterPreloadScript instead
of constructing a fresh BrowserWindow per test. ~21s -> ~9s for 144 tests.
2026-04-13 00:59:26 -07:00
Samuel Attard
6bbc801fc2 lint: add /** @remote no-locals */ mode and tag callWithBindings
no-locals is stricter than plain @remote: closures may not reference
ANY identifier declared in the file (imports from anywhere, or file-scope
const/let/var/function/class). JS/DOM globals are fine. Applied to
callWithBindings in api-context-bridge.spec.ts, whose closures are
executeJavaScript'd in a page world with no __rt shim and no require.
2026-04-13 00:59:26 -07:00
Samuel Attard
4a506e7e25 fix: route contextBridge through remote-tools for makeBindingWindow closures
makeBindingWindow stringifies its bindingCreator closure into a preload
script; under vite the captured 'contextBridge' import becomes
__vite_ssr_import_N__.contextBridge. Tag makeBindingWindow /** @remote */,
run rewriteForRemoteEval on the closure, and declare 'const __rt = renderer_1'
in the preload so __rt.contextBridge resolves.

remote-tools.ts re-exports contextBridge/ipcRenderer/webFrame from
electron/renderer — undefined at runtime in the main process, but typed
correctly for closures that only ever execute in a preload.

callWithBindings closures only reference their 'root' param, so no change
needed there. 144/144 pass.
2026-04-13 00:59:26 -07:00
Samuel Attard
59b3e45d0c perf: share a single utility process across itUtility tests in api-net
Lazy-fork once, await a 'ready' handshake, then post each test body to the
same long-lived child. The fixture no longer exits after each message; it
posts {ok:false} on failure and keeps running, and exits cleanly on a
{type:'shutdown'} message sent from afterAll.
2026-04-13 00:59:26 -07:00
Samuel Attard
2276abbd96 feat: support /** @remote */ tagging in the remote-tools-imports lint rule
Functions declared with a /** @remote */ JSDoc (or const/for-of bindings
so tagged) are treated like itremote/remotely: any closure passed to them
is checked for imports that don't come from ./lib/remote-tools.

api-net.spec.ts's itUtility stringifies its closure and posts it to a
utility-process fixture, so it's the same __vite_ssr_import_ problem.
- itUtility now runs rewriteForRemoteEval(fn) before posting
- the fixture declares a local __rt spreading net-helpers + electron/main
- the for-of loop that aliases itUtility as 'test' is tagged @remote
- remote-tools.ts re-exports net, session, http, defer, and the net-helpers
- api-net.spec.ts imports those via remote-tools (closure bodies unchanged)

api-net: 252 passed / 2 todo.
2026-04-13 00:59:25 -07:00
Samuel Attard
5b10d20d38 chore: update yarn.lock after dropping sinon from spec deps 2026-04-13 00:59:25 -07:00
Samuel Attard
88ec0f4bef test: await two previously-unawaited waitUntil calls
Both passed without actually waiting for the condition; now that waitUntil
takes ctx.signal they at least stopped on abort, but the assertions were
still never gating the test.
2026-04-13 00:59:25 -07:00
Samuel Attard
cb60689173 test: replace sinon with vi.mock in version-bump and drop sinon dep
Same ESM-vs-CJS stub issue as release-notes: sinon.stub on
require('node:child_process') doesn't intercept the ESM import that
version-bumper.ts uses under vite. vi.mock('node:child_process', {spy:true})
does. sinon is no longer used anywhere in spec/.
2026-04-13 00:59:24 -07:00
Samuel Attard
34c05cd1a5 refactor: thread ctx.signal through waitUntil so polling stops on test abort 2026-04-13 00:59:24 -07:00
Samuel Attard
4929a267e6 test: replace sinon stub with vi.mock for spawnSync in release-notes
Under vite, notes.ts imports spawnSync via ESM; sinon.stub on the CJS
require() object doesn't intercept that binding. vi.mock('node:child_process',
{spy: true}) replaces the module in vite's graph so vi.mocked(cp.spawnSync)
.mockImplementation() applies to the import notes.ts sees.
2026-04-13 00:59:24 -07:00
Samuel Attard
7d31ad9297 test: write unload/close fixture output to per-test tmp paths
close.html and unload.html previously wrote to __dirname + '/close'|'/unload'
inside spec/fixtures/api/ itself. Pass the output path via ?out= query param
and use a pid+timestamp tmp file so parallel workers and retries never race.
2026-04-13 00:59:24 -07:00
Samuel Attard
8cebedc7b6 test: fix nested it() calls that should have been describe()/ifdescribe()
16 inner it() calls in api-browser-window.spec.ts were wrapped in an outer
it() or ifit() where the author meant describe()/ifdescribe(). Under mocha
these inner tests were registered as siblings at collection time; under
vitest they throw. Also removes two unused chai imports in api-safe-storage
left over from moving chai.use() to setup.ts.
2026-04-13 00:59:23 -07:00
Samuel Attard
69c9ff51eb lint: add no-nested-tests rule for it()/ifit() nested in test bodies
Mocha silently tolerated it() inside another it()/ifit() body; vitest does
not. The rule tracks test-call nesting depth and flags any inner definition.
2026-04-13 00:59:23 -07:00
Samuel Attard
64f3c1c199 chore: route itremote/remotely closure imports through remote-tools
Swaps expect/setTimeout/BrowserWindow imports in the 5 files flagged by
remote-tools-imports/no-foreign-imports-in-remote-closure so their
stringified closures resolve via the __rt shim. Import-line changes only.
2026-04-13 00:59:23 -07:00
Samuel Attard
0d321ccae0 lint: add rule banning foreign imports in itremote/remotely closures
remote-tools-imports/no-foreign-imports-in-remote-closure flags any
identifier inside an itremote()/remotely() closure that is bound to an
import from somewhere other than spec/lib/remote-tools. Those bindings
get rewritten to __vite_ssr_import_N__ by vite's SSR transform and fail
when the closure is stringified and eval'd in a remote context.

Skips type-only imports and type-annotation positions. Currently flags
50 sites across 5 files (node, webview, chromium, fuses, api-native-image).
2026-04-13 00:59:22 -07:00
Samuel Attard
36e5f6a2a5 feat: add spec/lib/remote-tools for imports used in itremote/remotely closures
vite's SSR transform rewrites import bindings to __vite_ssr_import_N__,
which breaks closures that are stringified and eval'd in a remote context.

remote-tools.ts re-exports the common modules (path, fs, url, expect, ...)
so spec files can 'import { path, expect } from ./lib/remote-tools' and
closure bodies stay unchanged. runRemote/remotely regex-replace every
__vite_ssr_import_N__ with __rt (a renderer-side object whose keys mirror
the remote-tools export names), so __rt.path.join(...) etc. resolve with
no property-name ambiguity.

asar.spec.ts: 170 failing itremote tests -> 0, import-line changes only.
2026-04-13 00:59:22 -07:00
Samuel Attard
65f2dee205 build: use 8-core Linux test runners for parallel vitest workers 2026-04-13 00:59:22 -07:00
Samuel Attard
c2304737f1 fix: correct defer() ordering and make runCleanupFunctions drain-safe
vitest's onTestFinished runs *after* afterEach (contrary to the earlier
assumption), so defer() callbacks saw windows already destroyed by
afterEach(closeAllWindows). And runCleanupFunctions didn't clear its
queue on throw, so one bad defer cascaded into every subsequent test.

- runCleanupFunctions now splices the queue before iterating and wraps
  each cleanup in try/catch, aggregating errors.
- closeAllWindows runs runCleanupFunctions() first, so the 190+ existing
  afterEach(closeAllWindows) call sites get mocha's ordering (defers run,
  then windows close) without modification. setup.ts's onTestFinished
  remains as a fallback for tests that defer() without closeAllWindows.
- cleanupWebContents guards against already-destroyed contents.
2026-04-13 00:59:21 -07:00
Samuel Attard
8e51023155 test: await closeWindow(c) in 'should attach child window to parent'
The unawaited async call let the child window linger into the next test's
afterEach assertNotWindows check.
2026-04-13 00:59:21 -07:00
Samuel Attard
7cdd1314d2 fix: drop unused assertNotWindows param from closeAllWindows
vitest passes a context object as the first arg to hook callbacks, so
afterEach(closeAllWindows) effectively called closeAllWindows(ctx) - a
truthy value that triggered the unused assert-no-windows-remain path,
producing unhandled rejections. afterAll(closeAllWindows) failed outright
with a FixtureParseError because vitest parses the param list.

No caller ever passed the argument explicitly, so the param is removed.
2026-04-13 00:59:21 -07:00
Samuel Attard
984f5c5023 test: isolate OS-singleton tests into spec/serial/ for post-parallel execution 2026-04-13 00:59:21 -07:00
Samuel Attard
abadff1643 test: deflake 'creates unique session id for each target'
Await each CDP step in sequence and use Runtime.evaluate on the attached
session after Debugger.enable is acknowledged, so Debugger.scriptParsed is
guaranteed to fire regardless of page-load timing. 0/10 flakes (was ~3/5).
2026-04-13 00:59:20 -07:00
Samuel Attard
6beb0f3de3 fix: use inline require() in stringified utility-process closure
The closure at spec/api-app.spec.ts:2282 is stringified and eval'd inside
a utility-process fixture. Under vite's SSR transform the captured import
bindings become __vite_ssr_import_N__ refs that don't exist in the fixture.
Inline require() calls survive toString() intact.
2026-04-13 00:59:20 -07:00
Samuel Attard
2e826cdaa4 fix: align runner app name, userData path, and decouple net-helpers from vitest
- spec/_vitest_runner/package.json: name/productName match spec/package.json
  so app.name assertions hold
- worker-entry: userData is <mkdtemp>/<app.name>/ so getPath('userData')
  still includes the app name
- net-helpers: import defer from defer-helpers and own listen() directly,
  so the utility-process fixture (which ts-node-requires net-helpers) no
  longer pulls in spec-helpers -> vitest
2026-04-13 00:59:20 -07:00
Samuel Attard
dc02d7907b fix: use regex alias for electron/* and split defer helpers from spec-helpers
vite's resolve.alias in object form matched the bare 'electron' specifier
but not 'electron/main' etc. The array-with-regex form matches all four.

Also extract defer/runCleanupFunctions into spec/lib/defer-helpers.ts so
setup.ts doesn't transitively import 'electron/main' (setupFiles go
through a slightly different SSR load path than test files).
2026-04-13 00:59:19 -07:00
Samuel Attard
3bb67099de chore: remove remaining mocha references
- refresh-page fixture served mocha.js as a 'large JS file' over a custom
  protocol; point it at chai.js instead since mocha is no longer a dep
- drop descriptive 'mocha' mentions from comments
2026-04-13 00:59:19 -07:00
Samuel Attard
6fea5e8691 build: switch spec runner from mocha to vitest 2026-04-13 00:59:19 -07:00
Samuel Attard
7a5dc9e725 chore: remove ELECTRON_FORCE_TEST_SUITE_EXIT mechanism
This was a win-arm64 workaround for the mocha runner: process.exit() could
hang in the single Electron process, so the suite SIGTERMed itself after
printing the failure count to stdout for script/spec-runner.js to scrape.

Under vitest, the process that decides and reports the exit code is the
plain-Node vitest CLI; Electron instances are pool workers that the pool
tears down. The workaround no longer applies.
2026-04-13 00:59:19 -07:00
Samuel Attard
2067a6b975 chore: port CI-only behaviour and defer() ordering from spec/index.js
- allowOnly: !CI matches mocha's forbidOnly
- retry: 3 on CI matches mocha's CI retries
- runCleanupFunctions via ctx.onTestFinished so defer()-ed cleanups run
  before test-file afterEach hooks, matching the per-suite hook ordering
  in spec/index.js
2026-04-13 00:59:18 -07:00
Samuel Attard
3dbd48441e chore: replace ifit/ifdescribe addOnly shim with vitest runIf 2026-04-13 00:59:18 -07:00
Samuel Attard
6eee70a432 chore: migrate webview-spec.ts to vitest 2026-04-13 00:59:18 -07:00
Samuel Attard
07cdd3543b chore: migrate visibility-state-spec.ts to vitest 2026-04-13 00:59:17 -07:00
Samuel Attard
e7d867952c chore: migrate version-bump-spec.ts to vitest 2026-04-13 00:59:17 -07:00
Samuel Attard
e4474b232e chore: migrate types-spec.ts to vitest 2026-04-13 00:59:17 -07:00
Samuel Attard
d39cbc204b chore: migrate spellchecker-spec.ts to vitest 2026-04-13 00:59:17 -07:00
Samuel Attard
b1f3befe21 chore: migrate security-warnings-spec.ts to vitest 2026-04-13 00:59:16 -07:00
Samuel Attard
6d99359799 chore: migrate release-notes-spec.ts to vitest 2026-04-13 00:59:16 -07:00
Samuel Attard
b5c9d0bdff chore: migrate process-binding-spec.ts to vitest 2026-04-13 00:59:16 -07:00
Samuel Attard
46464ace53 chore: migrate parse-features-string-spec.ts to vitest 2026-04-13 00:59:15 -07:00
Samuel Attard
46ce6bdc94 chore: migrate node-spec.ts to vitest 2026-04-13 00:59:15 -07:00
Samuel Attard
295deb50e0 chore: migrate modules-spec.ts to vitest 2026-04-13 00:59:15 -07:00
Samuel Attard
2e8b3fb5bf chore: migrate mas-spec.ts to vitest 2026-04-13 00:59:14 -07:00
Samuel Attard
4304cd88b6 chore: migrate logging-spec.ts to vitest 2026-04-13 00:59:14 -07:00
Samuel Attard
b93c6dd11a chore: migrate guest-window-manager-spec.ts to vitest 2026-04-13 00:59:14 -07:00
Samuel Attard
6c9447f2e6 chore: migrate fuses-spec.ts to vitest 2026-04-13 00:59:14 -07:00
Samuel Attard
1127cd3b6c chore: migrate extensions-spec.ts to vitest 2026-04-13 00:59:13 -07:00
Samuel Attard
0608bc93a0 chore: migrate esm-spec.ts to vitest 2026-04-13 00:59:13 -07:00
Samuel Attard
0a1e6119a6 chore: migrate drag-region-spec.ts to vitest 2026-04-13 00:59:13 -07:00
Samuel Attard
d69cee4a05 chore: migrate deprecate-spec.ts to vitest 2026-04-13 00:59:12 -07:00