GioJSdocs
On this page

resetTestApp

Forget the routes renderPage and callRoute discovered, so the next call sees files your test added or removed.

ts
import { resetTestApp } from '@gio.js/core/testing';

await resetTestApp();

Reference

ParameterTypeDefaultDescription
appDirstringevery appThe app/ directory to forget, resolved like renderPage's appDir option. Left out, every app directory discovered in this process is forgotten.

Behavior

  • renderPage and callRoute discover an app directory once per process - routes, layouts, handlers, special files, gio.config.ts plugins - and reuse it. resetTestApp drops that, and the next call discovers again.
  • It runs the dropped apps' plugin onShutdown hooks, and resolves once they finished. A directory that was never discovered is ignored.
  • It does not unload modules. A page, layout or helper that was already imported stays as it was - vi.resetModules() does not change that - so an edit to it shows up only in a new test process. Values already loaded from .env files stay in process.env as well.

Examples

A route added by the test

tests/generated-routes.test.ts
import { mkdir, rm, writeFile } from 'node:fs/promises';
import { afterAll, expect, it } from 'vitest';
import { callRoute, resetTestApp } from '@gio.js/core/testing';

afterAll(async () => {
  await rm('app/api/generated', { recursive: true, force: true });
  await resetTestApp();
});

it('serves a route.ts written during the test', async () => {
  await mkdir('app/api/generated', { recursive: true });
  await writeFile('app/api/generated/route.ts', 'export const GET = () => ({ generated: true });');
  await resetTestApp();                       // discover again
  const res = await callRoute('/api/generated');
  expect(await res.json()).toEqual({ generated: true });
});

Run plugin shutdown hooks

ts
import { after } from 'node:test';
import { resetTestApp } from '@gio.js/core/testing';

// Closes the database pool your gio.config.ts plugin opened in onStartup.
after(() => resetTestApp());

Good to know

  • Module state outlives it. Reset module-level state of your own (an in-memory store, a counter) in your own beforeEach.
  • vitest isolates test files by default, and node --test runs each file in its own process, so a fresh file always starts with a fresh discovery.
  • It does not touch servers started with createTestServer; restart those to pick up file changes.

Version history

VersionChanges
v0.1.0-beta.8Introduced.