Skip to content

Commit

Permalink
fix(vite): vitest executor should continue to load plugins #22001 (#2…
Browse files Browse the repository at this point in the history
…7118)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https:/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 -->
Plugins were not being loaded by vitest executor when calling
`startVitest` when using a vite config file with a custom name.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Correctly load the plugins found in the resolved config file, regardless
of the config file name


## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #22001
  • Loading branch information
Coly010 authored Jul 25, 2024
1 parent 37cc8ab commit 58cd577
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/vite/src/executors/test/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export async function getOptions(
configFile: viteConfigPath,
};

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

export function getOptionsAsArgv(obj: Record<string, any>): string[] {
Expand Down
5 changes: 3 additions & 2 deletions packages/vite/src/executors/test/vitest.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function* vitestExecutor(
// Allows ESM to be required in CJS modules. Vite will be published as ESM in the future.
const { startVitest } = await loadVitestDynamicImport();

const resolvedOptions =
const { resolvedOptions, plugins } =
(await getOptions(options, context, projectRoot)) ?? {};

const watch = resolvedOptions['watch'] === true;
Expand All @@ -37,7 +37,8 @@ export async function* vitestExecutor(
const ctx = await startVitest(
resolvedOptions['mode'] ?? 'test',
cliFilters,
resolvedOptions
resolvedOptions,
{ plugins }
);

let hasErrors = false;
Expand Down

0 comments on commit 58cd577

Please sign in to comment.