Skip to content

Commit

Permalink
fix(vite): load the correct config file from @nx/vite:test executor
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Aug 19, 2024
1 parent 08fc13d commit ce9e895
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
45 changes: 45 additions & 0 deletions e2e/vue/src/vue-legacy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { cleanupProject, newProject, runCLI, uniq } from '@nx/e2e/utils';

describe('Vue Plugin (legacy)', () => {
let proj: string;

beforeAll(() => {
proj = newProject({
packages: ['@nx/vue'],
unsetProjectNameAndRootFormat: false,
});
});

afterAll(() => cleanupProject());

it('should serve application in dev mode', async () => {
const app = uniq('app');

runCLI(
`generate @nx/vue:app ${app} --unitTestRunner=vitest --e2eTestRunner=playwright`,
{ env: { NX_ADD_PLUGINS: 'false' } }
);
let result = runCLI(`test ${app}`);
expect(result).toContain(`Successfully ran target test for project ${app}`);

result = runCLI(`build ${app}`);
expect(result).toContain(
`Successfully ran target build for project ${app}`
);
}, 200_000);

it('should build library', async () => {
const lib = uniq('lib');

runCLI(
`generate @nx/vue:lib ${lib} --bundler=vite --unitTestRunner=vitest`,

{ env: { NX_ADD_PLUGINS: 'false' } }
);

const result = runCLI(`build ${lib}`);
expect(result).toContain(
`Successfully ran target build for project ${lib}`
);
});
});
7 changes: 2 additions & 5 deletions packages/vite/src/executors/test/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,10 @@ export async function getOptions(
// This should not be needed as it's going to be set in vite.config.ts
// but leaving it here in case someone did not migrate correctly
root: resolved.config.root ?? root,
configFile: viteConfigPath,
config: viteConfigPath,
};

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

export function getOptionsAsArgv(obj: Record<string, any>): string[] {
Expand Down
5 changes: 2 additions & 3 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, plugins } =
const resolvedOptions =
(await getOptions(options, context, projectRoot)) ?? {};

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

let hasErrors = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/utils/options-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function normalizeViteConfigFilePath(
configFile?: string
): string | undefined {
if (configFile) {
const normalized = joinPathFragments(configFile);
const normalized = joinPathFragments(contextRoot, configFile);
if (!existsSync(normalized)) {
throw new Error(
`Could not find vite config at provided path "${normalized}".`
Expand Down

0 comments on commit ce9e895

Please sign in to comment.