chore(TypeScript): remove mock-fs

This commit is contained in:
harttle
2019-02-17 21:37:13 +08:00
parent aa49b4f117
commit f432aade6a
11 changed files with 57 additions and 57 deletions
+2 -4
View File
@@ -1,6 +1,6 @@
import Liquid from '../../src/liquid'
import * as mock from 'mock-fs'
import * as chai from 'chai'
import { mock, restore } from 'test/stub/mockfs'
const expect = chai.expect
@@ -36,9 +36,7 @@ describe('Liquid', function () {
'/root/foo': 'foo'
})
})
after(function () {
mock.restore()
})
after(restore)
it('should render single template', function (done) {
render.call({ root: '.' }, 'foo', null, (err, result) => {
if (err) return done(err)
+3 -5
View File
@@ -1,6 +1,6 @@
import { expect } from 'chai'
import * as mock from 'mock-fs'
import Liquid from '../../../src/liquid'
import Liquid from 'src/liquid'
import { mock, restore } from 'test/stub/mockfs'
describe('LiquidOptions#cache', function () {
let engine
@@ -11,9 +11,7 @@ describe('LiquidOptions#cache', function () {
})
mock({ '/root/files/foo.html': 'foo' })
})
afterEach(function () {
mock.restore()
})
afterEach(restore)
it('should be disabled by default', function () {
return engine.renderFile('files/foo')
.then(x => expect(x).to.equal('foo'))
+2 -4
View File
@@ -1,6 +1,6 @@
import Liquid from 'src/liquid'
import { expect } from 'chai'
import * as mock from 'mock-fs'
import { mock, restore } from 'test/stub/mockfs'
describe('tags/include', function () {
let liquid
@@ -10,9 +10,7 @@ describe('tags/include', function () {
extname: '.html'
})
})
afterEach(function () {
mock.restore()
})
afterEach(restore)
it('should support include', async function () {
mock({
'/current.html': 'bar{% include "bar/foo.html" %}bar',
+2 -4
View File
@@ -1,6 +1,6 @@
import Liquid from 'src/liquid'
import { expect } from 'chai'
import * as mock from 'mock-fs'
import { mock, restore } from 'test/stub/mockfs'
describe('tags/layout', function () {
let liquid
@@ -10,9 +10,7 @@ describe('tags/layout', function () {
extname: '.html'
})
})
afterEach(function () {
mock.restore()
})
afterEach(restore)
it('should throw when block not closed', function () {
mock({
+4 -18
View File
@@ -1,29 +1,15 @@
import { resolve } from '../../src/parser/template'
import * as path from 'path'
import { fs } from 'src/parser/template'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import { mock, restore } from '../stub/mockfs'
use(chaiAsPromised)
describe('template', function () {
let readFile, stat
before(function () {
readFile = fs.readFile
stat = fs.stat
fs.readFile = async function (file) {
if (file === '/foo/bar.html') return 'bar'
throw new Error('NOENT')
}
fs.stat = async function (file) {
if (file === '/foo/bar.html') return { type: 'file' }
throw new Error('NOENT')
}
})
after(function () {
fs.readFile = readFile
fs.stat = stat
})
before(() => mock({ '/foo/bar.html': 'bar' }))
after(restore)
describe('#resolve()', function () {
it('should resolve based on root', async function () {
const filepath = await resolve('bar.html', '/foo', { root: [] })
+5 -7
View File
@@ -1,7 +1,7 @@
import { expect } from 'chai'
import Liquid from 'src/liquid'
import * as mock from 'mock-fs'
import * as path from 'path'
import { mock, restore } from 'test/stub/mockfs'
let engine = new Liquid()
const strictEngine = new Liquid({
@@ -10,9 +10,7 @@ const strictEngine = new Liquid({
})
describe('error', function () {
afterEach(function () {
mock.restore()
})
afterEach(restore)
describe('TokenizationError', function () {
it('should throw TokenizationError when tag illegal', async function () {
@@ -66,7 +64,7 @@ describe('error', function () {
'/foo.html': html
})
const err = await expect(engine.renderFile('/foo.html')).be.rejected
mock.restore()
restore()
expect(err.name).to.equal('TokenizationError')
expect(err.file).to.equal(path.resolve('/foo.html'))
})
@@ -207,7 +205,7 @@ describe('error', function () {
'/foo.html': html
})
const err = await expect(engine.renderFile('/foo.html')).be.rejected
mock.restore()
restore()
console.log(err, err.name)
expect(err.name).to.equal('RenderError')
expect(err.file).to.equal(path.resolve('/foo.html'))
@@ -299,7 +297,7 @@ describe('error', function () {
'/foo.html': html
})
const err = await expect(engine.renderFile('/foo.html')).be.rejected
mock.restore()
restore()
expect(err.name).to.equal('ParseError')
expect(err.file).to.equal(path.resolve('/foo.html'))
})