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