Skip to content

Commit

Permalink
fix(vitest-angular): use vite overrides to pass test watch mode (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts authored Dec 17, 2024
1 parent 7a85cb9 commit 438571f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
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

0 comments on commit 438571f

Please sign in to comment.