fix(testing): do not set vitest root when not in workspaceRoot (#14362)
This commit is contained in:
parent
f1f69df470
commit
7857ae00a0
@ -592,7 +592,7 @@ export function runCommandAsync(
|
||||
exec(
|
||||
command,
|
||||
{
|
||||
cwd: tmpProjPath(),
|
||||
cwd: opts.cwd || tmpProjPath(),
|
||||
env: {
|
||||
CI: 'true',
|
||||
...(opts.env || getStrippedEnvironmentVariables()),
|
||||
|
||||
@ -205,6 +205,14 @@ describe('Vite Plugin', () => {
|
||||
expect(result.combinedOutput).toContain(
|
||||
`Successfully ran target test for project ${lib}`
|
||||
);
|
||||
|
||||
// TODO(caleb): run tests from project root and make sure they still work
|
||||
const nestedResults = await runCLIAsync(`test ${lib} --skip-nx-cache`, {
|
||||
cwd: `${tmpProjPath()}/libs/${lib}`,
|
||||
});
|
||||
expect(nestedResults.combinedOutput).toContain(
|
||||
`Successfully ran target test for project ${lib}`
|
||||
);
|
||||
}, 100_000);
|
||||
|
||||
it('should collect coverage', () => {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { ExecutorContext } from '@nrwl/devkit';
|
||||
import { ExecutorContext, workspaceRoot } from '@nrwl/devkit';
|
||||
import { File, Reporter } from 'vitest';
|
||||
import { VitestExecutorOptions } from './schema';
|
||||
import { relative } from 'path';
|
||||
|
||||
class NxReporter implements Reporter {
|
||||
deferred: {
|
||||
@ -46,11 +47,15 @@ export default async function* runExecutor(
|
||||
)() as Promise<typeof import('vitest/node')>);
|
||||
|
||||
const projectRoot = context.projectGraph.nodes[context.projectName].data.root;
|
||||
const offset = relative(workspaceRoot, context.cwd);
|
||||
|
||||
const nxReporter = new NxReporter(options.watch);
|
||||
const settings = {
|
||||
...options,
|
||||
root: projectRoot,
|
||||
// when running nx from the project root, the root will get appended to the cwd.
|
||||
// creating an invalid path and no tests will be found.
|
||||
// instead if we are not at the root, let the cwd be root.
|
||||
root: offset === '' ? projectRoot : '',
|
||||
reporters: [...(options.reporters ?? []), 'default', nxReporter],
|
||||
// if reportsDirectory is not provides vitest will remove all files in the project root
|
||||
// when coverage is enabled in the vite.config.ts
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user