Skip to content

Commit fe99ac1

Browse files
committed
Added test
1 parent 2d4cdc4 commit fe99ac1

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node:
3+
- lts/*
4+
services: xvfb

bench.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ function benchRead () {
3737
console.time('512mb read')
3838
st.read(0, 65536, function onread (err, buf) {
3939
if (err) throw err
40-
if (offset >= 512 * 1024 * 1024) return console.timeEnd('512mb read')
40+
if (offset >= 512 * 1024 * 1024) {
41+
console.timeEnd('512mb read')
42+
console.log('### EXIT')
43+
return
44+
}
4145
st.read(offset += buf.length, 65536, onread)
4246
})
4347
}

browser-runner.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const puppeteer = require('puppeteer')
2+
const budo = require('budo')
3+
const tapFinished = require('tap-finished')
4+
const { PassThrough, pipeline } = require('stream')
5+
6+
const args = process.argv.slice(2)
7+
8+
budo.cli(args, { live: false, watchGlob: '', stream: false }).on('connect', runTests)
9+
10+
async function runTests (ev) {
11+
const results = new PassThrough()
12+
let browser
13+
let page
14+
15+
try {
16+
browser = await puppeteer.launch()
17+
page = await browser.newPage()
18+
} catch (err) {
19+
console.error(err)
20+
shutdown(1)
21+
}
22+
23+
page.on('error', async err => {
24+
console.error(err)
25+
shutdown(1)
26+
})
27+
28+
page.on('pageerror', async err => {
29+
console.error(err)
30+
shutdown(1)
31+
})
32+
33+
page.on('console', msg => {
34+
msg = msg.text()
35+
if (msg.includes('### EXIT')) {
36+
shutdown()
37+
} else {
38+
results.push(`${msg}\n`)
39+
}
40+
})
41+
42+
pipeline(results, tapFinished(result => {
43+
shutdown(result.ok ? 0 : 1)
44+
}), () => {})
45+
46+
pipeline(results, process.stdout, () => {})
47+
48+
await page.goto(`http://localhost:${ev.port}`)
49+
50+
async function shutdown (code = 0) {
51+
if (browser) {
52+
await browser.close().catch(() => {})
53+
}
54+
55+
process.exit(code)
56+
}
57+
}

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
"random-access-storage": "^1.3.0"
99
},
1010
"devDependencies": {
11-
"standard": "^11.0.1"
11+
"budo": "^11.6.3",
12+
"puppeteer": "^3.0.2",
13+
"random-access-test": "github:random-access-storage/random-access-test",
14+
"standard": "^11.0.1",
15+
"tap-finished": "0.0.1",
16+
"tape": "^5.0.0"
1217
},
1318
"scripts": {
14-
"test": "standard"
19+
"test": "browserify ./test.js | tape-puppet --devtools",
20+
"posttest": "npm run lint",
21+
"lint": "standard"
1522
},
1623
"repository": {
1724
"type": "git",

test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const test = require('random-access-test')
2+
const racf = require('./')
3+
4+
const createStorage = (root) => (file, opts) => racf(`${root}/${file}`, opts)
5+
6+
const storage = createStorage('tests-' + Math.random())
7+
8+
test(function (name, options, callback) {
9+
callback(storage(name, options))
10+
}, {})

0 commit comments

Comments
 (0)