Skip to content

Commit 1b0f2a3

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

File tree

3 files changed

+40
-1
lines changed

3 files changed

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

0 commit comments

Comments
 (0)