Skip to content

Commit 04b25d9

Browse files
committed
Run tests in a browser
1 parent 6a6cdc6 commit 04b25d9

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

.airtap.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
providers:
2+
- airtap-manual
3+
4+
browsers:
5+
- name: manual

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "JSON parse with prototype poisoning protection",
55
"main": "index.js",
66
"scripts": {
7-
"test": "standard && tape test.js"
7+
"test": "standard && tape test.js && node ./test.browser-bootstrap.js test.js"
88
},
99
"repository": {
1010
"type": "git",
@@ -24,6 +24,9 @@
2424
},
2525
"homepage": "https://github.com/fastify/secure-json-parse#readme",
2626
"devDependencies": {
27+
"airtap": "^4.0.1",
28+
"airtap-manual": "^1.0.0",
29+
"puppeteer": "^5.5.0",
2730
"standard": "^16.0.0",
2831
"tape": "^5.1.1"
2932
}

test.browser-bootstrap.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { spawn } = require('child_process')
2+
const puppeteer = require('puppeteer')
3+
4+
function isOldNode () {
5+
const match = process.version.match(/^v(\d+)/)
6+
const v = Number(match[1])
7+
return v < 10
8+
}
9+
10+
function run () {
11+
// airtap requires node 10
12+
if (isOldNode()) return
13+
14+
const args = process.argv.slice(2)
15+
16+
const airtap = spawn('airtap', args, { stdio: ['inherit', 'inherit', 'pipe'] })
17+
airtap.on('close', (code) => process.exit(code))
18+
19+
let errBuffer = ''
20+
let foundUrl = false
21+
airtap.stderr.on('data', (data) => {
22+
process.stderr.write(data)
23+
24+
if (foundUrl) return
25+
26+
errBuffer += data.toString()
27+
const match = errBuffer.match(/https?:\/\/localhost:\d+\/airtap/)
28+
if (!match) return
29+
30+
const url = match[0]
31+
foundUrl = true
32+
puppeteer.launch().then(function (browser) {
33+
browser.newPage().then(function (page) {
34+
page.goto(url, {})
35+
})
36+
})
37+
})
38+
}
39+
40+
run()

0 commit comments

Comments
 (0)