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
+25 -37
View File
@@ -1,61 +1,53 @@
import { expect } from 'chai'
import Liquid from '../..'
import { mock, restore } from '../stub/mockfs'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import { resolve } from 'path'
use(chaiAsPromised)
describe('#renderFile()', function () {
var engine
const root = resolve(__dirname, '../stub/root')
const views = resolve(__dirname, '../stub/views')
let engine
beforeEach(function () {
engine = new Liquid({
root: '/root/',
root,
extname: '.html'
})
mock({
'/root/files/bar': 'bar',
'/root/files/foo.html': 'foo',
'/root/files/name.html': 'My name is {{name}}.',
'/un-readable.html': { mode: '0000' }
})
})
afterEach(restore)
it('should render file', async function () {
const html = await engine.renderFile('/root/files/foo.html', {})
const html = await engine.renderFile(resolve(root, 'foo.html'), {})
return expect(html).to.equal('foo')
})
it('should find files without extname', async function () {
var engine = new Liquid({ root: '/root' })
const html = await engine.renderFile('/root/files/bar', {})
var engine = new Liquid({ root })
const html = await engine.renderFile(resolve(root, 'bar'), {})
return expect(html).to.equal('bar')
})
it('should accept relative path', async function () {
const html = await engine.renderFile('files/foo.html')
const html = await engine.renderFile('foo.html')
return expect(html).to.equal('foo')
})
it('should resolve array as root', async function () {
engine = new Liquid({
root: ['/boo', '/root/'],
extname: '.html'
})
const html = await engine.renderFile('files/foo.html')
return expect(html).to.equal('foo')
})
it('should default root to cwd', async function () {
var files = {}
files[process.cwd() + '/foo.html'] = 'FOO'
mock(files)
it('should traverse root array', async function () {
engine = new Liquid({
root: ['/boo', root],
extname: '.html'
})
const html = await engine.renderFile('foo.html')
return expect(html).to.equal('FOO')
return expect(html).to.equal('foo')
})
it('should default root to cwd', async function () {
engine = new Liquid()
const html = await engine.renderFile('package.json')
return expect(html).to.contain('"name": "liquidjs"')
})
it('should render file with context', async function () {
const html = await engine.renderFile('/root/files/name.html', { name: 'harttle' })
const html = await engine.renderFile(resolve(views, 'name.html'), { name: 'harttle' })
return expect(html).to.equal('My name is harttle.')
})
it('should use default extname', async function () {
const html = await engine.renderFile('files/name', { name: 'harttle' })
return expect(html).to.equal('My name is harttle.')
const html = await engine.renderFile(resolve(root, 'foo'))
return expect(html).to.equal('foo')
})
it('should throw with lookup list when file not exist', function () {
engine = new Liquid({
@@ -63,10 +55,6 @@ describe('#renderFile()', function () {
extname: '.html'
})
return expect(engine.renderFile('/not/exist.html')).to
.be.rejectedWith(/failed to lookup \/not\/exist.html in: \/boo,\/root\//i)
})
it('should throw when file not readable', function () {
return expect(engine.renderFile('/un-readable.html')).to
.be.rejectedWith(/EACCES/)
.be.rejectedWith(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
})
})