refactor: remove mock-fs from dev dependency

This commit is contained in:
harttle
2019-02-19 22:28:27 +08:00
parent f432aade6a
commit 852c6ad453
70 changed files with 711 additions and 795 deletions
+47
View File
@@ -0,0 +1,47 @@
import fs from 'src/fs/node'
import * as path from 'path'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import { mock, restore } from 'test/stub/mockfs'
use(chaiAsPromised)
describe('fs', function () {
before(() => mock({
'/foo/bar.html': 'bar',
'/un-readable.html': { mode: '0000', content: '' }
}))
after(restore)
describe('#resolve()', function () {
it('should resolve based on root', async function () {
const filepath = fs.resolve('/foo', 'bar.html', '.liquid')
const expected = path.resolve('/foo/bar.html')
return expect(filepath).to.equal(expected)
})
it('should add extension if it has no extension', async function () {
const filepath = fs.resolve('/foo', 'bar', '.liquid')
const expected = path.resolve('/foo/bar.liquid')
return expect(filepath).to.equal(expected)
})
})
describe('#exists', () => {
it('should resolve as false if not exists', async () => {
const result = await fs.exists('/foo/foo.html')
return expect(result).to.be.false
})
it('should resolve as true if exists', async () => {
const result = await fs.exists('/foo/bar.html')
return expect(result).to.be.true
})
})
describe('#readFile', function () {
it('should throw when not exist', function () {
return expect(fs.readFile('/foo/foo.html')).to.rejectedWith('ENOENT')
})
it('should throw when file not readable', function () {
return expect(fs.readFile('/un-readable.html')).to
.be.rejectedWith(/EACCES/)
})
})
})