Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 2289ac9

Browse files
committed
Merge pull request #100 from ipfs/tests/refactor
just a bit of cleanup
2 parents cd6797d + 4b9e954 commit 2289ac9

File tree

85 files changed

+66
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+66
-58
lines changed

karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ module.exports = function (config) {
88

99
files: [
1010
nodeForgePath,
11-
'tests/test-core/browser.js'
11+
'test/core-tests/browser.js'
1212
],
1313

1414
preprocessors: {
15-
'tests/test-core/*': ['webpack']
15+
'test/core-tests/*': ['webpack']
1616
},
1717

1818
webpack: {

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
"main": "src/core/index.js",
99
"scripts": {
1010
"lint": "standard --verbose | snazzy",
11-
"coverage": "istanbul cover --print both -- _mocha tests/test-core/index.js",
12-
"coverage:http-api": "istanbul cover --print both -- _mocha tests/test-http-api/index.js",
11+
"coverage": "istanbul cover --print both -- _mocha test/core-tests/index.js",
12+
"coverage:http-api": "istanbul cover --print both -- _mocha test/http-api-tests/index.js",
1313
"test": "npm run test:node && npm run test:browser",
1414
"test:node": "npm run test:node:core && npm run test:node:http-api && npm run test:node:cli",
1515
"test:node:teamcity": "npm run test:node:core:teamcity && npm run test:node:http-api:teamcity && npm run test:node:cli:teamcity",
16-
"test:node:cli:teamcity": "mocha --reporter mocha-teamcity-reporter tests/test-cli/index.js",
17-
"test:node:core:teamcity": "mocha --reporter mocha-teamcity-reporter tests/test-core/index.js",
18-
"test:node:http-api:teamcity": "mocha --reporter mocha-teamcity-reporter tests/test-http-api/index.js",
19-
"test:node:cli": "mocha tests/test-cli/index.js",
20-
"test:node:core": "mocha tests/test-core/index.js",
21-
"test:node:http-api": "mocha tests/test-http-api/index.js",
16+
"test:node:cli:teamcity": "mocha --reporter mocha-teamcity-reporter test/cli-tests/index.js",
17+
"test:node:core:teamcity": "mocha --reporter mocha-teamcity-reporter test/core-tests/index.js",
18+
"test:node:http-api:teamcity": "mocha --reporter mocha-teamcity-reporter test/http-api-tests/index.js",
19+
"test:node:cli": "mocha test/cli-tests/index.js",
20+
"test:node:core": "mocha test/core-tests/index.js",
21+
"test:node:http-api": "mocha test/http-api-tests/index.js",
2222
"test:browser": "karma start karma.conf.js",
2323
"test:browser:teamcity": "karma start --reporters teamcity --colors false karma.conf.js",
24-
"test:core": "mocha tests/test-core/index.js",
25-
"test:cli": "mocha tests/test-cli/index.js"
24+
"test:core": "mocha test/core-tests/index.js",
25+
"test:cli": "mocha test/cli-tests/index.js"
2626
},
2727
"pre-commit": [
2828
"lint",

src/core/init.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = (repo, opts, callback) => {
1010
opts.bits = opts.bits || 2048
1111

1212
// Pre-set config values.
13-
var config = require('../../default-config.json')
13+
var config = require('../init-files/default-config.json')
1414

1515
// Verify repo does not yet exist (or that 'force' is provided).
1616
repo.exists((err, res) => {
@@ -65,7 +65,7 @@ module.exports = (repo, opts, callback) => {
6565
const blocks = new IpfsBlocks(repo)
6666
const dag = new IpfsDagService(blocks)
6767

68-
const initDocsPath = path.join(__dirname, '../../init-doc')
68+
const initDocsPath = path.join(__dirname, '../init-files/init-docs')
6969

7070
importer.import(initDocsPath, dag, {
7171
recursive: true
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/test-cli/index.js renamed to test/cli-tests/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const rimraf = require('rimraf')
66
const expect = require('chai').expect
77

88
describe('cli', () => {
9-
const repoExample = process.cwd() + '/tests/repo-example'
10-
const repoTests = exports.repoTests = process.cwd() + '/tests/repo-tests-run'
9+
const repoExample = process.cwd() + '/test/go-ipfs-repo'
10+
const repoTests = exports.repoTests = process.cwd() + '/test/repo-tests-run'
1111

1212
before((done) => {
1313
ncp(repoExample, repoTests, (err) => {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/test-cli/test-object.js renamed to test/cli-tests/test-object.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('object', () => {
3232
})
3333

3434
it('put', (done) => {
35-
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'put', process.cwd() + '/tests/node.json'])
35+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'put', process.cwd() + '/test/test-data/node.json'])
3636
.run((err, stdout, exitcode) => {
3737
expect(err).to.not.exist
3838
expect(exitcode).to.equal(0)
@@ -81,7 +81,7 @@ describe('object', () => {
8181

8282
describe('patch', () => {
8383
it('append-data', (done) => {
84-
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'append-data', 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', process.cwd() + '/tests/badconfig'])
84+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'append-data', 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', process.cwd() + '/test/test-data/badconfig'])
8585
.run((err, stdout, exitcode) => {
8686
expect(err).to.not.exist
8787
expect(exitcode).to.equal(0)
@@ -92,7 +92,7 @@ describe('object', () => {
9292
})
9393

9494
it('set-data', (done) => {
95-
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'set-data', 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6', process.cwd() + '/tests/badconfig'])
95+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'set-data', 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6', process.cwd() + '/test/test-data/badconfig'])
9696
.run((err, stdout, exitcode) => {
9797
expect(err).to.not.exist
9898
expect(exitcode).to.equal(0)
@@ -167,7 +167,7 @@ describe('object', () => {
167167
})
168168

169169
it('put', (done) => {
170-
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'put', process.cwd() + '/tests/node.json'])
170+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'put', process.cwd() + '/test/test-data/node.json'])
171171
.run((err, stdout, exitcode) => {
172172
expect(err).to.not.exist
173173
expect(exitcode).to.equal(0)
@@ -216,7 +216,7 @@ describe('object', () => {
216216

217217
describe('patch', () => {
218218
it('append-data', (done) => {
219-
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'append-data', 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', process.cwd() + '/tests/badconfig'])
219+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'append-data', 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', process.cwd() + '/test/test-data/badconfig'])
220220
.run((err, stdout, exitcode) => {
221221
expect(err).to.not.exist
222222
expect(exitcode).to.equal(0)
@@ -227,7 +227,7 @@ describe('object', () => {
227227
})
228228

229229
it('set-data', (done) => {
230-
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'set-data', 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6', process.cwd() + '/tests/badconfig'])
230+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'set-data', 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6', process.cwd() + '/test/test-data/badconfig'])
231231
.run((err, stdout, exitcode) => {
232232
expect(err).to.not.exist
233233
expect(exitcode).to.equal(0)
File renamed without changes.

tests/test-core/browser.js renamed to test/core-tests/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const async = require('async')
44
const store = require('idb-plus-blob-store')
55
const _ = require('lodash')
66

7-
const repoContext = require.context('buffer!./../repo-example', true)
7+
const repoContext = require.context('buffer!./../go-ipfs-repo', true)
88

99
const idb = window.indexedDB ||
1010
window.mozIndexedDB ||

tests/test-core/index.js renamed to test/core-tests/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const rimraf = require('rimraf')
66
const expect = require('chai').expect
77

88
describe('core', () => {
9-
const repoExample = process.cwd() + '/tests/repo-example'
10-
const repoTests = process.cwd() + '/tests/repo-tests-run'
9+
const repoExample = process.cwd() + '/test/go-ipfs-repo'
10+
const repoTests = process.cwd() + '/test/repo-tests-run'
1111

1212
before((done) => {
1313
ncp(repoExample, repoTests, (err) => {

tests/test-core/test-block.js renamed to test/core-tests/test-block.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const Block = require('ipfs-blocks').Block
99
const isNode = !global.window
1010

1111
const fileA = isNode
12-
? fs.readFileSync(process.cwd() + '/tests/repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')
13-
: require('buffer!./../repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')
12+
? fs.readFileSync(process.cwd() + '/test/go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')
13+
: require('buffer!./../go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')
1414

1515
// TODO use arrow funtions again when https://github.com/webpack/webpack/issues/1944 is fixed
1616
describe('block', function () {
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/test-core/test-init-node.js renamed to test/core-tests/test-init-node.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22

33
const expect = require('chai').expect
44
const IPFS = require('../../src/core')
5-
const createTempRepo = require('../temp-repo')
5+
const createTempRepo = require('../utils/temp-repo')
66

7-
describe('node: init', function () {
7+
describe('init (Node.js specific)', function () {
88
this.timeout(10000)
99

10-
it('init docs written', (done) => {
11-
var repo = createTempRepo()
12-
const ipfs = new IPFS(repo)
10+
var ipfs
11+
var repo
12+
13+
beforeEach((done) => {
14+
repo = createTempRepo()
15+
ipfs = new IPFS(repo)
16+
done()
17+
})
18+
19+
afterEach((done) => {
20+
repo.teardown(done)
21+
})
22+
23+
it('init docs are written', (done) => {
1324
ipfs.init({ bits: 64 }, (err) => {
1425
expect(err).to.not.exist
1526

@@ -18,23 +29,20 @@ describe('node: init', function () {
1829
ipfs.object.get(multihash, {}, (err, node) => {
1930
expect(err).to.not.exist
2031
expect(node.links).to.exist
21-
22-
repo.teardown(done)
32+
done()
2333
})
2434
})
2535
})
2636

2737
it('empty repo', (done) => {
28-
var repo = createTempRepo()
29-
const ipfs = new IPFS(repo)
3038
ipfs.init({ bits: 64, emptyRepo: true }, (err) => {
3139
expect(err).to.not.exist
3240

3341
// Check for default assets
3442
var multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex')
3543
ipfs.object.get(multihash, {}, (err, node) => {
3644
expect(err).to.exist
37-
repo.teardown(done)
45+
done()
3846
})
3947
})
4048
})

tests/test-core/test-init.js renamed to test/core-tests/test-init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const expect = require('chai').expect
44
const IPFS = require('../../src/core')
5-
const createTempRepo = require('../temp-repo')
5+
const createTempRepo = require('../utils/temp-repo')
66

77
describe('init', function () {
88
this.timeout(10000)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/test-http-api/index.js renamed to test/http-api-tests/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const ncp = require('ncp').ncp
77
const rimraf = require('rimraf')
88

99
describe('http api', () => {
10-
const repoExample = process.cwd() + '/tests/repo-example'
11-
const repoTests = process.cwd() + '/tests/repo-tests-run'
10+
const repoExample = process.cwd() + '/test/go-ipfs-repo'
11+
const repoTests = process.cwd() + '/test/repo-tests-run'
1212
process.env.IPFS_PATH = repoTests
1313

1414
before((done) => {
File renamed without changes.

tests/test-http-api/test-config.js renamed to test/http-api-tests/test-config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const FormData = require('form-data')
88
const streamToPromise = require('stream-to-promise')
99

1010
describe('config', () => {
11-
const configPath = process.cwd() + '/tests/repo-tests-run/config'
12-
const originalConfigPath = process.cwd() + '/tests/repo-example/config'
11+
const configPath = process.cwd() + '/test/repo-tests-run/config'
12+
const originalConfigPath = process.cwd() + '/test/go-ipfs-repo/config'
1313
const updatedConfig = () => JSON.parse(fs.readFileSync(configPath, 'utf8'))
1414
const restoreConfig = () => fs.writeFileSync(configPath, fs.readFileSync(originalConfigPath, 'utf8'), 'utf8')
1515

@@ -169,7 +169,7 @@ describe('config', () => {
169169

170170
it('returns 500 if the config is invalid', (done) => {
171171
const form = new FormData()
172-
const filePath = 'tests/badconfig'
172+
const filePath = 'test/test-data/badconfig'
173173
form.append('file', fs.createReadStream(filePath))
174174
const headers = form.getHeaders()
175175

@@ -188,7 +188,7 @@ describe('config', () => {
188188

189189
it('updates value', (done) => {
190190
const form = new FormData()
191-
const filePath = 'tests/otherconfig'
191+
const filePath = 'test/test-data/otherconfig'
192192
form.append('file', fs.createReadStream(filePath))
193193
const headers = form.getHeaders()
194194
const expectedConfig = JSON.parse(fs.readFileSync(filePath, 'utf8'))
@@ -311,7 +311,7 @@ describe('config', () => {
311311

312312
describe('ipfs.config.replace', () => {
313313
it('returns error if the config is invalid', (done) => {
314-
const filePath = 'tests/badconfig'
314+
const filePath = 'test/test-data/badconfig'
315315

316316
ctl.config.replace(filePath, (err) => {
317317
expect(err).to.exist
@@ -320,7 +320,7 @@ describe('config', () => {
320320
})
321321

322322
it('updates value', (done) => {
323-
const filePath = 'tests/otherconfig'
323+
const filePath = 'test/test-data/otherconfig'
324324
const expectedConfig = JSON.parse(fs.readFileSync(filePath, 'utf8'))
325325

326326
ctl.config.replace(filePath, (err) => {
File renamed without changes.

tests/test-http-api/test-object.js renamed to test/http-api-tests/test-object.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('object', () => {
102102

103103
it('returns 500 if the node is invalid', (done) => {
104104
const form = new FormData()
105-
const filePath = 'tests/badnode.json'
105+
const filePath = 'test/test-data/badnode.json'
106106
form.append('file', fs.createReadStream(filePath))
107107
const headers = form.getHeaders()
108108

@@ -121,7 +121,7 @@ describe('object', () => {
121121

122122
it('updates value', (done) => {
123123
const form = new FormData()
124-
const filePath = 'tests/node.json'
124+
const filePath = 'test/test-data/node.json'
125125
form.append('data', fs.createReadStream(filePath))
126126
const headers = form.getHeaders()
127127
const expectedResult = {
@@ -298,7 +298,7 @@ describe('object', () => {
298298

299299
it('returns 500 for request with invalid key', (done) => {
300300
const form = new FormData()
301-
const filePath = 'tests/badconfig'
301+
const filePath = 'test/test-data/badconfig'
302302
form.append('file', fs.createReadStream(filePath))
303303
const headers = form.getHeaders()
304304

@@ -317,7 +317,7 @@ describe('object', () => {
317317

318318
it('updates value', (done) => {
319319
const form = new FormData()
320-
const filePath = 'tests/badconfig'
320+
const filePath = 'test/test-data/badconfig'
321321
form.append('data', fs.createReadStream(filePath))
322322
const headers = form.getHeaders()
323323
const expectedResult = {
@@ -371,7 +371,7 @@ describe('object', () => {
371371

372372
it('returns 500 for request with invalid key', (done) => {
373373
const form = new FormData()
374-
const filePath = 'tests/badconfig'
374+
const filePath = 'test/test-data/badconfig'
375375
form.append('file', fs.createReadStream(filePath))
376376
const headers = form.getHeaders()
377377

@@ -390,7 +390,7 @@ describe('object', () => {
390390

391391
it('updates value', (done) => {
392392
const form = new FormData()
393-
const filePath = 'tests/badconfig'
393+
const filePath = 'test/test-data/badconfig'
394394
form.append('data', fs.createReadStream(filePath))
395395
const headers = form.getHeaders()
396396
const expectedResult = {
@@ -585,7 +585,7 @@ describe('object', () => {
585585

586586
describe('ipfs.object.put', () => {
587587
it('returns error if the node is invalid', (done) => {
588-
const filePath = 'tests/badnode.json'
588+
const filePath = 'test/test-data/badnode.json'
589589

590590
ctl.object.put(filePath, 'json', (err) => {
591591
expect(err).to.exist
@@ -594,7 +594,7 @@ describe('object', () => {
594594
})
595595

596596
it('updates value', (done) => {
597-
const filePath = 'tests/node.json'
597+
const filePath = 'test/test-data/node.json'
598598
const expectedResult = {
599599
Hash: 'QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm',
600600
Links: [{
@@ -713,7 +713,7 @@ describe('object', () => {
713713
})
714714

715715
it('returns error for request without data', (done) => {
716-
const filePath = 'tests/badnode.json'
716+
const filePath = 'test/test-data/badnode.json'
717717

718718
ctl.object.patch.appendData(null, filePath, (err) => {
719719
expect(err).to.exist
@@ -723,7 +723,7 @@ describe('object', () => {
723723

724724
it('updates value', (done) => {
725725
const key = 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
726-
const filePath = 'tests/badnode.json'
726+
const filePath = 'test/test-data/badnode.json'
727727
const expectedResult = {
728728
Hash: 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6',
729729
Links: []
@@ -755,7 +755,7 @@ describe('object', () => {
755755
})
756756

757757
it('returns error for request without data', (done) => {
758-
const filePath = 'tests/badnode.json'
758+
const filePath = 'test/test-data/badnode.json'
759759

760760
ctl.object.patch.setData(null, filePath, (err) => {
761761
expect(err).to.exist
@@ -765,7 +765,7 @@ describe('object', () => {
765765

766766
it('updates value', (done) => {
767767
const key = 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6'
768-
const filePath = 'tests/badnode.json'
768+
const filePath = 'test/test-data/badnode.json'
769769
const expectedResult = {
770770
Hash: 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6',
771771
Links: []
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)