forked from geolonia/normalize-japanese-addresses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.test.ts
58 lines (51 loc) · 1.62 KB
/
browser.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { before, describe, test } from 'node:test'
import assert from 'node:assert'
import puppeteer from 'puppeteer'
import fs from 'node:fs/promises'
import path from 'node:path'
const runTest = (type: 'esm' | 'umd') => {
return async () => {
const browser = await puppeteer.launch({
args: [
'--disable-web-security', // for loading files from file://
],
})
try {
const page = await browser.newPage()
await page.goto(
`file://${path.join(import.meta.dirname, `browser/index-${type}.html`)}`,
)
await Promise.race([
page.waitForSelector('#result', { timeout: 20_000 }),
page.waitForSelector('#error', { timeout: 20_000 }),
])
const errorElem = await page.$$('#error')
if (errorElem.length > 0) {
const errorValue = await page.$eval('#error', (el) => el.textContent)
assert.strictEqual(
errorElem.length,
0,
`#error should not exist, instead we have: ${errorValue}`,
)
}
const result = await page.$eval('#result', (el) => el.textContent)
assert.strictEqual(result, 'OK')
} finally {
await browser.close()
}
}
}
describe(`browser`, { timeout: 60_000 }, () => {
before(async () => {
await fs.copyFile(
path.join(import.meta.dirname, '../../dist/main-esm.mjs'),
path.join(import.meta.dirname, 'browser/main-esm.mjs'),
)
await fs.copyFile(
path.join(import.meta.dirname, '../../dist/main-umd.cjs'),
path.join(import.meta.dirname, 'browser/main-umd.cjs'),
)
})
test(`esm`, runTest('esm'))
test(`umd`, runTest('umd'))
})