-
Notifications
You must be signed in to change notification settings - Fork 2
/
run-interactive-test-browser.js
43 lines (38 loc) · 1.2 KB
/
run-interactive-test-browser.js
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
import * as fs from 'fs/promises'
import url from 'url'
import puppeteer from 'puppeteer'
import runOsmServer from './tools/osm-server.js'
import runClientServer from './tools/client-server.js'
import build from './tools/build.js'
const dstDir='test-build/dist'
let clientServer,clientUrl
if (process.argv.includes('--client-server')) {
console.log(`running client server`)
clientServer=await runClientServer(dstDir)
clientUrl=clientServer.url
} else {
clientUrl=`${url.pathToFileURL(`${dstDir}/index.html`)}`
}
console.log(`running dummy osm server`)
const downloads=await readJson('downloads.json')
const demoNotes=await readJson('demo-notes.json')
const osmServer=await runOsmServer(clientUrl)
osmServer.setNotes(demoNotes)
osmServer.setLogin(true)
console.log(`bundling test build`)
await build(osmServer.config,'src',dstDir,'cache',downloads)
console.log(`running puppeteer`)
{
const browser=await puppeteer.launch({headless:false})
const page=await browser.newPage()
await page.goto(clientUrl)
browser.on('disconnected',()=>{
osmServer.close()
if (clientServer) clientServer.close()
})
}
async function readJson(downloadsFilename) {
return JSON.parse(
await fs.readFile(downloadsFilename,'utf-8')
)
}