revert(test): abandon shared-mock dedup — infeasible in vitest browser mode
CI proved cross-file sharing of a virtual-module mock body cannot work in
@vitest/browser-playwright 4.1.6: the static-import spread fails the hoist
("no top level variables"), and the await-vi.hoisted-import form fails to
parse ("Unexpected identifier 'vi'"). vi.hoisted has the same hoist
constraint as vi.mock, so there is no way to thread an external module's
body into the factory here.
Reverts Phase 1: restores the 4 $app/forms/$app/navigation specs to their
inline factories, inlines NotificationBell.spec's forms stub, deletes the
src/__mocks__/$app/* modules and the $mocks alias (vite, vitest-coverage,
kit). The no-factory-ban meta-test stays (no-factory vi.mock is still
banned). ADR-012 amended to record the infeasibility. Everything else
($app/state migration, confirm context-inject, notification refactor, the
pin, the meta-test) is unaffected. Part of #560.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -11,9 +11,10 @@ import { fileURLToPath } from 'url';
|
||||
// implementation (replaceState, which delegates through a getter). The result
|
||||
// is a partial mock that crashes when an unsubstituted export is hit.
|
||||
//
|
||||
// The sanctioned dedup pattern keeps the factory and shares its body:
|
||||
// import * as formsMock from '$mocks/$app/forms';
|
||||
// vi.mock('$app/forms', () => ({ ...formsMock }));
|
||||
// The sanctioned form keeps an INLINE sync factory:
|
||||
// vi.mock('$app/forms', () => ({ enhance(node, submit) { ... } }));
|
||||
// (Sharing the body via a module imported into the factory is infeasible in
|
||||
// browser mode — vitest hoists vi.mock above the import; see ADR-012.)
|
||||
//
|
||||
// ESLint and the CI grep guard catch the pattern earlier; this in-suite test
|
||||
// catches it at every vitest invocation — the layer hardest to disable. It
|
||||
@@ -60,9 +61,10 @@ describe('scan: hasNoFactoryViMock', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('does not flag a vi.mock with a shared-body spread factory', () => {
|
||||
const fixture = `import * as formsMock from '$mocks/$app/forms';
|
||||
vi.mock('$app/forms', () => ({ ...formsMock }));`;
|
||||
it('does not flag a vi.mock with a multi-line inline factory', () => {
|
||||
const fixture = `vi.mock('$app/forms', () => ({
|
||||
enhance: (node, submit) => ({ destroy() {} })
|
||||
}));`;
|
||||
expect(hasNoFactoryViMock(fixture)).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user