Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vitest-angular): use vite overrides to pass test watch mode #1509

Merged
merged 1 commit into from
Dec 17, 2024
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
1 change: 0 additions & 1 deletion libs/card/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"prefix": "lib",
"projectType": "library",
"tags": [],
"implicitDependencies": ["vitest-angular"],
"targets": {
"test": {
"executor": "@nx/vite:test"
Expand Down
8 changes: 3 additions & 5 deletions packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function angular(options?: PluginOptions): Plugin[] {
let nextProgram: NgtscProgram | undefined | ts.Program;
let builderProgram: ts.EmitAndSemanticDiagnosticsBuilderProgram;
let watchMode = false;
let testWatchMode = process.env['ANALOG_VITEST_WATCH'] === 'true';
let testWatchMode = false;
const sourceFileCache = new SourceFileCache();
const isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];
const isStackBlitz = !!process.versions['webcontainer'];
Expand Down Expand Up @@ -216,13 +216,11 @@ export function angular(options?: PluginOptions): Plugin[] {
resolvedConfig = config;

// set test watch mode
// - environment variable from vitest-angular
// - vite override from vitest-angular
// - @nx/vite executor set server.watch explicitly to undefined (watch)/null (watch=false)
// - vite config for test.watch variable
testWatchMode =
testWatchMode ||
!(config.server.watch === null) ||
config.test?.watch === true;
!(config.server.watch === null) || config.test?.watch === true;
},
configureServer(server) {
viteServer = server;
Expand Down
8 changes: 5 additions & 3 deletions packages/vitest-angular/src/lib/builders/test/vitest.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ async function vitestBuilder(
): Promise<BuilderOutput> {
process.env['TEST'] = 'true';
process.env['VITEST'] = 'true';
process.env['ANALOG_VITEST_WATCH'] = `${options.watch === true}`;

const { startVitest } = await (Function(
'return import("vitest/node")'
Expand All @@ -22,14 +21,17 @@ async function vitestBuilder(
context.target as unknown as string
);
const extraArgs = await getExtraArgs(options);
const watch = options.watch === true;
const config = {
root: `${projectConfig['root'] || '.'}`,
watch: options.watch === true,
watch,
config: options.configFile,
...extraArgs,
};

const server = await startVitest('test', options.testFiles ?? [], config);
const server = await startVitest('test', options.testFiles ?? [], config, {
test: { watch },
});

let hasErrors = false;

Expand Down
Loading