Skip to content

Commit 10fb48b

Browse files
committed
Added unit tests
1 parent c9d2c06 commit 10fb48b

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ typings/
6161
.next
6262

6363
package-lock.json
64+
test-bundle.js

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function mutableStorage (options) {
5555
if (!mounted) {
5656
loading = doMount()
5757
}
58-
if(loading) {
58+
if (loading) {
5959
loading.then(() => {
6060
this._open(req)
6161
}, (err) => {
@@ -72,7 +72,7 @@ function mutableStorage (options) {
7272
if (!mounted) {
7373
loading = doMount()
7474
}
75-
if(loading) {
75+
if (loading) {
7676
loading.then(() => {
7777
this._openReadonly(req)
7878
}, (err) => {

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Chooses the fastest random access backend based on the user's browser",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build-test": "browserify test.js > test-bundle.js"
89
},
910
"repository": {
1011
"type": "git",
@@ -24,10 +25,17 @@
2425
},
2526
"homepage": "https://github.com/RangerMauve/random-access-web#readme",
2627
"dependencies": {
27-
"random-access-idb-mutable-file": "^0.3.0",
28+
"@sammacbeth/random-access-idb-mutable-file": "^0.1.1",
2829
"random-access-chrome-file": "^1.1.2",
2930
"random-access-idb": "^1.2.1",
31+
"random-access-idb-mutable-file": "^0.3.0",
3032
"random-access-memory": "^3.1.1",
3133
"random-access-storage": "^1.3.0"
34+
},
35+
"devDependencies": {
36+
"browserify": "^16.3.0",
37+
"hyperdrive": "^9.14.5",
38+
"random-access-test": "github:random-access-storage/random-access-test",
39+
"tape": "^4.11.0"
3240
}
3341
}

test.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<title>random-access-web tests</title>
2+
<h1>Open dev tools for results</h1>
3+
<script src="test-bundle.js"></script>

test.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var test = require('random-access-test')
2+
const RAW = require('./')
3+
const tape = require('tape')
4+
const hyperdrive = require('hyperdrive')
5+
6+
const storage = RAW('tests-' + Math.random())
7+
8+
test(
9+
function (name, options, callback) {
10+
callback(storage(name, options))
11+
},
12+
{
13+
// Choose which test to exercise
14+
reopen: true, // tests that re-open same file (not applicable to ram)
15+
content: false, // tests that populates with options.content
16+
del: true, // tests that excersise advisory del API
17+
writable: true, // tests that excersise open with `options.writable`
18+
size: true, // tests that excersise open with `options.size`
19+
truncate: false // tests that excersise open with `options.truncate`
20+
}
21+
)
22+
23+
tape('Works with hyperdrive', (t) => {
24+
const storage = RAW('tests-hyperdrive-' + Math.random())
25+
26+
const archive = hyperdrive(storage)
27+
28+
archive.writeFile('/example.txt', 'Hello World!', (err) => {
29+
t.notOk(err, 'able to write')
30+
archive.readFile('/example.txt', 'utf8', (err2, result) => {
31+
t.notOk(err2, 'able to read')
32+
t.equals(result, 'Hello World!')
33+
t.end()
34+
})
35+
})
36+
})

0 commit comments

Comments
 (0)