From c23782a5a949a60157dcb5bc3c3639d072a55c17 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 10 Jan 2020 16:04:50 +0000 Subject: [PATCH 1/3] docs: update files.flush return type `ipfs.files.flush` returns the CID of the flushed path since `go-IPFS@v0.4.20`. It also only takes one path as an optional parameter. --- SPEC/FILES.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SPEC/FILES.md b/SPEC/FILES.md index 419cb6dcc..d85cc86cb 100644 --- a/SPEC/FILES.md +++ b/SPEC/FILES.md @@ -1204,22 +1204,22 @@ await ipfs.files.mv('/src-file1', '/src-file2', '/dst-dir') > Flush a given path's data to the disk -##### `ipfs.files.flush([...paths])` +##### `ipfs.files.flush([path])` Where: -- `paths` are optional string paths to flush (default: `/`) +- `path` is an optional string path to flush (default: `/`) **Returns** | Type | Description | | -------- | -------- | -| `Promise` | If successfully copied. Otherwise an error will be thrown | +| `Promise` | The CID of the path that has been flushed | **Example:** ```JavaScript -await ipfs.files.flush('/') +const cid = await ipfs.files.flush('/') ``` #### `files.ls` From 4c9a359cf7ab8f92df1d8277b17173daf8b6cbc8 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 10 Jan 2020 17:20:26 +0000 Subject: [PATCH 2/3] test: update tests to assert CIDs are returned --- src/files-mfs/flush.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/files-mfs/flush.js b/src/files-mfs/flush.js index 54c74cdcf..ba3d22915 100644 --- a/src/files-mfs/flush.js +++ b/src/files-mfs/flush.js @@ -13,7 +13,7 @@ module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - describe('.files.flush', function () { + describe.only('.files.flush', function () { this.timeout(40 * 1000) let ipfs @@ -32,13 +32,22 @@ module.exports = (common, options) => { } }) - it('should flush root', () => ipfs.files.flush()) + it('should flush root', async () => { + const root = await ipfs.files.stat('/') + const flushed = await ipfs.files.flush() + + expect(root.hash).to.equal(flushed.toString()) + }) it('should flush specific dir', async () => { const testDir = `/test-${hat()}` await ipfs.files.mkdir(testDir, { parents: true }) - await ipfs.files.flush(testDir) + + const dirStats = await ipfs.files.stat(testDir) + const flushed = await ipfs.files.flush(testDir) + + expect(dirStats.hash).to.equal(flushed.toString()) }) }) } From 6327507483e13d6e996451b56f83d0374653bb6e Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 10 Jan 2020 17:24:27 +0000 Subject: [PATCH 3/3] fix: linting --- src/files-mfs/flush.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/files-mfs/flush.js b/src/files-mfs/flush.js index ba3d22915..d7d282d18 100644 --- a/src/files-mfs/flush.js +++ b/src/files-mfs/flush.js @@ -13,7 +13,7 @@ module.exports = (common, options) => { const describe = getDescribe(options) const it = getIt(options) - describe.only('.files.flush', function () { + describe('.files.flush', function () { this.timeout(40 * 1000) let ipfs