Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion scripts/workspaceSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { stubSpecsFor, type PackageManifest } from "./lib/sourceStubs";
import { ROOT } from "./lib/testDiscovery";
import { distToSource, listWorkspacePackages } from "./lib/workspaceSource";
import { distToSource, listWorkspacePackages, WORKSPACE_GROUPS } from "./lib/workspaceSource";

const packages = listWorkspacePackages(ROOT);

Expand Down Expand Up @@ -61,4 +61,27 @@ describe("workspace source resolution", () => {
expect(distToSource(invented)).toBeUndefined();
expect(distToSource(join(ROOT, "packages/ai/src/node.ts"))).toBeUndefined();
});

/**
* The invariant that actually broke: the resolver covers all three workspace
* groups, but the coverage denominator listed only two, so `examples/*`
* source was rewritten to `src`, executed by its own tests, and then left out
* of the denominator entirely. All three example packages are published and
* none is `private`, so there is no "not really shipped" argument for the
* omission — and a missing group is invisible in a coverage report, which
* shows a smaller file list rather than an error.
*
* Reads the ACTUAL config rather than re-deriving it, so the two cannot drift
* back apart.
*/
it("counts every workspace group in the coverage denominator", async () => {
const mod = (await import("../vitest.config.ts")) as {
default: { test?: { coverage?: { include?: string[] } } };
};
const include = mod.default.test?.coverage?.include ?? [];
const missing = WORKSPACE_GROUPS.filter(
(group) => !include.some((glob) => glob.startsWith(`${group}/`))
);
expect(missing).toEqual([]);
});
});
24 changes: 23 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,32 @@ export default defineConfig({
coverage: {
provider: "v8", // or 'istanbul'
reporter: ["text", "json", "json-summary", "html"],
/**
* Base directory the globs below resolve against. Pinned rather than
* inherited: `include`/`exclude` are documented as relative to
* `coverage.root`, which otherwise follows the run's root — and this
* config is invoked from package directories too
* (`vitest run --config ../../vitest.config.ts`), where a repo-relative
* glob would match nothing.
*/
root: __dirname,
/**
* The denominator is every package's own `src`, stated explicitly. Left
* to vitest's default (files loaded during the run), a package's score
* silently omits the modules no test imports at all — the ones a coverage
* report exists to surface — and its file list changes with whichever
* section CI happened to run.
*
* All THREE workspace groups, matching `WORKSPACE_GROUPS`: `examples/*`
* holds published, non-private packages with tests of their own, so
* omitting it drops real source from the denominator while still counting
* the tests that cover it.
*/
include: ["packages/*/src/**/*.{ts,tsx}", "providers/*/src/**/*.{ts,tsx}"],
include: [
"packages/*/src/**/*.{ts,tsx}",
"providers/*/src/**/*.{ts,tsx}",
"examples/*/src/**/*.{ts,tsx}",
],
exclude: [
...configDefaults.exclude,
// Built output is never the unit of measure. Nothing should resolve
Expand All @@ -122,6 +140,10 @@ export default defineConfig({
"**/dist/**",
// The cross-package suite is the harness, not the subject.
"packages/test/**",
// The examples keep their suites in `src/test`, which also holds the
// odd non-`.test.` helper (`chromeAvailability.ts`) that the filename
// rules below cannot catch.
"examples/*/src/test/**",
// Tests, fixtures and testing-only helpers: counting them inflates
// every package by the coverage of code that exists to be run.
"**/__tests__/**",
Expand Down
Loading