Skip to content

Commit ed0af90

Browse files
authored
test: use available port for e2e tests (#2036)
1 parent 5605e05 commit ed0af90

38 files changed

+128
-124
lines changed

e2e/components/datetime-format.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
55
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/components/datetime-format.html`
6+
url(`/examples/${pattern}/components/datetime-format.html`)
77
)
88
})
99

1010
test('rendering', async () => {
11+
console.log(new Date())
1112
expect(await getText(page, '#app p.p1')).toMatch(
1213
/([1-9]|1[0-2])\/([1-9]|[12]\d|3[01])\/([12]\d{3})/
1314
)

e2e/components/number-format.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/components/number-format.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/components/number-format.html`))
86
})
97

108
test('rendering', async () => {

e2e/components/translation.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/components/translation.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/components/translation.html`))
86
})
97

108
test('rendering', async () => {

e2e/datetime.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getText } from './helper'
1+
import { getText, url } from './helper'
22
;['composition', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(`http://localhost:8080/examples/${pattern}/datetime.html`)
5+
await page.goto(url(`/examples/${pattern}/datetime.html`))
66
})
77

88
test('initial rendering', async () => {

e2e/directive/basic.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/directive/basic.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/directive/basic.html`))
86
})
97

108
test('initial rendering', async () => {

e2e/directive/object.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/directive/object.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/directive/object.html`))
86
})
97

108
test('rendering', async () => {

e2e/directive/plural.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/directive/plural.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/directive/plural.html`))
86
})
97

108
test('rendering', async () => {

e2e/directive/preserve.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText, sleep } from '../helper'
1+
import { getText, sleep, url } from '../helper'
22
;['composition', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/directive/preserve.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/directive/preserve.html`))
86
})
97

108
test('initial rendering', async () => {

e2e/fallback/basic.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
const warnings: string[] = []
@@ -11,9 +11,7 @@ import { getText } from '../helper'
1111
}
1212
}
1313
})
14-
await page.goto(
15-
`http://localhost:8080/examples/${pattern}/fallback/basic.html`
16-
)
14+
await page.goto(url(`/examples/${pattern}/fallback/basic.html`))
1715
})
1816

1917
test('warning', () => {

e2e/fallback/component.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/fallback/component.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/fallback/component.html`))
86
})
97

108
test('initial rendering', async () => {

e2e/fallback/default-format.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
const warnings: string[] = []
@@ -8,9 +8,7 @@ import { getText } from '../helper'
88
warnings.push(msg.text())
99
}
1010
})
11-
await page.goto(
12-
`http://localhost:8080/examples/${pattern}/fallback/default-format.html`
13-
)
11+
await page.goto(url(`/examples/${pattern}/fallback/default-format.html`))
1412
})
1513

1614
test('warning', () => {

e2e/fallback/format.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
const warnings: string[] = []
@@ -11,9 +11,7 @@ import { getText } from '../helper'
1111
}
1212
}
1313
})
14-
await page.goto(
15-
`http://localhost:8080/examples/${pattern}/fallback/format.html`
16-
)
14+
await page.goto(url(`/examples/${pattern}/fallback/format.html`))
1715
})
1816

1917
test('warning', () => {

e2e/fallback/option.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
const warnings: string[] = []
@@ -11,9 +11,7 @@ import { getText } from '../helper'
1111
}
1212
}
1313
})
14-
await page.goto(
15-
`http://localhost:8080/examples/${pattern}/fallback/option.html`
16-
)
14+
await page.goto(url(`/examples/${pattern}/fallback/option.html`))
1715
})
1816

1917
test('warning', () => {

e2e/fallback/suppress.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
const warnings: string[] = []
@@ -11,9 +11,7 @@ import { getText } from '../helper'
1111
}
1212
}
1313
})
14-
await page.goto(
15-
`http://localhost:8080/examples/${pattern}/fallback/suppress.html`
16-
)
14+
await page.goto(url(`/examples/${pattern}/fallback/suppress.html`))
1715
})
1816

1917
test('warning', () => {

e2e/formatting/linked.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/formatting/linked.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/formatting/linked.html`))
86
})
97

108
test('initial rendering', async () => {

e2e/formatting/list.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/formatting/list.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/formatting/list.html`))
86
})
97

108
test('initial rendering', async () => {

e2e/formatting/literal.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/formatting/literal.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/formatting/literal.html`))
86
})
97

108
test('initial rendering', async () => {

e2e/formatting/named.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/formatting/named.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/formatting/named.html`))
86
})
97

108
test('initial rendering', async () => {

e2e/functions/linked.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/functions/linked.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/functions/linked.html`))
86
})
97

108
test('initial rendering', async () => {

e2e/functions/list.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/functions/list.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/functions/list.html`))
86
})
97

108
test('initial rendering', async () => {

e2e/functions/named.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/functions/named.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/functions/named.html`))
86
})
97

108
test('initial rendering', async () => {

e2e/functions/plural.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
beforeAll(async () => {
5-
await page.goto(
6-
`http://localhost:8080/examples/${pattern}/functions/plural.html`
7-
)
5+
await page.goto(url(`/examples/${pattern}/functions/plural.html`))
86
})
97

108
test('initial rendering', async () => {

e2e/helper.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { JSDOM } from 'jsdom'
2+
import { useTestContext } from '../scripts/test-utils'
23

34
import type { Page } from 'playwright-core'
45

@@ -73,3 +74,17 @@ export function assertLocaleHeadWithDom(dom: Document, headSelector: string) {
7374
}
7475
}
7576
}
77+
78+
export function url(path: string) {
79+
const ctx = useTestContext()
80+
81+
if (!ctx.url) {
82+
throw new Error('url is not available (is server option enabled?)')
83+
}
84+
85+
if (path.startsWith(ctx.url)) {
86+
return path
87+
}
88+
89+
return ctx.url + path
90+
}

e2e/hotfix.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getText } from './helper'
1+
import { getText, url } from './helper'
22

33
describe('CVE-2024-52809', () => {
44
beforeAll(async () => {
5-
await page.goto(`http://localhost:8080/e2e/hotfix/CVE-2024-52809.html`)
5+
await page.goto(url(`/e2e/hotfix/CVE-2024-52809.html`))
66
})
77

88
test('fix', async () => {

e2e/missing/handler.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
const warnings: string[] = []
@@ -11,9 +11,7 @@ import { getText } from '../helper'
1111
}
1212
}
1313
})
14-
await page.goto(
15-
`http://localhost:8080/examples/${pattern}/missing/handler.html`
16-
)
14+
await page.goto(url(`/examples/${pattern}/missing/handler.html`))
1715
})
1816

1917
test('warning', () => {

e2e/missing/option.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
const warnings: string[] = []
@@ -11,9 +11,7 @@ import { getText } from '../helper'
1111
}
1212
}
1313
})
14-
await page.goto(
15-
`http://localhost:8080/examples/${pattern}/missing/option.html`
16-
)
14+
await page.goto(url(`/examples/${pattern}/missing/option.html`))
1715
})
1816

1917
test('warning', () => {

e2e/missing/suppress.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getText } from '../helper'
1+
import { getText, url } from '../helper'
22
;['composition', 'petite', 'legacy'].forEach(pattern => {
33
describe(`${pattern}`, () => {
44
const warnings: string[] = []
@@ -11,9 +11,7 @@ import { getText } from '../helper'
1111
}
1212
}
1313
})
14-
await page.goto(
15-
`http://localhost:8080/examples/${pattern}/missing/suppress.html`
16-
)
14+
await page.goto(url(`/examples/${pattern}/missing/suppress.html`))
1715
})
1816

1917
test('warning', () => {

0 commit comments

Comments
 (0)