1 |
|
2 |
|
3 | 'use strict'
|
4 |
|
5 | let chai = require('chai')
|
6 | let config = require('..')
|
7 | let path = require('path')
|
8 |
|
9 | chai.use(require('chai-as-promised'))
|
10 | let assert = chai.assert
|
11 | let fixture = path.resolve.bind(path, __dirname, 'fixtures')
|
12 |
|
13 | describe('mako-config', function () {
|
14 | it('should resolve entries relative to the config file', function () {
|
15 | return config(fixture('simple/mako.json')).then(function (config) {
|
16 | assert.deepEqual(config.entries, [ fixture('simple/index.html') ])
|
17 | })
|
18 | })
|
19 |
|
20 | it('should resolve entries from glob patterns', function () {
|
21 | return config(fixture('glob/mako.json')).then(function (config) {
|
22 | assert.deepEqual(config.entries, [
|
23 | fixture('glob/a.txt'),
|
24 | fixture('glob/b.txt'),
|
25 | fixture('glob/c.txt')
|
26 | ])
|
27 | })
|
28 | })
|
29 |
|
30 | it('should expand relative root to absolute path', function () {
|
31 | return config(fixture('root/mako.json')).then(function (config) {
|
32 | assert.strictEqual(config.root, fixture('root/dir'))
|
33 | })
|
34 | })
|
35 |
|
36 | it('should include concurrency if specified', function () {
|
37 | return config(fixture('concurrency/mako.json')).then(function (config) {
|
38 | assert.strictEqual(config.concurrency, 250)
|
39 | })
|
40 | })
|
41 |
|
42 | it('should prune out entries that do not exist', function () {
|
43 | return config(fixture('missing-entry/mako.json')).then(function (config) {
|
44 | assert.deepEqual(config.entries, [])
|
45 | })
|
46 | })
|
47 |
|
48 | it('should allow the list of entries to be pre-empted', function () {
|
49 | return config(fixture('alternate-entries/mako.json'), [ 'index.md' ]).then(function (config) {
|
50 | assert.deepEqual(config.entries, [ fixture('alternate-entries/index.md') ])
|
51 | })
|
52 | })
|
53 |
|
54 | it('should include an empty array of plugins if not specified', function () {
|
55 | return config(fixture('simple/mako.json')).then(function (config) {
|
56 | assert.deepEqual(config.plugins, [])
|
57 | })
|
58 | })
|
59 |
|
60 | it('should resolve plugins', function () {
|
61 | return config(fixture('plugin/mako.json')).then(function (config) {
|
62 | assert.deepEqual(config.plugins, [ 'vendor', 'local' ])
|
63 | })
|
64 | })
|
65 |
|
66 | it('should pass arguments to plugins', function () {
|
67 | return config(fixture('plugin-options/mako.json')).then(function (config) {
|
68 | assert.deepEqual(config.plugins, [
|
69 | [ 'local', 'a', 'b', 'c' ]
|
70 | ])
|
71 | })
|
72 | })
|
73 |
|
74 | it('should include the source file path', function () {
|
75 | let file = fixture('simple/mako.json')
|
76 | return config(file).then(function (config) {
|
77 | assert.strictEqual(config.path, file)
|
78 | })
|
79 | })
|
80 |
|
81 | it('should include the original json structure', function () {
|
82 | return config(fixture('glob/mako.json')).then(function (config) {
|
83 | assert.deepEqual(config.original, {
|
84 | entries: [ '*.txt' ]
|
85 | })
|
86 | })
|
87 | })
|
88 |
|
89 | it('should throw when the file is missing', function () {
|
90 | return assert.isRejected(config('does-not-exist'))
|
91 | })
|
92 |
|
93 | it('should throw when the config file has invalid JSON', function () {
|
94 | return assert.isRejected(config(fixture('invalid-json/mako.json')))
|
95 | })
|
96 |
|
97 | context('with NODE_ENV', function () {
|
98 | beforeEach(function () {
|
99 | delete process.env.NODE_ENV
|
100 | })
|
101 |
|
102 | it('should assume development when not otherwise specified', function () {
|
103 | return config(fixture('env/mako.json')).then(function (config) {
|
104 | assert.deepEqual(config.plugins, [ 'default', 'dev' ])
|
105 | })
|
106 | })
|
107 |
|
108 | it('should merge additional entries', function () {
|
109 | process.env.NODE_ENV = 'production'
|
110 |
|
111 | return config(fixture('env/mako.json')).then(function (config) {
|
112 | assert.deepEqual(config.entries, [ fixture('env/index.html'), fixture('env/production.js') ])
|
113 | })
|
114 | })
|
115 |
|
116 | it('should merge additional plugins', function () {
|
117 | process.env.NODE_ENV = 'production'
|
118 |
|
119 | return config(fixture('env/mako.json')).then(function (config) {
|
120 | assert.deepEqual(config.plugins, [ 'default', 'prod' ])
|
121 | })
|
122 | })
|
123 |
|
124 | it('should handle an empty env config without failing', function () {
|
125 | return config(fixture('empty-env/mako.json')).then(function (config) {
|
126 | assert.deepEqual(config.entries, [ fixture('empty-env/index.html') ])
|
127 | assert.deepEqual(config.plugins, [ 'default' ])
|
128 | })
|
129 | })
|
130 | })
|
131 | })
|
132 |
|
133 | describe('sync', function () {
|
134 | it('should resolve entries relative to the config file', function () {
|
135 | let results = config.sync(fixture('simple/mako.json'))
|
136 | assert.deepEqual(results.entries, [ fixture('simple/index.html') ])
|
137 | })
|
138 |
|
139 | it('should resolve entries from glob patterns', function () {
|
140 | let results = config.sync(fixture('glob/mako.json'))
|
141 | assert.deepEqual(results.entries, [
|
142 | fixture('glob/a.txt'),
|
143 | fixture('glob/b.txt'),
|
144 | fixture('glob/c.txt')
|
145 | ])
|
146 | })
|
147 |
|
148 | it('should expand relative root to absolute path', function () {
|
149 | let results = config.sync(fixture('root/mako.json'))
|
150 | assert.strictEqual(results.root, fixture('root/dir'))
|
151 | })
|
152 |
|
153 | it('should include concurrency if specified', function () {
|
154 | let results = config.sync(fixture('concurrency/mako.json'))
|
155 | assert.strictEqual(results.concurrency, 250)
|
156 | })
|
157 |
|
158 | it('should prune out entries that do not exist', function () {
|
159 | let results = config.sync(fixture('missing-entry/mako.json'))
|
160 | assert.deepEqual(results.entries, [])
|
161 | })
|
162 |
|
163 | it('should allow the list of entries to be pre-empted', function () {
|
164 | let results = config.sync(fixture('alternate-entries/mako.json'), [ 'index.md' ])
|
165 | assert.deepEqual(results.entries, [ fixture('alternate-entries/index.md') ])
|
166 | })
|
167 |
|
168 | it('should include an empty array of plugins if not specified', function () {
|
169 | let results = config.sync(fixture('simple/mako.json'))
|
170 | assert.deepEqual(results.plugins, [])
|
171 | })
|
172 |
|
173 | it('should resolve plugins', function () {
|
174 | let results = config.sync(fixture('plugin/mako.json'))
|
175 | assert.deepEqual(results.plugins, [ 'vendor', 'local' ])
|
176 | })
|
177 |
|
178 | it('should pass arguments to plugins', function () {
|
179 | let results = config.sync(fixture('plugin-options/mako.json'))
|
180 | assert.deepEqual(results.plugins, [
|
181 | [ 'local', 'a', 'b', 'c' ]
|
182 | ])
|
183 | })
|
184 |
|
185 | it('should include the source file path', function () {
|
186 | let file = fixture('simple/mako.json')
|
187 | let results = config.sync(file)
|
188 | assert.strictEqual(results.path, file)
|
189 | })
|
190 |
|
191 | it('should include the original json structure', function () {
|
192 | let results = config.sync(fixture('glob/mako.json'))
|
193 | assert.deepEqual(results.original, {
|
194 | entries: [ '*.txt' ]
|
195 | })
|
196 | })
|
197 |
|
198 | it('should throw when the file is missing', function () {
|
199 | return assert.throws(() => config.sync('does-not-exist'))
|
200 | })
|
201 |
|
202 | it('should throw when the config file has invalid JSON', function () {
|
203 | return assert.throws(() => config.sync(fixture('invalid-json/mako.json')))
|
204 | })
|
205 |
|
206 | context('with NODE_ENV', function () {
|
207 | beforeEach(function () {
|
208 | delete process.env.NODE_ENV
|
209 | })
|
210 |
|
211 | it('should assume development when not otherwise specified', function () {
|
212 | let results = config.sync(fixture('env/mako.json'))
|
213 | assert.deepEqual(results.plugins, [ 'default', 'dev' ])
|
214 | })
|
215 |
|
216 | it('should merge additional entries', function () {
|
217 | process.env.NODE_ENV = 'production'
|
218 |
|
219 | let results = config.sync(fixture('env/mako.json'))
|
220 | assert.deepEqual(results.entries, [ fixture('env/index.html'), fixture('env/production.js') ])
|
221 | })
|
222 |
|
223 | it('should merge additional plugins', function () {
|
224 | process.env.NODE_ENV = 'production'
|
225 |
|
226 | let results = config.sync(fixture('env/mako.json'))
|
227 | assert.deepEqual(results.plugins, [ 'default', 'prod' ])
|
228 | })
|
229 |
|
230 | it('should handle an empty env config without failing', function () {
|
231 | let results = config.sync(fixture('empty-env/mako.json'))
|
232 | assert.deepEqual(results.entries, [ fixture('empty-env/index.html') ])
|
233 | assert.deepEqual(results.plugins, [ 'default' ])
|
234 | })
|
235 | })
|
236 | })
|