Files
cypress/packages/server/test/unit/template_engine_spec.js
Tim Griesser 4626f7481c feat: ProjectLifecycleManager & general launchpad cleanup (#19347)
See #19347 for full summary

Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>
Co-authored-by: estrada9166 <estrada9166@hotmail.com>
Co-authored-by: Alejandro Estrada <estrada9166@gmail.com>
Co-authored-by: Jess <jess@jessicasachs.io>
2021-12-21 21:28:44 -05:00

55 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')
const { sinon } = require('../spec_helper')
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
})
})
})
})