-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: os-native add-to-ipfs on Windows and macOS (#1976)
* fix: use new glob source API See ipfs/js-ipfs#3889 * feat: add tests and improve add-to-ipfs
- Loading branch information
Showing
9 changed files
with
158 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* eslint-env mocha */ | ||
|
||
const chai = require('chai') | ||
const path = require('path') | ||
const { expect } = chai | ||
const dirtyChai = require('dirty-chai') | ||
|
||
const mockElectron = require('./mocks/electron') | ||
const mockLogger = require('./mocks/logger') | ||
const mockNotify = require('./mocks/notify') | ||
|
||
const proxyquire = require('proxyquire').noCallThru() | ||
|
||
const { makeRepository } = require('./../e2e/utils/ipfsd') | ||
|
||
chai.use(dirtyChai) | ||
|
||
const getFixtures = (...files) => files.map(f => path.join(__dirname, 'fixtures', f)) | ||
|
||
describe('Add To Ipfs', function () { | ||
this.timeout(5000) | ||
|
||
let electron, notify, addToIpfs, ipfsd, ctx | ||
|
||
before(async () => { | ||
const repo = await makeRepository({ start: true }) | ||
ipfsd = repo.ipfsd | ||
ctx = { | ||
getIpfsd: () => ipfsd, | ||
launchWebUI: () => {} | ||
} | ||
}) | ||
|
||
after(() => { | ||
if (ipfsd) ipfsd.stop() | ||
}) | ||
|
||
beforeEach(async () => { | ||
electron = mockElectron() | ||
notify = mockNotify() | ||
addToIpfs = proxyquire('../../src/add-to-ipfs', { | ||
electron: electron, | ||
'./common/notify': notify, | ||
'./common/logger': mockLogger() | ||
}) | ||
}) | ||
|
||
it('add to ipfs single file', async () => { | ||
const cid = await addToIpfs(ctx, getFixtures('hello-world.txt')) | ||
expect(electron.clipboard.writeText.callCount).to.equal(1) | ||
expect(notify.notifyError.callCount).to.equal(0) | ||
expect(notify.notify.callCount).to.equal(1) | ||
expect(cid.toString()).to.equal('QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks') | ||
}) | ||
|
||
it('add to ipfs single directory', async () => { | ||
const cid = await addToIpfs(ctx, getFixtures('dir')) | ||
expect(electron.clipboard.writeText.callCount).to.equal(1) | ||
expect(notify.notifyError.callCount).to.equal(0) | ||
expect(notify.notify.callCount).to.equal(1) | ||
expect(cid.toString()).to.equal('QmVuxXkWEyCKvQiMqVnDiwyJUUyDQZ7VsKhQDCZzPj1Yq8') | ||
}) | ||
|
||
it('add to ipfs multiple files', async () => { | ||
const cid = await addToIpfs(ctx, getFixtures('dir', 'hello-world.txt')) | ||
expect(electron.clipboard.writeText.callCount).to.equal(1) | ||
expect(notify.notifyError.callCount).to.equal(0) | ||
expect(notify.notify.callCount).to.equal(1) | ||
expect(cid.toString()).to.equal('QmdYASNGKMVK4HL1uzi3VCZyjQGg3M6VuLsgX5xTKL1gvH') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello, IPFS! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello, world! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const sinon = require('sinon') | ||
|
||
module.exports = function mockNotify () { | ||
return { | ||
notify: sinon.spy(), | ||
notifyError: sinon.spy() | ||
} | ||
} |