This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move mfs cmds and safer exit (#1981)
This PR moves mfs cli commands to parser.js to make them available for tests and also add `signal-exit` to the cli to make forced exits safer. Co-Authored-By: hugomrdias <mail@hugodias.me>
- Loading branch information
1 parent
1fd2227
commit fee0141
Showing
6 changed files
with
86 additions
and
76 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,25 +1,43 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const runOnAndOff = require('../utils/on-and-off') | ||
const sinon = require('sinon') | ||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
const YargsPromise = require('yargs-promise') | ||
const clearModule = require('clear-module') | ||
chai.use(dirtyChai) | ||
|
||
describe('id', () => runOnAndOff((thing) => { | ||
let ipfs | ||
|
||
before(function () { | ||
this.timeout(60 * 1000) | ||
ipfs = thing.ipfs | ||
describe('id', () => { | ||
let cli | ||
let cliUtils | ||
beforeEach(() => { | ||
cliUtils = require('../../src/cli/utils') | ||
cli = new YargsPromise(require('../../src/cli/parser')) | ||
}) | ||
afterEach(() => { | ||
sinon.restore() | ||
// TODO: the lines below shouldn't be necessary, cli needs refactor to simplify testability | ||
// Force the next require to not use require cache | ||
clearModule('../../src/cli/utils') | ||
clearModule('../../src/cli/parser') | ||
}) | ||
|
||
it('get the id', function () { | ||
this.timeout(60 * 1000) | ||
it('should output formatted json string', async () => { | ||
const fakeId = sinon.fake.returns( | ||
{ id: 'id', publicKey: 'publicKey' } | ||
) | ||
|
||
sinon | ||
.stub(cliUtils, 'getIPFS') | ||
.callsArgWith(1, null, { id: fakeId }) | ||
|
||
// TODO: the lines below shouldn't be necessary, cli needs refactor to simplify testability | ||
// Force the next require to not use require cache | ||
clearModule('../../src/cli/commands/id.js') | ||
const { data } = await cli.parse('id') | ||
|
||
return ipfs('id').then((res) => { | ||
const id = JSON.parse(res) | ||
expect(id).to.have.property('id') | ||
expect(id).to.have.property('publicKey') | ||
expect(id).to.have.property('addresses') | ||
}) | ||
expect(data).to.eq('{\n "id": "id",\n "publicKey": "publicKey"\n}') | ||
}) | ||
})) | ||
}) |