diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..cf5aae4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,46 @@ +language: node_js +cache: npm +stages: + - check + - test + - cov + +node_js: + - '10' + +os: + - linux + - osx + - windows + +script: npx nyc -s npm run test:node -- --bail +after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov + +jobs: + include: + - stage: check + script: + - npx aegir commitlint --travis + - npx aegir dep-check + - npm run lint + + - stage: test + name: chrome + addons: + chrome: stable + script: npx aegir test -t browser + + - stage: test + name: webworker + addons: + chrome: stable + script: npx aegir test -t webworker + + - stage: test + name: firefox + addons: + firefox: latest + script: npx aegir test -t browser -- --browsers FirefoxHeadless + +notifications: + email: false diff --git a/README.md b/README.md index 7eb2f5b..e0e52da 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) -[![Build Status](https://ci.ipfs.team/buildStatus/icon?job=ipfs/js-ipfs-mfs/master)](https://ci.ipfs.team/job/ipfs/job/js-ipfs-mfs/job/master/) +[![Build Status](https://flat.badgen.net/travis/ipfs/js-ipfs-mfs)](https://travis-ci.com/ipfs/js-ipfs-mfs) [![Code Coverage](https://codecov.io/gh/ipfs/js-ipfs-mfs/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-ipfs-mfs) [![Dependency Status](https://david-dm.org/ipfs/js-ipfs-mfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-mfs) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile deleted file mode 100644 index a7da2e5..0000000 --- a/ci/Jenkinsfile +++ /dev/null @@ -1,2 +0,0 @@ -// Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories. -javascript() diff --git a/package.json b/package.json index cbcc408..953f9fe 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,8 @@ "ipld-in-memory": "^2.0.0", "multihashes": "~0.4.14", "pull-buffer-stream": "^1.0.1", - "pull-traverse": "^1.0.3" + "pull-traverse": "^1.0.3", + "temp-write": "^3.4.0" }, "dependencies": { "async": "^2.6.1", diff --git a/test/fixtures/large-file.jpg b/test/fixtures/large-file.jpg deleted file mode 100644 index 04e1c07..0000000 Binary files a/test/fixtures/large-file.jpg and /dev/null differ diff --git a/test/fixtures/small-file.txt b/test/fixtures/small-file.txt deleted file mode 100644 index cd08755..0000000 --- a/test/fixtures/small-file.txt +++ /dev/null @@ -1 +0,0 @@ -Hello world! diff --git a/test/helpers/random-bytes.js b/test/helpers/random-bytes.js new file mode 100644 index 0000000..7ed4191 --- /dev/null +++ b/test/helpers/random-bytes.js @@ -0,0 +1,21 @@ +'use strict' + +const crypto = require('crypto') +const MAX_BYTES = 65536 + +// One day this will be merged: https://github.com/crypto-browserify/randombytes/pull/16 +module.exports = function randomBytes (num) { + const bytes = Buffer.allocUnsafe(num) + + for (let offset = 0; offset < num; offset += MAX_BYTES) { + let size = MAX_BYTES + + if ((offset + size) > num) { + size = num - offset + } + + crypto.randomFillSync(bytes, offset, size) + } + + return bytes +} diff --git a/test/read.spec.js b/test/read.spec.js index 64fce9c..3f1af26 100644 --- a/test/read.spec.js +++ b/test/read.spec.js @@ -4,8 +4,6 @@ const chai = require('chai') chai.use(require('dirty-chai')) const expect = chai.expect -const path = require('path') -const loadFixture = require('aegir/fixtures') const bufferStream = require('pull-buffer-stream') const pull = require('pull-stream/pull') const collect = require('pull-stream/sinks/collect') @@ -13,10 +11,11 @@ const { createMfs, createShardedDirectory } = require('./helpers') +const randomBytes = require('./helpers/random-bytes') describe('read', () => { let mfs - let smallFile = loadFixture(path.join('test', 'fixtures', 'small-file.txt')) + let smallFile = randomBytes(13) before(async () => { mfs = await createMfs() diff --git a/test/stat.spec.js b/test/stat.spec.js index 805ac08..b9782af 100644 --- a/test/stat.spec.js +++ b/test/stat.spec.js @@ -4,8 +4,7 @@ const chai = require('chai') chai.use(require('dirty-chai')) const expect = chai.expect -const path = require('path') -const loadFixture = require('aegir/fixtures') +const randomBytes = require('./helpers/random-bytes') const { createMfs, @@ -16,8 +15,8 @@ const { describe('stat', () => { let mfs - let smallFile = loadFixture(path.join('test', 'fixtures', 'small-file.txt')) - let largeFile = loadFixture(path.join('test', 'fixtures', 'large-file.jpg')) + let smallFile = randomBytes(13) + let largeFile = randomBytes(490668) before(async () => { mfs = await createMfs() diff --git a/test/write.spec.js b/test/write.spec.js index 41f44a9..03e862c 100644 --- a/test/write.spec.js +++ b/test/write.spec.js @@ -4,12 +4,12 @@ const chai = require('chai') chai.use(require('dirty-chai')) const expect = chai.expect -const path = require('path') -const loadFixture = require('aegir/fixtures') const isNode = require('detect-node') const values = require('pull-stream/sources/values') const bufferStream = require('pull-buffer-stream') const multihash = require('multihashes') +const randomBytes = require('./helpers/random-bytes') +const util = require('util') const { collectLeafCids, createMfs, @@ -19,16 +19,17 @@ const { } = require('./helpers') const CID = require('cids') -let fs +let fs, tempWrite if (isNode) { fs = require('fs') + tempWrite = require('temp-write') } describe('write', () => { let mfs - let smallFile = loadFixture(path.join('test', 'fixtures', 'small-file.txt')) - let largeFile = loadFixture(path.join('test', 'fixtures', 'large-file.jpg')) + let smallFile = randomBytes(13) + let largeFile = randomBytes(490668) const runTest = (fn) => { let i = 0 @@ -148,7 +149,8 @@ describe('write', () => { } const filePath = `/small-file-${Math.random()}.txt` - const pathToFile = path.resolve(path.join(__dirname, 'fixtures', 'small-file.txt')) + const pathToFile = await tempWrite(smallFile) + const fsStats = await util.promisify(fs.stat)(pathToFile) await mfs.write(filePath, pathToFile, { create: true @@ -156,7 +158,7 @@ describe('write', () => { const stats = await mfs.stat(filePath) - expect(stats.size).to.equal(smallFile.length) + expect(stats.size).to.equal(fsStats.size) }) it('writes part of a small file using a path (Node only)', async function () { @@ -165,7 +167,7 @@ describe('write', () => { } const filePath = `/small-file-${Math.random()}.txt` - const pathToFile = path.resolve(path.join(__dirname, 'fixtures', 'small-file.txt')) + const pathToFile = await tempWrite(smallFile) await mfs.write(filePath, pathToFile, { create: true, @@ -183,7 +185,7 @@ describe('write', () => { } const filePath = `/small-file-${Math.random()}.txt` - const pathToFile = path.resolve(path.join(__dirname, 'fixtures', 'small-file.txt')) + const pathToFile = await tempWrite(smallFile) const stream = fs.createReadStream(pathToFile) await mfs.write(filePath, stream, {