Skip to content

test: use random e2e test ports #23541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Dev Server Builder', () => {
expect(output.success).toBe(true);

// When webpack-dev-server doesn't have `contentBase: false`, this will serve the repo README.
const response = await fetch('http://localhost:4200/README.md', {
const response = await fetch(`http://localhost:${output.port}/README.md`, {
headers: {
'Accept': 'text/html',
},
Expand Down
10 changes: 9 additions & 1 deletion tests/legacy-cli/e2e/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,17 @@ export function useCIDefaults(projectName = 'test-project') {
const appTargets = project.targets || project.architect;
appTargets.build.options.progress = false;
appTargets.test.options.progress = false;
// Disable auto-updating webdriver in e2e.
if (appTargets.e2e) {
// Disable auto-updating webdriver in e2e.
appTargets.e2e.options.webdriverUpdate = false;
// Use a random port in e2e.
appTargets.e2e.options.port = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alan-agius4 do you think this would also be the ideal place to set appTargets.serve.options.port? I just had a test running ng serve fail in another PR due to 4200 being in use...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note there's various ng serve --port=0 throughout the tests already but a few are missing such as

rebuild-deps-type-check.ts
rebuild-types.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added another commit but feel free to only merge the first if you'd like.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we should.

}

if (appTargets.serve) {
// Use a random port in serve.
appTargets.serve.options ??= {};
appTargets.serve.options.port = 0;
}
});
}
Expand Down