UNPKG

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