nx/e2e/web/src/file-server-legacy.test.ts
Colum Ferry 320d9f223f
fix(testing): application generators should accurately configure e2e projects (#27453)
- feat(devkit): add util for determining the e2e web server info
- feat(vite): add util for determining the e2e web server info
- feat(webpack): add util for determining the e2e web server info
- fix(webpack): allow port override
- fix(devkit): e2e web server info util should handle target defaults
- feat(webpack): export the e2e web server info utils
- fix(vite): rename util
- fix(devkit): util should determine the devTarget for cypress
- fix(react): improve accuracy of e2e project generation

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
The logic for finding the correct targets and web addresses to use when
setting up e2e projects is flawed and missing some key considerations.


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
The logic is accurate and usage is simplified across plugins 

Projects:
- [x] Angular
- [x] Expo
- [x] Next
- [x] Nuxt
- [x] Vue
- [x] Web
- [x] Remix
- [x] React
- [x] React Native


## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-08-27 10:00:43 -04:00

78 lines
1.7 KiB
TypeScript

import {
cleanupProject,
killPorts,
newProject,
promisifiedTreeKill,
runCLI,
runCommandUntil,
uniq,
} from '@nx/e2e/utils';
describe('file-server', () => {
beforeAll(() => {
newProject({ name: uniq('fileserver') });
});
afterAll(() => cleanupProject());
it('should setup and serve static files from app', async () => {
const ngAppName = uniq('ng-app');
const reactAppName = uniq('react-app');
runCLI(
`generate @nx/angular:app ${ngAppName} --no-interactive --e2eTestRunner=none`,
{
env: {
NX_ADD_PLUGINS: 'false',
},
}
);
runCLI(
`generate @nx/react:app ${reactAppName} --no-interactive --e2eTestRunner=none`,
{
env: {
NX_ADD_PLUGINS: 'false',
},
}
);
runCLI(
`generate @nx/web:static-config --buildTarget=${reactAppName}:build --targetName=custom-serve-static --no-interactive`,
{
env: {
NX_ADD_PLUGINS: 'false',
},
}
);
const port = 6200;
const ngServe = await runCommandUntil(
`serve-static ${ngAppName} --port=${port}`,
(output) => {
return output.indexOf(`localhost:${port}`) > -1;
}
);
try {
await promisifiedTreeKill(ngServe.pid, 'SIGKILL');
await killPorts(port);
} catch {
// ignore
}
const reactServe = await runCommandUntil(
`custom-serve-static ${reactAppName} --port=${port + 1}`,
(output) => {
return output.indexOf(`localhost:${port + 1}`) > -1;
}
);
try {
await promisifiedTreeKill(reactServe.pid, 'SIGKILL');
await killPorts(port + 1);
} catch {
// ignore
}
}, 300_000);
});