fix(react): ensure playwright configuration is using correct port in app gen (#21941)
This commit is contained in:
parent
21e764833e
commit
c9c56a2cfd
@ -29,6 +29,44 @@ describe('React Applications', () => {
|
|||||||
|
|
||||||
afterAll(() => cleanupProject());
|
afterAll(() => cleanupProject());
|
||||||
|
|
||||||
|
it('should be able to use Vite to build and test apps', async () => {
|
||||||
|
const appName = uniq('app');
|
||||||
|
const libName = uniq('lib');
|
||||||
|
|
||||||
|
runCLI(
|
||||||
|
`generate @nx/react:app ${appName} --bundler=vite --no-interactive --skipFormat`
|
||||||
|
);
|
||||||
|
runCLI(
|
||||||
|
`generate @nx/react:lib ${libName} --bundler=none --no-interactive --unit-test-runner=vitest --skipFormat`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Library generated with Vite
|
||||||
|
checkFilesExist(`libs/${libName}/vite.config.ts`);
|
||||||
|
|
||||||
|
const mainPath = `apps/${appName}/src/main.tsx`;
|
||||||
|
updateFile(
|
||||||
|
mainPath,
|
||||||
|
`
|
||||||
|
import '@${proj}/${libName}';
|
||||||
|
${readFile(mainPath)}
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
runCLI(`build ${appName}`);
|
||||||
|
|
||||||
|
checkFilesExist(`dist/apps/${appName}/index.html`);
|
||||||
|
|
||||||
|
if (runE2ETests()) {
|
||||||
|
const e2eResults = runCLI(`e2e ${appName}-e2e`, {
|
||||||
|
env: {
|
||||||
|
DEBUG: 'cypress:server:*',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(e2eResults).toContain('All specs passed!');
|
||||||
|
expect(await killPorts()).toBeTruthy();
|
||||||
|
}
|
||||||
|
}, 250_000);
|
||||||
|
|
||||||
it('should be able to generate a react app + lib (with CSR and SSR)', async () => {
|
it('should be able to generate a react app + lib (with CSR and SSR)', async () => {
|
||||||
const appName = uniq('app');
|
const appName = uniq('app');
|
||||||
const libName = uniq('lib');
|
const libName = uniq('lib');
|
||||||
@ -124,44 +162,6 @@ describe('React Applications', () => {
|
|||||||
});
|
});
|
||||||
}, 500000);
|
}, 500000);
|
||||||
|
|
||||||
it('should be able to use Vite to build and test apps', async () => {
|
|
||||||
const appName = uniq('app');
|
|
||||||
const libName = uniq('lib');
|
|
||||||
|
|
||||||
runCLI(
|
|
||||||
`generate @nx/react:app ${appName} --bundler=vite --no-interactive --skipFormat`
|
|
||||||
);
|
|
||||||
runCLI(
|
|
||||||
`generate @nx/react:lib ${libName} --bundler=none --no-interactive --unit-test-runner=vitest --skipFormat`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Library generated with Vite
|
|
||||||
checkFilesExist(`libs/${libName}/vite.config.ts`);
|
|
||||||
|
|
||||||
const mainPath = `apps/${appName}/src/main.tsx`;
|
|
||||||
updateFile(
|
|
||||||
mainPath,
|
|
||||||
`
|
|
||||||
import '@${proj}/${libName}';
|
|
||||||
${readFile(mainPath)}
|
|
||||||
`
|
|
||||||
);
|
|
||||||
|
|
||||||
runCLI(`build ${appName}`);
|
|
||||||
|
|
||||||
checkFilesExist(`dist/apps/${appName}/index.html`);
|
|
||||||
|
|
||||||
if (runE2ETests()) {
|
|
||||||
const e2eResults = runCLI(`e2e ${appName}-e2e`, {
|
|
||||||
env: {
|
|
||||||
DEBUG: 'cypress:server:*',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(e2eResults).toContain('All specs passed!');
|
|
||||||
expect(await killPorts()).toBeTruthy();
|
|
||||||
}
|
|
||||||
}, 250_000);
|
|
||||||
|
|
||||||
it('should generate app with routing', async () => {
|
it('should generate app with routing', async () => {
|
||||||
const appName = uniq('app');
|
const appName = uniq('app');
|
||||||
|
|
||||||
|
|||||||
@ -49,7 +49,7 @@ export async function addE2e(
|
|||||||
bundler: options.bundler === 'rspack' ? 'webpack' : options.bundler,
|
bundler: options.bundler === 'rspack' ? 'webpack' : options.bundler,
|
||||||
skipFormat: true,
|
skipFormat: true,
|
||||||
devServerTarget: `${options.projectName}:serve`,
|
devServerTarget: `${options.projectName}:serve`,
|
||||||
baseUrl: 'http://localhost:4200',
|
baseUrl: `http://localhost:${options.devServerPort ?? 4200}`,
|
||||||
jsx: true,
|
jsx: true,
|
||||||
rootProject: options.rootProject,
|
rootProject: options.rootProject,
|
||||||
webServerCommands: hasNxBuildPlugin
|
webServerCommands: hasNxBuildPlugin
|
||||||
@ -85,7 +85,7 @@ export async function addE2e(
|
|||||||
webServerCommand: `${getPackageManagerCommand().exec} nx serve ${
|
webServerCommand: `${getPackageManagerCommand().exec} nx serve ${
|
||||||
options.name
|
options.name
|
||||||
}`,
|
}`,
|
||||||
webServerAddress: 'http://localhost:4200',
|
webServerAddress: `http://localhost:${options.devServerPort ?? 4200}`,
|
||||||
rootProject: options.rootProject,
|
rootProject: options.rootProject,
|
||||||
addPlugin: options.addPlugin,
|
addPlugin: options.addPlugin,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,11 +11,13 @@ export function updateModuleFederationE2eProject(
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
let projectConfig = readProjectConfiguration(host, options.e2eProjectName);
|
let projectConfig = readProjectConfiguration(host, options.e2eProjectName);
|
||||||
projectConfig.targets.e2e.options = {
|
if (projectConfig.targets.e2e.executor !== '@nx/playwright:playwright') {
|
||||||
...projectConfig.targets.e2e.options,
|
projectConfig.targets.e2e.options = {
|
||||||
baseUrl: `http://localhost:${options.devServerPort}`,
|
...projectConfig.targets.e2e.options,
|
||||||
};
|
baseUrl: `http://localhost:${options.devServerPort}`,
|
||||||
updateProjectConfiguration(host, options.e2eProjectName, projectConfig);
|
};
|
||||||
|
updateProjectConfiguration(host, options.e2eProjectName, projectConfig);
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user