Skip to content

Commit 6832c36

Browse files
Mariovidorochdev
authored andcommitted
[test-optimization] [SDTEST-2267] Remove getPort from Test Optimization tests (#6064)
1 parent 24ad524 commit 6832c36

File tree

7 files changed

+37
-45
lines changed

7 files changed

+37
-45
lines changed

integration-tests/automatic-log-submission.spec.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const { exec, execSync } = require('child_process')
44

55
const { assert } = require('chai')
6-
const getPort = require('get-port')
76

87
const {
98
createSandbox,
@@ -31,8 +30,9 @@ describe('test visibility automatic log submission', () => {
3130
// Install chromium (configured in integration-tests/playwright.config.js)
3231
// *Be advised*: this means that we'll only be using chromium for this test suite
3332
execSync('npx playwright install chromium', { cwd, env: restOfEnv, stdio: 'inherit' })
34-
webAppPort = await getPort()
35-
webAppServer.listen(webAppPort)
33+
webAppServer.listen(0, () => {
34+
webAppPort = webAppServer.address().port
35+
})
3636
})
3737

3838
after(async () => {
@@ -41,8 +41,7 @@ describe('test visibility automatic log submission', () => {
4141
})
4242

4343
beforeEach(async function () {
44-
const port = await getPort()
45-
receiver = await new FakeCiVisIntake(port).start()
44+
receiver = await new FakeCiVisIntake().start()
4645
})
4746

4847
afterEach(async () => {

integration-tests/cucumber/cucumber.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const { exec, execSync } = require('child_process')
44

5-
const getPort = require('get-port')
65
const { assert } = require('chai')
76
const fs = require('fs')
87
const path = require('path')
@@ -95,8 +94,7 @@ versions.forEach(version => {
9594
})
9695

9796
beforeEach(async function () {
98-
const port = await getPort()
99-
receiver = await new FakeCiVisIntake(port).start()
97+
receiver = await new FakeCiVisIntake().start()
10098
})
10199

102100
afterEach(async () => {

integration-tests/cypress/cypress.spec.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const { exec, execSync } = require('child_process')
55
const path = require('path')
66
const fs = require('fs')
77

8-
const getPort = require('get-port')
98
const { assert } = require('chai')
109

1110
const {
@@ -114,7 +113,7 @@ moduleTypes.forEach(({
114113

115114
this.retries(2)
116115
this.timeout(60000)
117-
let sandbox, cwd, receiver, childProcess, webAppPort, secondWebAppServer
116+
let sandbox, cwd, receiver, childProcess, webAppPort, secondWebAppServer, secondWebAppPort
118117

119118
if (type === 'commonJS') {
120119
testCommand = testCommand(version)
@@ -124,8 +123,24 @@ moduleTypes.forEach(({
124123
// cypress-fail-fast is required as an incompatible plugin
125124
sandbox = await createSandbox([`cypress@${version}`, 'cypress-fail-fast@7.1.0'], true)
126125
cwd = sandbox.folder
127-
webAppPort = await getPort()
128-
webAppServer.listen(webAppPort)
126+
webAppServer.listen(0, 'localhost', () => {
127+
webAppPort = webAppServer.address().port
128+
})
129+
if (version === 'latest') {
130+
secondWebAppServer = http.createServer((req, res) => {
131+
res.setHeader('Content-Type', 'text/html')
132+
res.writeHead(200)
133+
res.end(`
134+
<!DOCTYPE html>
135+
<html>
136+
<div class="hella-world">Hella World</div>
137+
</html>
138+
`)
139+
})
140+
secondWebAppServer.listen(0, 'localhost', () => {
141+
secondWebAppPort = secondWebAppServer.address().port
142+
})
143+
}
129144
})
130145

131146
after(async () => {
@@ -1732,21 +1747,6 @@ moduleTypes.forEach(({
17321747
...restEnvVars
17331748
} = getCiVisEvpProxyConfig(receiver.port)
17341749

1735-
const secondWebAppPort = await getPort()
1736-
1737-
secondWebAppServer = http.createServer((req, res) => {
1738-
res.setHeader('Content-Type', 'text/html')
1739-
res.writeHead(200)
1740-
res.end(`
1741-
<!DOCTYPE html>
1742-
<html>
1743-
<div class="hella-world">Hella World</div>
1744-
</html>
1745-
`)
1746-
})
1747-
1748-
secondWebAppServer.listen(secondWebAppPort)
1749-
17501750
const specToRun = 'cypress/e2e/multi-origin.js'
17511751

17521752
childProcess = exec(

integration-tests/playwright/playwright.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const satisfies = require('semifies')
55
const path = require('path')
66
const fs = require('fs')
77

8-
const getPort = require('get-port')
98
const { assert } = require('chai')
109

1110
const {
@@ -86,10 +85,12 @@ versions.forEach((version) => {
8685
// Install chromium (configured in integration-tests/playwright.config.js)
8786
// *Be advised*: this means that we'll only be using chromium for this test suite
8887
execSync('npx playwright install chromium', { cwd, env: restOfEnv, stdio: 'inherit' })
89-
webAppPort = await getPort()
90-
webAppServer.listen(webAppPort)
91-
webPortWithRedirect = await getPort()
92-
webAppServerWithRedirect.listen(webPortWithRedirect)
88+
webAppServer.listen(0, () => {
89+
webAppPort = webAppServer.address().port
90+
})
91+
webAppServerWithRedirect.listen(0, () => {
92+
webPortWithRedirect = webAppServerWithRedirect.address().port
93+
})
9394
})
9495

9596
after(async () => {
@@ -99,8 +100,7 @@ versions.forEach((version) => {
99100
})
100101

101102
beforeEach(async function () {
102-
const port = await getPort()
103-
receiver = await new FakeCiVisIntake(port).start()
103+
receiver = await new FakeCiVisIntake().start()
104104
})
105105

106106
afterEach(async () => {

integration-tests/selenium/selenium.spec.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const { exec } = require('child_process')
44

55
const { assert } = require('chai')
6-
const getPort = require('get-port')
76

87
const {
98
createSandbox,
@@ -41,8 +40,9 @@ versionRange.forEach(version => {
4140
])
4241
cwd = sandbox.folder
4342

44-
webAppPort = await getPort()
45-
webAppServer.listen(webAppPort)
43+
webAppServer.listen(0, () => {
44+
webAppPort = webAppServer.address().port
45+
})
4646
})
4747

4848
after(async function () {
@@ -51,8 +51,7 @@ versionRange.forEach(version => {
5151
})
5252

5353
beforeEach(async function () {
54-
const port = await getPort()
55-
receiver = await new FakeCiVisIntake(port).start()
54+
receiver = await new FakeCiVisIntake().start()
5655
})
5756

5857
afterEach(async () => {

integration-tests/test-api-manual.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const { exec } = require('child_process')
44

5-
const getPort = require('get-port')
65
const { assert } = require('chai')
76

87
const {
@@ -27,8 +26,7 @@ describe('test-api-manual', () => {
2726
})
2827

2928
beforeEach(async function () {
30-
const port = await getPort()
31-
receiver = await new FakeCiVisIntake(port).start()
29+
receiver = await new FakeCiVisIntake().start()
3230
})
3331

3432
afterEach(async () => {

integration-tests/test-optimization-startup.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const { exec } = require('child_process')
44

5-
const getPort = require('get-port')
65
const { assert } = require('chai')
76

87
const { createSandbox } = require('./helpers')
@@ -24,8 +23,7 @@ describe('test optimization startup', () => {
2423

2524
beforeEach(async function () {
2625
processOutput = ''
27-
const port = await getPort()
28-
receiver = await new FakeCiVisIntake(port).start()
26+
receiver = await new FakeCiVisIntake().start()
2927
})
3028

3129
afterEach(async () => {

0 commit comments

Comments
 (0)