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

Commit 3bae1d8

Browse files
committed
fix aegir setup (test->src), make it buildable, remove require(raw! for fs, stop requiring fs inside functions (breaks webpack)
1 parent 3130b8f commit 3bae1d8

14 files changed

+17
-31
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "interface-ipfs-core",
33
"version": "0.1.5",
44
"description": "A test suite and interface you can use to implement a IPFS core interface.",
5-
"main": "test/index.js",
6-
"jsnext:main": "test/index.js",
5+
"main": "lib/index.js",
6+
"jsnext:main": "src/index.js",
77
"scripts": {
88
"test": "exit(0)",
99
"build": "aegir-build node",
@@ -42,4 +42,4 @@
4242
"David Dias <[email protected]>",
4343
"Friedel Ziegelmayer <[email protected]>"
4444
]
45-
}
45+
}
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.

test/files.js renamed to src/files.js

+14-28
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,23 @@
22
'use strict'
33

44
const expect = require('chai').expect
5-
const DAGNode = require('ipfs-merkle-dag').DAGNode
65
const bs58 = require('bs58')
7-
const bl = require('bl')
86
const Readable = require('readable-stream')
97
const path = require('path')
108
const isNode = require('detect-node')
9+
const fs = require('fs')
1110

1211
module.exports = (common) => {
1312
describe('.files/add', () => {
14-
let testfile
15-
let testfileBig
13+
let smallFile
14+
let bigFile
1615
let ipfs
1716

1817
before((done) => {
19-
// load test data
20-
if (isNode) {
21-
const fs = require('fs')
22-
23-
const testfilePath = path.join(__dirname, './data/testfile.txt')
24-
testfile = fs.readFileSync(testfilePath)
25-
26-
const testfileBigPath = path.join(__dirname, './data/15mb.random')
27-
testfileBig = fs.createReadStream(testfileBigPath, { bufferSize: 128 })
28-
} else {
29-
testfile = require('raw!./data/testfile.txt')
30-
}
18+
smallFile = fs.readFileSync(path.join(__dirname, './data/testfile.txt')
19+
)
20+
bigFile = fs.readFileSync(path.join(__dirname, './data/15mb.random')
21+
)
3122

3223
common.setup((err, _ipfs) => {
3324
expect(err).to.not.exist
@@ -66,7 +57,7 @@ module.exports = (common) => {
6657

6758
const file = {
6859
path: 'testfile.txt',
69-
content: new Buffer(testfile)
60+
content: smallFile
7061
}
7162

7263
ipfs.files.add([file], (err, res) => {
@@ -82,8 +73,7 @@ module.exports = (common) => {
8273
})
8374

8475
it('buffer', (done) => {
85-
let buf = new Buffer(testfile)
86-
ipfs.files.add(buf, (err, res) => {
76+
ipfs.files.add(smallFile, (err, res) => {
8777
expect(err).to.not.exist
8878

8979
expect(res).to.have.length(1)
@@ -96,11 +86,7 @@ module.exports = (common) => {
9686
})
9787

9888
it('BIG buffer', (done) => {
99-
if (!isNode) {
100-
return done()
101-
}
102-
103-
ipfs.files.add(testfileBig, (err, res) => {
89+
ipfs.files.add(bigFile, (err, res) => {
10490
expect(err).to.not.exist
10591

10692
expect(res).to.have.length(1)
@@ -113,8 +99,9 @@ module.exports = (common) => {
11399
})
114100

115101
it('add a nested dir as array', (done) => {
116-
if (!isNode) return done()
117-
const fs = require('fs')
102+
if (!isNode) {
103+
return done()
104+
}
118105
const base = path.join(__dirname, 'data/test-folder')
119106
const content = (name) => ({
120107
path: `test-folder/${name}`,
@@ -149,8 +136,7 @@ module.exports = (common) => {
149136

150137
describe('promise', () => {
151138
it('buffer', () => {
152-
let buf = new Buffer(testfile)
153-
return ipfs.files.add(buf)
139+
return ipfs.files.add(smallFile)
154140
.then((res) => {
155141
const added = res[0] != null ? res[0] : res
156142
const mh = bs58.encode(added.node.multihash()).toString()
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)