fix(react): fix react windows e2e tests (#16959)
This commit is contained in:
parent
ad8099a764
commit
e8c31d7ac7
@ -1,5 +1,6 @@
|
||||
import {
|
||||
ExecutorContext,
|
||||
joinPathFragments,
|
||||
logger,
|
||||
stripIndents,
|
||||
workspaceRoot,
|
||||
@ -7,7 +8,7 @@ import {
|
||||
import { CoverageOptions, File, Reporter } from 'vitest';
|
||||
import { loadConfigFromFile } from 'vite';
|
||||
import { VitestExecutorOptions } from './schema';
|
||||
import { join, relative } from 'path';
|
||||
import { relative } from 'path';
|
||||
import { existsSync } from 'fs';
|
||||
|
||||
class NxReporter implements Reporter {
|
||||
@ -105,8 +106,8 @@ async function getSettings(
|
||||
: ({} as CoverageOptions);
|
||||
|
||||
const viteConfigPath = options.config
|
||||
? join(context.root, options.config)
|
||||
: findViteConfig(join(context.root, projectRoot));
|
||||
? joinPathFragments(context.root, options.config)
|
||||
: findViteConfig(joinPathFragments(context.root, projectRoot));
|
||||
|
||||
const resolved = await loadConfigFromFile(
|
||||
{
|
||||
@ -148,8 +149,10 @@ function findViteConfig(projectRootFullPath: string): string {
|
||||
const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];
|
||||
|
||||
for (const ext of allowsExt) {
|
||||
if (existsSync(join(projectRootFullPath, `vite.config.${ext}`))) {
|
||||
return join(projectRootFullPath, `vite.config.${ext}`);
|
||||
if (
|
||||
existsSync(joinPathFragments(projectRootFullPath, `vite.config.${ext}`))
|
||||
) {
|
||||
return joinPathFragments(projectRootFullPath, `vite.config.${ext}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
import dts from 'vite-plugin-dts';
|
||||
import { join } from 'path';
|
||||
import { joinPathFragments } from '@nx/devkit';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../node_modules/.vite/my-lib',
|
||||
@ -14,7 +14,7 @@ export default defineConfig({
|
||||
plugins: [
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
react(),
|
||||
@ -59,7 +59,7 @@ import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
import dts from 'vite-plugin-dts';
|
||||
import { join } from 'path';
|
||||
import { joinPathFragments } from '@nx/devkit';
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: '../../node_modules/.vite/react-lib-nonb-jest',
|
||||
@ -67,7 +67,7 @@ export default defineConfig({
|
||||
plugins: [
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
react(),
|
||||
@ -152,7 +152,7 @@ exports[`@nx/vite:configuration library mode should set up non buildable library
|
||||
|
||||
exports[`@nx/vite:configuration library mode should set up non buildable library which already has vite.config.ts correctly 1`] = `
|
||||
"import dts from 'vite-plugin-dts';
|
||||
import { join } from 'path';
|
||||
import { joinPathFragments } from '@nx/devkit';
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
@ -185,7 +185,7 @@ export default defineConfig({
|
||||
],
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
],
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
exports[`ensureViteConfigIsCorrect should add build and test options if defineConfig is empty 1`] = `
|
||||
"import dts from 'vite-plugin-dts';
|
||||
import { join } from 'path';
|
||||
import { joinPathFragments } from '@nx/devkit';
|
||||
|
||||
/// <reference types="vitest" />
|
||||
import { defineConfig } from 'vite';
|
||||
@ -30,7 +30,7 @@ import { join } from 'path';
|
||||
},plugins: [
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
react(),
|
||||
@ -51,7 +51,7 @@ import { join } from 'path';
|
||||
|
||||
exports[`ensureViteConfigIsCorrect should add build option but not update test option if test already setup 1`] = `
|
||||
"import dts from 'vite-plugin-dts';
|
||||
import { join } from 'path';
|
||||
import { joinPathFragments } from '@nx/devkit';
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
@ -83,7 +83,7 @@ import { defineConfig } from 'vite';
|
||||
],
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
],
|
||||
@ -103,7 +103,7 @@ import { defineConfig } from 'vite';
|
||||
|
||||
exports[`ensureViteConfigIsCorrect should add build options if build options don't exist 1`] = `
|
||||
"import dts from 'vite-plugin-dts';
|
||||
import { join } from 'path';
|
||||
import { joinPathFragments } from '@nx/devkit';
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
@ -135,7 +135,7 @@ import { defineConfig } from 'vite';
|
||||
],
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
],
|
||||
@ -155,7 +155,7 @@ import { defineConfig } from 'vite';
|
||||
|
||||
exports[`ensureViteConfigIsCorrect should add build options if defineConfig is not used 1`] = `
|
||||
"import dts from 'vite-plugin-dts';
|
||||
import { join } from 'path';
|
||||
import { joinPathFragments } from '@nx/devkit';
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
@ -194,7 +194,7 @@ import { defineConfig } from 'vite';
|
||||
],
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
],
|
||||
@ -227,7 +227,7 @@ exports[`ensureViteConfigIsCorrect should add build options if it is using condi
|
||||
|
||||
exports[`ensureViteConfigIsCorrect should add new build options if some build options already exist 1`] = `
|
||||
"import dts from 'vite-plugin-dts';
|
||||
import { join } from 'path';
|
||||
import { joinPathFragments } from '@nx/devkit';
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
@ -242,7 +242,7 @@ import { defineConfig } from 'vite';
|
||||
],
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
],
|
||||
@ -276,13 +276,13 @@ exports[`ensureViteConfigIsCorrect should not do anything if project has everyth
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
import dts from 'vite-plugin-dts';
|
||||
import { join } from 'path';
|
||||
import { joinPathFragments } from '@nx/devkit';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
react(),
|
||||
@ -323,7 +323,7 @@ exports[`ensureViteConfigIsCorrect should not do anything if project has everyth
|
||||
|
||||
exports[`ensureViteConfigIsCorrect should update both test and build options - keep existing settings 1`] = `
|
||||
"import dts from 'vite-plugin-dts';
|
||||
import { join } from 'path';
|
||||
import { joinPathFragments } from '@nx/devkit';
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
@ -338,7 +338,7 @@ import { defineConfig } from 'vite';
|
||||
],
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
],
|
||||
|
||||
@ -519,7 +519,7 @@ export function createOrEditViteConfig(
|
||||
: options.includeLib
|
||||
? `dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),`
|
||||
: '';
|
||||
@ -527,7 +527,7 @@ export function createOrEditViteConfig(
|
||||
const dtsImportLine = onlyVitest
|
||||
? ''
|
||||
: options.includeLib
|
||||
? `import dts from 'vite-plugin-dts';\nimport { join } from 'path';`
|
||||
? `import dts from 'vite-plugin-dts';\nimport { joinPathFragments } from '@nx/devkit';`
|
||||
: '';
|
||||
|
||||
let viteConfigContent = '';
|
||||
|
||||
@ -6,7 +6,7 @@ import {
|
||||
readTargetOptions,
|
||||
} from '@nx/devkit';
|
||||
import { existsSync } from 'fs';
|
||||
import { join, relative } from 'path';
|
||||
import { relative } from 'path';
|
||||
import {
|
||||
BuildOptions,
|
||||
InlineConfig,
|
||||
@ -19,7 +19,6 @@ import { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';
|
||||
import { VitePreviewServerExecutorOptions } from '../executors/preview-server/schema';
|
||||
import replaceFiles from '../../plugins/rollup-replace-files.plugin';
|
||||
import { ViteBuildExecutorOptions } from '../executors/build/schema';
|
||||
import * as path from 'path';
|
||||
|
||||
/**
|
||||
* Returns the path to the vite config file or undefined when not found.
|
||||
@ -56,8 +55,8 @@ export function getViteServerProxyConfigPath(
|
||||
context.projectsConfigurations.projects[context.projectName].root;
|
||||
|
||||
const proxyConfigPath = nxProxyConfig
|
||||
? join(context.root, nxProxyConfig)
|
||||
: join(projectRoot, 'proxy.conf.json');
|
||||
? joinPathFragments(context.root, nxProxyConfig)
|
||||
: joinPathFragments(projectRoot, 'proxy.conf.json');
|
||||
|
||||
if (existsSync(proxyConfigPath)) {
|
||||
return proxyConfigPath;
|
||||
@ -78,7 +77,7 @@ export function getViteSharedConfig(
|
||||
const projectRoot =
|
||||
context.projectsConfigurations.projects[context.projectName].root;
|
||||
|
||||
const root = path.relative(
|
||||
const root = relative(
|
||||
context.cwd,
|
||||
joinPathFragments(context.root, projectRoot)
|
||||
);
|
||||
|
||||
@ -154,13 +154,13 @@ export const hasEverything = `
|
||||
import react from '@vitejs/plugin-react';
|
||||
import viteTsConfigPaths from 'vite-tsconfig-paths';
|
||||
import dts from 'vite-plugin-dts';
|
||||
import { join } from 'path';
|
||||
import { joinPathFragments } from '@nx/devkit';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
react(),
|
||||
@ -248,10 +248,10 @@ export const testOptionObject = {
|
||||
|
||||
export const dtsPlugin = `dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
|
||||
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),`;
|
||||
export const dtsImportLine = `import dts from 'vite-plugin-dts';\nimport { join } from 'path';`;
|
||||
export const dtsImportLine = `import dts from 'vite-plugin-dts';\nimport { joinPathFragments } from '@nx/devkit';`;
|
||||
|
||||
export const pluginOption = `
|
||||
plugins: [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user