Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

feat: add tests for add data using File DOM api #461

Merged
merged 6 commits into from
May 16, 2019
Merged
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
8 changes: 5 additions & 3 deletions SPEC/FILES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ Where `data` may be:
- a [`Buffer instance`][b]
- a [`Readable Stream`][rs]
- a [`Pull Stream`][ps]
- a [`File`][file]
- an array of objects, each of the form:
```JavaScript
{
path: '/tmp/myfile.txt', // The file path
content: <data> // A Buffer, Readable Stream or Pull Stream with the contents of the file
content: <data> // A Buffer, Readable Stream, Pull Stream or File with the contents of the file
}
```
If no `content` is passed, then the path is treated as an empty directory
Expand Down Expand Up @@ -137,7 +138,7 @@ Returns a Readable Stream of class Duplex, where objects can be written of the f
```js
{
path: '/tmp/myfile.txt', // The file path
content: <data> // A Buffer, Readable Stream or Pull Stream with the contents of the file
content: <data> // A Buffer, Readable Stream, Pull Stream or File with the contents of the file
}
```

Expand Down Expand Up @@ -185,7 +186,7 @@ Returns a Pull Stream, where objects can be written of the forms
```js
{
path: '/tmp/myfile.txt', // The file path
content: <data> // A Buffer, Readable Stream or Pull Stream with the contents of the file
content: <data> // A Buffer, Readable Stream, Pull Stream or File with the contents of the file
}
```

Expand Down Expand Up @@ -1136,5 +1137,6 @@ A great source of [examples][] can be found in the tests for this API.
[b]: https://www.npmjs.com/package/buffer
[rs]: https://www.npmjs.com/package/readable-stream
[ps]: https://www.npmjs.com/package/pull-stream
[file]: https://developer.mozilla.org/en-US/docs/Web/API/File
[cid]: https://www.npmjs.com/package/cids
[blob]: https://developer.mozilla.org/en-US/docs/Web/API/Blob
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"into-stream": "^5.1.0",
"ipfs-block": "~0.8.0",
"ipfs-unixfs": "~0.1.16",
"ipfs-utils": "~0.0.3",
"ipld-dag-cbor": "~0.13.1",
"ipld-dag-pb": "~0.15.3",
"is-ipfs": "~0.6.0",
Expand All @@ -59,7 +60,7 @@
"multihashing-async": "~0.6.0",
"peer-id": "~0.12.0",
"peer-info": "~0.15.0",
"pull-stream": "^3.6.9",
"pull-stream": "^3.6.11",
"pump": "^3.0.0",
"randombytes": "^2.0.6",
"readable-stream": "^3.1.1",
Expand Down
17 changes: 15 additions & 2 deletions src/files-regular/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const pull = require('pull-stream')
const path = require('path')
const expectTimeout = require('../utils/expect-timeout')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { supportsFileReader } = require('ipfs-utils/src/supports')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
Expand Down Expand Up @@ -35,6 +36,18 @@ module.exports = (createCommon, options) => {

after((done) => common.teardown(done))

it('should add a File', function (done) {
if (supportsFileReader) {
ipfs.add(new self.File(['should add a File'], 'filename.txt', { type: 'text/plain' }), (err, filesAdded) => {
expect(err).to.not.exist()
expect(filesAdded[0].hash).to.be.eq('QmTVfLxf3qXiJgr4KwG6UBckcNvTqBp93Rwy5f7h3mHsVC')
done()
})
} else {
this.skip('skip in node')
}
})

it('should add a Buffer', (done) => {
ipfs.add(fixtures.smallFile.data, (err, filesAdded) => {
expect(err).to.not.exist()
Expand Down Expand Up @@ -125,7 +138,7 @@ module.exports = (createCommon, options) => {

ipfs.add(data, (err) => {
expect(err).to.exist()
expect(err.message).to.contain('invalid input')
expect(err.message).to.contain('Input not supported')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this pass when these tests are run against js-ipfs-http-client?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

done()
})
})
Expand All @@ -135,7 +148,7 @@ module.exports = (createCommon, options) => {

ipfs.add(data, (err) => {
expect(err).to.exist()
expect(err.message).to.contain('invalid input')
expect(err.message).to.contain('Input not supported')
done()
})
})
Expand Down