1 |
|
2 |
|
3 | 'use strict'
|
4 |
|
5 | let chai = require('chai')
|
6 | let cp = require('child_process')
|
7 | let fs = require('fs')
|
8 | let path = require('path')
|
9 | let rm = require('rimraf').sync
|
10 |
|
11 | chai.use(require('chai-as-promised'))
|
12 | let assert = chai.assert
|
13 | let fixture = path.resolve.bind(path, __dirname, 'fixtures')
|
14 |
|
15 | describe('mako cli', function () {
|
16 | afterEach(function () {
|
17 | rm(fixture('*/build'))
|
18 | rm(fixture('*/mako.cache'))
|
19 | })
|
20 |
|
21 | it('should build a simple project', function () {
|
22 | return run('simple').then(() => {
|
23 | let file = fixture('simple/build/index.js')
|
24 | assert.isTrue(fs.existsSync(file))
|
25 | })
|
26 | })
|
27 |
|
28 | it('should not save a cached tree', function () {
|
29 | return run('simple').then(() => {
|
30 | let file = fixture('simple/mako.cache')
|
31 | assert.isFalse(fs.existsSync(file))
|
32 | })
|
33 | })
|
34 |
|
35 | it('should enable the cache', function () {
|
36 | return run('simple', '--cache').then(() => {
|
37 | let file = fixture('simple/mako.cache')
|
38 | assert.isTrue(fs.existsSync(file))
|
39 | })
|
40 | })
|
41 |
|
42 | it('should expand glob patterns in the config', function () {
|
43 | return run('entry-globs').then(() => {
|
44 | let files = [
|
45 | fixture('entry-globs/build/a.js'),
|
46 | fixture('entry-globs/build/b.js'),
|
47 | fixture('entry-globs/build/c.js')
|
48 | ]
|
49 |
|
50 | files.forEach(function (file) {
|
51 | assert.isTrue(fs.existsSync(file))
|
52 | })
|
53 | })
|
54 | })
|
55 |
|
56 | it('should only run for the entries specified as arguments', function () {
|
57 | return run('entry-globs', 'a.js').then(() => {
|
58 | let yes = [
|
59 | fixture('entry-globs/build/a.js')
|
60 | ]
|
61 |
|
62 | let no = [
|
63 | fixture('entry-globs/build/b.js'),
|
64 | fixture('entry-globs/build/c.js')
|
65 | ]
|
66 |
|
67 | yes.forEach(file => assert.isTrue(fs.existsSync(file)))
|
68 | no.forEach(file => assert.isFalse(fs.existsSync(file)))
|
69 | })
|
70 | })
|
71 |
|
72 | it('should allow passing config to plugins', function () {
|
73 | return run('plugin-config').then(() => {
|
74 |
|
75 | let file = fixture('plugin-config/build/sub/index.js')
|
76 | assert.isTrue(fs.existsSync(file))
|
77 | })
|
78 | })
|
79 |
|
80 | it('should fail when config does not exist', function () {
|
81 | return assert.isRejected(run('alternate-config'))
|
82 | })
|
83 |
|
84 | it('should allow specifying another config path', function () {
|
85 | return run('alternate-config', '--config build.json')
|
86 | })
|
87 | })
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | function run (name, args) {
|
97 | return new Promise(function (resolve, reject) {
|
98 | let cmd = path.resolve(__dirname, '../bin/mako')
|
99 | if (args) cmd += ' ' + args
|
100 | let options = { cwd: fixture(name) }
|
101 | cp.exec(cmd, options, function (err, stdout, stderr) {
|
102 | if (err) {
|
103 | reject(err)
|
104 | } else {
|
105 | resolve({ out: stdout, err: stderr })
|
106 | }
|
107 | })
|
108 | })
|
109 | }
|