Files
cypress/packages/server/test/unit/template_engine_spec.js
Brian Mann 91a4477ad0 replace handlebars with squirrelly (#5521)
* WIP: rip out handlebars and implement with squirrelly

- handle caching ourselves
- TODO: add tests, make sure escaping and all that jazz works

* fixes squirrelly template handling

* only fire mocha events when in run mode

* add unit tests for template engine rendering + caching
2019-10-30 02:21:53 -04:00

54 lines
1.3 KiB
JavaScript

require('../spec_helper')
const os = require('os')
const path = require('path')
const Bluebird = require('bluebird')
const { cache, render } = require('../../lib/template_engine')
const fs = require('../../lib/util/fs')
describe('lib/template_engine', () => {
it('renders and caches a template function', () => {
sinon.spy(fs, 'readFile')
expect(cache).to.deep.eq({})
const tmpPath = path.join(os.tmpdir(), 'index.html')
return fs
.writeFileAsync(tmpPath, 'My favorite template engine is {{favorite}}.')
.then(() => {
return Bluebird.fromCallback((cb) => {
const opts = {
favorite: 'Squirrelly',
}
return render(tmpPath, opts, cb)
})
})
.then((str) => {
expect(str).to.eq('My favorite template engine is Squirrelly.')
expect(fs.readFile).to.be.calledOnce
const compiledFn = cache[tmpPath]
expect(compiledFn).to.be.a('function')
return Bluebird.fromCallback((cb) => {
const opts = {
favorite: 'Squirrelly2',
}
return render(tmpPath, opts, cb)
})
.then((str) => {
expect(str).to.eq('My favorite template engine is Squirrelly2.')
expect(cache[tmpPath]).to.eq(compiledFn)
expect(fs.readFile).to.be.calledOnce
})
})
})
})