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

Commit d4fc07e

Browse files
committed
feat: More stat tests
1 parent 2ea064b commit d4fc07e

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"aegir": "^13.0.6",
3939
"chai": "^4.1.2",
4040
"dirty-chai": "^2.0.1",
41+
"fs-extra": "^5.0.0",
4142
"ipfs": "^0.28.2",
4243
"pre-commit": "^1.2.2",
4344
"safe-buffer": "^5.1.1",

test/stat.spec.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
const chai = require('chai')
55
chai.use(require('dirty-chai'))
66
const expect = chai.expect
7+
const fs = require('fs')
8+
const path = require('path')
79

810
const {
911
createMfs,
@@ -14,11 +16,19 @@ describe('stat', function () {
1416
this.timeout(30000)
1517

1618
let mfs
19+
let smallFile
20+
let largeFile
1721

1822
before(() => {
19-
return createMfs()
20-
.then(instance => {
23+
return Promise.all([
24+
createMfs(),
25+
fs.readFile(path.join(__dirname, 'fixtures', 'small-file.txt')),
26+
fs.readFile(path.join(__dirname, 'fixtures', 'large-file.jpg'))
27+
])
28+
.then(([instance, smallFileBuffer, largeFileBuffer]) => {
2129
mfs = instance
30+
smallFile = smallFileBuffer
31+
largeFile = largeFileBuffer
2232
})
2333
})
2434

@@ -93,7 +103,33 @@ describe('stat', function () {
93103

94104
})
95105

96-
it.skip('stats a file', () => {
106+
it('stats a small file', () => {
107+
const filePath = '/stat/small-file.txt'
97108

109+
return mfs.write(filePath, smallFile, {
110+
parents: true
111+
})
112+
.then(() => mfs.stat(filePath))
113+
.then((stats) => {
114+
expect(stats.size).to.equal(smallFile.length)
115+
expect(stats.cumulativeSize).to.equal(21)
116+
expect(stats.childBlocks).to.equal(0)
117+
expect(stats.type).to.equal('file')
118+
})
119+
})
120+
121+
it('stats a large file', () => {
122+
const filePath = '/stat/large-file.txt'
123+
124+
return mfs.write(filePath, largeFile, {
125+
parents: true
126+
})
127+
.then(() => mfs.stat(filePath))
128+
.then((stats) => {
129+
expect(stats.size).to.equal(largeFile.length)
130+
expect(stats.cumulativeSize).to.equal(490800)
131+
expect(stats.childBlocks).to.equal(2)
132+
expect(stats.type).to.equal('file')
133+
})
98134
})
99135
})

test/write.spec.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const chai = require('chai')
55
chai.use(require('dirty-chai'))
66
const expect = chai.expect
77
const path = require('path')
8-
const fs = require('fs')
8+
const fs = require('fs-extra')
99

1010
const {
1111
createMfs
@@ -15,11 +15,16 @@ describe('write', function () {
1515
this.timeout(30000)
1616

1717
let mfs
18+
let smallFile
1819

1920
before(() => {
20-
return createMfs()
21-
.then(instance => {
21+
return Promise.all([
22+
createMfs(),
23+
fs.readFile(path.join(__dirname, 'fixtures', 'small-file.txt'))
24+
])
25+
.then(([instance, smallFileBuffer]) => {
2226
mfs = instance
27+
smallFile = smallFileBuffer
2328
})
2429
})
2530

@@ -28,7 +33,6 @@ describe('write', function () {
2833
})
2934

3035
it('writes a small file', () => {
31-
const smallFile = fs.readFileSync(path.join(__dirname, 'fixtures', 'small-file.txt'))
3236
const filePath = '/small-file.txt'
3337

3438
return mfs.write(filePath, smallFile)
@@ -39,7 +43,6 @@ describe('write', function () {
3943
})
4044

4145
it('writes a deeply nested small file', () => {
42-
const smallFile = fs.readFileSync(path.join(__dirname, 'fixtures', 'small-file.txt'))
4346
const filePath = '/foo/bar/baz/qux/quux/garply/small-file.txt'
4447

4548
return mfs.write(filePath, smallFile, {

0 commit comments

Comments
 (0)