mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-19 14:30:38 -07:00
refactor: remove mock-fs from dev dependency
This commit is contained in:
+16
-37
@@ -1,16 +1,19 @@
|
||||
import { expect } from 'chai'
|
||||
import * as request from 'supertest'
|
||||
import * as express from 'express'
|
||||
import { mock, restore } from 'test/stub/mockfs'
|
||||
import { resolve } from 'path'
|
||||
import Liquid from '../..'
|
||||
|
||||
describe('express()', function () {
|
||||
var app, engine
|
||||
const root = resolve(__dirname, '../stub/root')
|
||||
const views = resolve(__dirname, '../stub/views')
|
||||
const partials = resolve(__dirname, '../stub/partials')
|
||||
let app, engine
|
||||
|
||||
beforeEach(function () {
|
||||
app = express()
|
||||
engine = new Liquid({
|
||||
root: '/root',
|
||||
root,
|
||||
extname: '.html'
|
||||
})
|
||||
|
||||
@@ -24,14 +27,18 @@ describe('express()', function () {
|
||||
file: req.params.file
|
||||
}))
|
||||
})
|
||||
after(restore)
|
||||
it('should render express views', function (done) {
|
||||
mock({ '/views/name.html': 'My name is {{name}}.' })
|
||||
app.set('views', ['/views'])
|
||||
it('should respect express views(array)', function (done) {
|
||||
app.set('views', [views])
|
||||
request(app).get('/name')
|
||||
.expect('My name is harttle.')
|
||||
.expect(200, done)
|
||||
})
|
||||
it('should respect express views(string)', function (done) {
|
||||
app.set('views', views)
|
||||
request(app).get('/include/bar')
|
||||
.expect('bar')
|
||||
.expect(200, done)
|
||||
})
|
||||
it('should pass error when file not found', function (done) {
|
||||
const view = {
|
||||
root: []
|
||||
@@ -49,41 +56,13 @@ describe('express()', function () {
|
||||
})
|
||||
})
|
||||
it('should respect root option when lookup', function (done) {
|
||||
mock({
|
||||
'/root/foo.html': 'foo',
|
||||
'/views/include.html': '{% include file %}'
|
||||
})
|
||||
app.set('views', ['/views'])
|
||||
app.set('views', [views])
|
||||
request(app).get('/include/foo')
|
||||
.expect('foo')
|
||||
.expect(200, done)
|
||||
})
|
||||
it('should respect express views (Array) when lookup', function (done) {
|
||||
mock({
|
||||
'/views/include.html': '{% include file %}',
|
||||
'/partials/bar.html': 'bar'
|
||||
})
|
||||
app.set('views', ['/views', '/partials'])
|
||||
request(app).get('/include/bar')
|
||||
.expect('bar')
|
||||
.expect(200, done)
|
||||
})
|
||||
it('should respect express views (String) when lookup', function (done) {
|
||||
mock({
|
||||
'/views/include.html': '{% include file %}',
|
||||
'/views/bar.html': 'bar'
|
||||
})
|
||||
app.set('views', '/views')
|
||||
request(app).get('/include/bar')
|
||||
.expect('bar')
|
||||
.expect(200, done)
|
||||
})
|
||||
it('should respect express views (undefined) when lookup', function (done) {
|
||||
const files = {}
|
||||
files[process.cwd() + '/views/include.html'] = '{% include file %}'
|
||||
files[process.cwd() + '/views/bar.html'] = 'bar'
|
||||
mock(files)
|
||||
|
||||
app.set('views', [views, partials])
|
||||
request(app).get('/include/bar')
|
||||
.expect('bar')
|
||||
.expect(200, done)
|
||||
|
||||
+25
-37
@@ -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\/"/)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user