Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cli tests using browser-run #7

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions mutable-file-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function mutableStorage (options) {
if (!mounted && !loading) {
loading = doMount()
}
if(loading) {
if (loading) {
loading.then(() => {
this._open(req)
}, (err) => {
Expand All @@ -35,32 +35,32 @@ module.exports = function mutableStorage (options) {
req.callback()
},
write: function (req) {
file.write(req.offset, req.data, function(err, data) {
file.write(req.offset, req.data, function (err, data) {
req.callback(err, data)
})
},
read: function (req) {
file.read(req.offset, req.size, function(err, data) {
file.read(req.offset, req.size, function (err, data) {
req.callback(err, data)
})
},
del: function (req) {
file.del(req.offset, req.size, function(err, data) {
file.del(req.offset, req.size, function (err, data) {
req.callback(err, data)
})
},
stat: function (req) {
file.stat( function(err, data) {
file.stat(function (err, data) {
req.callback(err, data)
})
},
close: function (req) {
file.close( function(err, data) {
file.close(function (err, data) {
req.callback(err, data)
})
},
destroy: function (req) {
file.destroy( function(err, data) {
file.destroy(function (err, data) {
req.callback(err, data)
})
}
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Chooses the fastest random access backend based on the user's browser",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "standard --fix && browserify test.js | browser-run",
"build-test": "browserify test.js > test-bundle.js"
},
"repository": {
Expand All @@ -26,16 +26,19 @@
"homepage": "https://github.com/RangerMauve/random-access-web#readme",
"dependencies": {
"@sammacbeth/random-access-idb-mutable-file": "^0.1.1",
"random-access-chrome-file": "^1.1.2",
"random-access-chrome-file": "^1.1.4",
"random-access-idb": "^1.2.1",
"random-access-idb-mutable-file": "^0.3.0",
"random-access-memory": "^3.1.1",
"random-access-storage": "^1.3.0"
"random-access-storage": "^1.4.1",
"@DougAnderson444/random-access-idb": "github:DougAnderson444/random-access-idb"
RangerMauve marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"browserify": "^16.3.0",
"hyperdrive": "^9.14.5",
"browser-run": "^8.0.0",
"browserify": "^16.5.2",
"hyperdrive": "^10.18.0",
"random-access-test": "github:random-access-storage/random-access-test",
"tape": "^4.11.0"
"standard": "^14.3.4",
"tape": "^5.0.1"
}
}
19 changes: 11 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ test(
tape('Works with hyperdrive', (t) => {
const storage = RAW('tests-hyperdrive-' + Math.random())

const archive = hyperdrive(storage)

archive.writeFile('/example.txt', 'Hello World!', (err) => {
t.notOk(err, 'able to write')
archive.readFile('/example.txt', 'utf8', (err2, result) => {
t.notOk(err2, 'able to read')
t.equals(result, 'Hello World!')
t.end()
const drive = hyperdrive(storage)
drive.ready((err) => {
t.error(err, 'drive ready, no error')
t.ok(drive.writable, 'drive is writable')
drive.writeFile('/example.txt', 'Hello World!', (err1) => {
t.error(err1, 'able to write')
drive.readFile('/example.txt', 'utf8', (err2, result) => {
t.error(err2, 'able to read')
t.equals(result, 'Hello World!')
t.end()
})
})
})
})