Summary
Add helper(s) to copy files into this.workspace from globs resolved relative to the current spec file, preserving (or optionally stripping) path structure. This replaces one-off writeFile seeding when a test needs a realistic fixture tree.
Desired API
given: {
tests_are_in_workspace,
}
async function tests_are_in_workspace(this: Context) {
await copy_to_workspace(this.workspace, ["fixtures/**/*.spec.ts"]);
}
Globs are resolved from the directory of the calling spec (the folder that contains the current *.spec.ts), so a layout like:
my-feature.spec.ts
fixtures/
suite-a/
foo.spec.ts
suite-b/
nested/
bar.spec.ts
copies those files into the temp workspace while preserving relative paths under that source root.
Base-path stripping
Support an optional base-path pattern so consumers can drop leading segments when placing files in the workspace. Example: base "fixtures/*" removes the first two path segments when they match fixtures/<anything>:
| Source (relative to spec dir) |
Destination in workspace |
fixtures/suite-a/foo.spec.ts |
foo.spec.ts |
fixtures/suite-b/nested/bar.spec.ts |
nested/bar.spec.ts |
Without a base path, preserve the full relative path from the spec directory (including fixtures/...).
Sketch (exact signature TBD):
await copy_to_workspace(this.workspace, ["fixtures/**/*.spec.ts"], {
base: "fixtures/*",
});
Acceptance criteria
Notes
- Today seeding is manual (
writeFile in given steps); this is the structured alternative for fixture trees.
- Prefer small, composable helpers over a heavy fixture framework.
- Implementation will need a reliable “directory of the current spec” signal under vitest (e.g.
import.meta.dirname at the call site, or a helper that accepts an explicit from / uses vitest’s test-file path). Decide in implementation which approach is least surprising and document it.
Summary
Add helper(s) to copy files into
this.workspacefrom globs resolved relative to the current spec file, preserving (or optionally stripping) path structure. This replaces one-offwriteFileseeding when a test needs a realistic fixture tree.Desired API
Globs are resolved from the directory of the calling spec (the folder that contains the current
*.spec.ts), so a layout like:copies those files into the temp workspace while preserving relative paths under that source root.
Base-path stripping
Support an optional base-path pattern so consumers can drop leading segments when placing files in the workspace. Example: base
"fixtures/*"removes the first two path segments when they matchfixtures/<anything>:fixtures/suite-a/foo.spec.tsfoo.spec.tsfixtures/suite-b/nested/bar.spec.tsnested/bar.spec.tsWithout a base path, preserve the full relative path from the spec directory (including
fixtures/...).Sketch (exact signature TBD):
Acceptance criteria
copy_to_workspace(workspace, globs, options?)helper fromagent-gwtprocess.cwd()/ package root)workspace, creating parent dirs as neededbasepattern strips a matching path prefix (e.g.fixtures/*→ dropfixtures/<segment>/) before writing into the workspacebasedoes not silently corrupt paths (document / error behavior)Notes
writeFilein given steps); this is the structured alternative for fixture trees.import.meta.dirnameat the call site, or a helper that accepts an explicitfrom/ uses vitest’s test-file path). Decide in implementation which approach is least surprising and document it.