UNPKG

2.37 kBJavaScriptView Raw
1/**
2 * Test case for module:coz
3 * Runs with nodeunit.
4 */
5'use strict'
6
7const Coz = require('../lib/coz.js')
8const mkdirp = require('mkdirp')
9const co = require('co')
10const fs = require('fs')
11const injectmock = require('injectmock')
12const assert = require('assert')
13
14describe('coz', function () {
15 before((done) => {
16 // injectmock(console, 'log', injectmock.noop)
17 mkdirp.sync(`${__dirname}/../tmp`)
18 done()
19 })
20
21 after((done) => {
22 injectmock.restoreAll()
23 done()
24 })
25
26 it('Create coz.', (done) => {
27 let coz = new Coz()
28 assert.ok(coz)
29 done()
30 })
31
32 it('Do render.', async () => {
33 let coz = new Coz()
34 let src = `${__dirname}/../doc/mockups/mock-bud.bud`
35 await coz.render([
36 src
37 ], { verbose: true, prefix: 'hogehoge' })
38 })
39
40 it('Do render without options.', async () => {
41 let coz = new Coz()
42 let src = `${__dirname}/../doc/mockups/mock-bud.bud`
43 await coz.render([
44 src
45 ])
46 })
47
48 it('Do clean.', async () => {
49 let coz = new Coz()
50 let filename = `${__dirname}/../tmp/some_file.txt.bud`
51 require('fs').writeFileSync(filename, 'module.exports = {path:__filename}')
52 await coz.clean(filename)
53 })
54
55 it('With custom setup.', async () => {
56 let coz = new Coz()
57 let filename = `${__dirname}/../tmp/some_coz_file0008.txt`
58 await coz.render({
59 path: filename,
60 force: true,
61 mkdirp: true,
62 tmpl: '{{myCustomHelper baz}}',
63 setup: {
64 helpers: {
65 myCustomHelper(txt) {
66 return 'my-custom-' + txt
67 }
68 }
69 },
70 data: {
71 baz: 'quz'
72 }
73 })
74 let content = fs.readFileSync(filename).toString()
75 assert.equal('my-custom-quz', content.trim())
76 })
77
78 it('Do render with configuration.', async () => {
79 let configuration = require.resolve('../doc/mockups/mock-coz-configuration')
80 let coz = new Coz(configuration)
81 let filename = `${__dirname}/../tmp/some_file2.txt`
82 if (fs.existsSync(filename)) {
83 fs.unlinkSync(filename)
84 }
85 assert.ok(coz)
86 await coz.render({
87 path: filename,
88 force: true,
89 engine: 'myCustomEngine',
90 tmpl: 'foobarbaz'
91 })
92 fs.readFile(filename, function (err, content) {
93 assert.ifError(err)
94 assert.equal(String(content).trim(), 'renderByMyCustom')
95 })
96 })
97})
98
99/* global describe, before, after, it */