mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-26 17:09:11 -06:00
* 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
54 lines
1.3 KiB
JavaScript
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
|
|
})
|
|
})
|
|
})
|
|
})
|