Skip to content

Commit 8e6c007

Browse files
authored
fix(vite): correct mapping for reportsDirectory when using executors (#30232)
Using vitest whenever we merge configs from executors and the config file. The executors should override the option which has be set inside of the config file. <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> The `reportsDirectory` option which can be set when using `@nx/vite:test` is not override the generated coverage directory path. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> When the `@nx/vite:test` executor runs the option `reportsDirectory` should override the option set inside `vite.config` ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #30223
1 parent 6678c74 commit 8e6c007

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

e2e/vite/src/vite-legacy.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ describe('Vite Plugin', () => {
8787
const result = runCLI(`test ${myApp}`);
8888
expect(result).toContain('Successfully ran target test');
8989
}, 200_000);
90+
91+
it('should generate a coverage file specified by the executor', async () => {
92+
updateJson(`${myApp}/project.json`, (json) => {
93+
json.targets.test.options.reportsDirectory = '../coverage/test-dir';
94+
return json;
95+
});
96+
97+
const result = runCLI(`test ${myApp} --coverage`);
98+
99+
checkFilesExist(`coverage/test-dir/index.html`);
100+
expect(result).toContain('Coverage report');
101+
}, 200_000);
90102
});
91103
});
92104

packages/vite/src/executors/test/lib/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,22 @@ export async function getOptions(
6767
options: { watch, ...normalizedExtraArgs },
6868
} = parseCLI(['vitest', ...getOptionsAsArgv(options)]);
6969

70+
const { reportsDirectory, coverage, ...restNormalizedArgs } =
71+
normalizedExtraArgs as Record<string, any>;
72+
7073
const settings = {
7174
// Explicitly set watch mode to false if not provided otherwise vitest
7275
// will enable watch mode by default for non CI environments
7376
watch: watch ?? false,
74-
...normalizedExtraArgs,
77+
...restNormalizedArgs,
7578
// This should not be needed as it's going to be set in vite.config.ts
7679
// but leaving it here in case someone did not migrate correctly
7780
root: resolved.config.root ?? root,
7881
config: viteConfigPath,
82+
coverage: {
83+
...(coverage ?? {}),
84+
...(reportsDirectory && { reportsDirectory }),
85+
},
7986
};
8087

8188
return mergeConfig(resolved?.config?.['test'] ?? {}, settings);

0 commit comments

Comments
 (0)