Skip to content

Commit

Permalink
fix(vite): default vitest provider to v8 (nrwl#18515)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini authored Aug 8, 2023
1 parent 006180b commit ff04be5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/vite/src/executors/test/vitest.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import {
ExecutorContext,
joinPathFragments,
logger,
readJsonFile,
stripIndents,
workspaceRoot,
} from '@nx/devkit';
import { CoverageOptions, File, Reporter } from 'vitest';
import { loadConfigFromFile } from 'vite';
import { VitestExecutorOptions } from './schema';
import { relative, resolve } from 'path';
import { join, relative, resolve } from 'path';
import { existsSync } from 'fs';
import { registerTsConfigPaths } from '@nx/js/src/internal';

Expand Down Expand Up @@ -99,14 +100,25 @@ async function getSettings(
context: ExecutorContext,
projectRoot: string
) {
const packageJsonPath = join(workspaceRoot, 'package.json');
const packageJson = existsSync(packageJsonPath)
? readJsonFile(packageJsonPath)
: undefined;
let provider: 'v8' | 'c8' = 'v8';
if (
packageJson?.dependencies?.['@vitest/coverage-c8'] ||
packageJson?.devDependencies?.['@vitest/coverage-c8']
) {
provider = 'c8';
}
const offset = relative(workspaceRoot, context.cwd);
// if reportsDirectory is not provided vitest will remove all files in the project root
// when coverage is enabled in the vite.config.ts
const coverage: CoverageOptions = options.reportsDirectory
? {
enabled: options.coverage,
reportsDirectory: options.reportsDirectory,
provider: 'c8',
provider,
}
: ({} as CoverageOptions);

Expand Down

0 comments on commit ff04be5

Please sign in to comment.