forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate_engine_spec.js
More file actions
54 lines (41 loc) · 1.34 KB
/
template_engine_spec.js
File metadata and controls
54 lines (41 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
})
})
})
})