Skip to content

Prevent silent unit/integration test misclassification via positive manifest (#1307 follow-up) #1314

@cliffhall

Description

@cliffhall

Background

#1307 added a new `integration` vitest project for v1.5-ported tests that need node env + 30s timeouts. Membership is controlled by an explicit `integrationTests` array in `clients/web/vite.config.ts`:

```ts
const integrationTests = [
'clients/web/src/test/core/inspectorClient.test.ts',
...
];

projects: [
{ name: 'unit', include: ['clients/web/src/**/*.test.{ts,tsx}'], exclude: integrationTests },
{ name: 'integration', include: integrationTests },
]
```

A new test file under `src/test/core/` that isn't added to `integrationTests` silently falls into the unit project and runs under happy-dom. There's a comment acknowledging this, but it's a sharp edge: an integration-style test that should spawn a real server will fail (or pass for the wrong reasons) under happy-dom with no signal at authoring time.

Proposed change

Flip the manifest so the project that runs is determined by file location rather than enumeration:

```ts
{ name: 'unit', include: ['clients/web/src//*.test.{ts,tsx}'], exclude: ['clients/web/src/test/integration/'] },
{ name: 'integration', include: ['clients/web/src/test/integration/**/*.test.ts'] },
```

This means either:

A) Move the 13 integration tests under a dedicated `src/test/integration/` folder (with sub-paths mirroring source layout) and drop the explicit `integrationTests` array. Cleanest, but it's a 13-file rename + import-path audit.

B) Keep tests where they are, add a per-file marker (e.g. a regex on the first line — `/* @vitest-environment node */`) and have the integration project glob with a filter. More plumbing, less file movement.

Recommend (A) — the rename is mechanical and the layout becomes self-documenting.

Why

  • Removes the developer trap entirely — there's no way to add a node-env test that accidentally runs under happy-dom (or vice versa).
  • The `integrationTests` array would no longer drift from reality silently.
  • Layout matches how most monorepos disambiguate test scopes (`unit/`, `integration/`, `e2e/`).

Acceptance criteria

  • Integration tests live in a path that the integration project's `include` glob owns, and unit's `include` excludes (no explicit enumeration).
  • Adding a new file under `src/test/integration/` automatically runs in node env; adding one outside automatically runs in happy-dom.
  • `npm run test:integration` and `npm run test:coverage` still pass with the same 13 files / 298 tests.
  • tsconfig.test.json `include` paths updated to match.

Out of scope

  • Renaming the unit-test directory structure or introducing a third project.
  • Changing what counts as "integration" — same 13 files in scope.

Origin

PR #1312 review comment (observation #5).

Metadata

Metadata

Assignees

No one assigned

    Labels

    v2Issues and PRs for v2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions