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

Commit dd446e8

Browse files
author
Pedro Santos
committed
refactor: key before and after methods to async syntax
1 parent 4172720 commit dd446e8

File tree

6 files changed

+30
-96
lines changed

6 files changed

+30
-96
lines changed

src/key/export.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,15 @@ module.exports = (createCommon, options) => {
99
const it = getIt(options)
1010
const common = createCommon()
1111

12-
describe('.key.export', () => {
12+
describe('.key.export', function () {
13+
this.timeout(60 * 1000)
1314
let ipfs
1415

15-
before(function (done) {
16-
// CI takes longer to instantiate the daemon, so we need to increase the
17-
// timeout for the before step
18-
this.timeout(60 * 1000)
19-
20-
common.setup((err, factory) => {
21-
expect(err).to.not.exist()
22-
factory.spawnNode((err, node) => {
23-
expect(err).to.not.exist()
24-
ipfs = node
25-
done()
26-
})
27-
})
16+
before(async () => {
17+
ipfs = await common.setup()
2818
})
2919

30-
after((done) => common.teardown(done))
20+
after(() => common.teardown())
3121

3222
it('should export "self" key', async function () {
3323
const pem = await ipfs.key.export('self', hat())

src/key/gen.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,19 @@ module.exports = (createCommon, options) => {
99
const it = getIt(options)
1010
const common = createCommon()
1111

12-
describe('.key.gen', () => {
12+
describe('.key.gen', function () {
13+
this.timeout(60 * 1000)
1314
const keyTypes = [
1415
{ type: 'rsa', size: 2048 }
1516
]
1617

1718
let ipfs
1819

19-
before(function (done) {
20-
// CI takes longer to instantiate the daemon, so we need to increase the
21-
// timeout for the before step
22-
this.timeout(60 * 1000)
23-
24-
common.setup((err, factory) => {
25-
expect(err).to.not.exist()
26-
factory.spawnNode((err, node) => {
27-
expect(err).to.not.exist()
28-
ipfs = node
29-
done()
30-
})
31-
})
20+
before(async () => {
21+
ipfs = await common.setup()
3222
})
3323

34-
after((done) => common.teardown(done))
24+
after(() => common.teardown())
3525

3626
keyTypes.forEach((kt) => {
3727
it(`should generate a new ${kt.type} key`, async function () {

src/key/import.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,15 @@ module.exports = (createCommon, options) => {
99
const it = getIt(options)
1010
const common = createCommon()
1111

12-
describe('.key.import', () => {
12+
describe('.key.import', function () {
13+
this.timeout(60 * 1000)
1314
let ipfs
1415

15-
before(function (done) {
16-
// CI takes longer to instantiate the daemon, so we need to increase the
17-
// timeout for the before step
18-
this.timeout(60 * 1000)
19-
20-
common.setup((err, factory) => {
21-
expect(err).to.not.exist()
22-
factory.spawnNode((err, node) => {
23-
expect(err).to.not.exist()
24-
ipfs = node
25-
done()
26-
})
27-
})
16+
before(async () => {
17+
ipfs = await common.setup()
2818
})
2919

30-
after((done) => common.teardown(done))
20+
after(() => common.teardown())
3121

3222
it('should import an exported key', async () => {
3323
const password = hat()

src/key/list.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,17 @@ module.exports = (createCommon, options) => {
1111
const it = getIt(options)
1212
const common = createCommon()
1313

14-
describe('.key.list', () => {
14+
describe('.key.list', function () {
15+
this.timeout(60 * 1000)
1516
let ipfs
1617

17-
before(function (done) {
18-
// CI takes longer to instantiate the daemon, so we need to increase the
19-
// timeout for the before step
20-
this.timeout(60 * 1000)
21-
22-
common.setup((err, factory) => {
23-
expect(err).to.not.exist()
24-
factory.spawnNode((err, node) => {
25-
expect(err).to.not.exist()
26-
ipfs = node
27-
done()
28-
})
29-
})
18+
before(async () => {
19+
ipfs = await common.setup()
3020
})
3121

32-
after((done) => common.teardown(done))
22+
after(() => common.teardown())
3323

3424
it('should list all the keys', async function () {
35-
this.timeout(60 * 1000)
36-
3725
const keys = await pTimes(3, () => ipfs.key.gen(hat(), { type: 'rsa', size: 2048 }), { concurrency: 1 })
3826

3927
const res = await ipfs.key.list()

src/key/rename.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,17 @@ module.exports = (createCommon, options) => {
1010
const it = getIt(options)
1111
const common = createCommon()
1212

13-
describe('.key.rename', () => {
13+
describe('.key.rename', function () {
14+
this.timeout(60 * 1000)
1415
let ipfs
1516

16-
before(function (done) {
17-
// CI takes longer to instantiate the daemon, so we need to increase the
18-
// timeout for the before step
19-
this.timeout(60 * 1000)
20-
21-
common.setup((err, factory) => {
22-
expect(err).to.not.exist()
23-
factory.spawnNode((err, node) => {
24-
expect(err).to.not.exist()
25-
ipfs = node
26-
done()
27-
})
28-
})
17+
before(async () => {
18+
ipfs = await common.setup()
2919
})
3020

31-
after((done) => common.teardown(done))
21+
after(() => common.teardown())
3222

3323
it('should rename a key', async function () {
34-
this.timeout(30 * 1000)
35-
3624
const oldName = hat()
3725
const newName = hat()
3826

src/key/rm.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,17 @@ module.exports = (createCommon, options) => {
1010
const it = getIt(options)
1111
const common = createCommon()
1212

13-
describe('.key.rm', () => {
13+
describe('.key.rm', function () {
14+
this.timeout(60 * 1000)
1415
let ipfs
1516

16-
before(function (done) {
17-
// CI takes longer to instantiate the daemon, so we need to increase the
18-
// timeout for the before step
19-
this.timeout(60 * 1000)
20-
21-
common.setup((err, factory) => {
22-
expect(err).to.not.exist()
23-
factory.spawnNode((err, node) => {
24-
expect(err).to.not.exist()
25-
ipfs = node
26-
done()
27-
})
28-
})
17+
before(async () => {
18+
ipfs = await common.setup()
2919
})
3020

31-
after((done) => common.teardown(done))
21+
after(() => common.teardown())
3222

3323
it('should rm a key', async function () {
34-
this.timeout(30 * 1000)
35-
3624
const key = await ipfs.key.gen(hat(), { type: 'rsa', size: 2048 })
3725

3826
const removeRes = await ipfs.key.rm(key.name)

0 commit comments

Comments
 (0)