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