UNPKG

5.4 kBJavaScriptView Raw
1var Lab = require('lab');
2var Moonboots = require('..');
3var moonboots;
4
5var EXPECTED_JS_HASH = 'app.794c89f5.js';
6var EXPECTED_JS_MIN_HASH = 'app.794c89f5.min.js';
7
8Lab.experiment('js with default options', function () {
9 Lab.before(function (done) {
10 var options = {
11 main: __dirname + '/../fixtures/app/app.js',
12 jsFileName: 'app'
13 };
14 moonboots = new Moonboots(options);
15 moonboots.on('ready', done);
16 });
17 Lab.test('filename', function (done) {
18 Lab.expect(moonboots.jsFileName(), 'js filename').to.equal(EXPECTED_JS_MIN_HASH);
19 done();
20 });
21 /*
22 Lab.test('content', function (done) {
23 Lab.expect(moonboots.jsSource(), 'js source').to.equal('how do we even test this?');
24 done();
25 });
26 */
27});
28
29Lab.experiment('js with uglify options', function () {
30 Lab.before(function (done) {
31 var options = {
32 main: __dirname + '/../fixtures/app/app.js',
33 jsFileName: 'app',
34 uglify: {
35 mangle: false
36 }
37 };
38
39 moonboots = new Moonboots(options);
40 moonboots.on('ready', done);
41 });
42 Lab.test('filename', function (done) {
43 Lab.expect(moonboots.jsFileName(), 'js filename').to.equal(EXPECTED_JS_MIN_HASH);
44 done();
45 });
46});
47
48Lab.experiment('js with no minify', function () {
49 Lab.before(function (done) {
50 var options = {
51 main: __dirname + '/../fixtures/app/app.js',
52 jsFileName: 'app',
53 minify: false
54 };
55 moonboots = new Moonboots(options);
56 moonboots.on('ready', done);
57 });
58 Lab.test('filename', function (done) {
59 Lab.expect(moonboots.jsFileName(), 'js filename').to.equal(EXPECTED_JS_HASH);
60 done();
61 });
62 /*
63 Lab.test('content', function (done) {
64 Lab.expect(moonboots.jsSource(), 'js source').to.equal('how do we even test this?');
65 done();
66 });
67 */
68});
69
70Lab.experiment('js with .js already added', function () {
71 Lab.before(function (done) {
72 var options = {
73 main: __dirname + '/../fixtures/app/app.js',
74 jsFileName: 'app.js'
75 };
76 moonboots = new Moonboots(options);
77 moonboots.on('ready', done);
78 });
79 Lab.test('filename', function (done) {
80 Lab.expect(moonboots.jsFileName(), 'js filename').to.equal(EXPECTED_JS_MIN_HASH);
81 done();
82 });
83});
84
85Lab.experiment('modulesDir', function () {
86 Lab.before(function (done) {
87 var options = {
88 main: __dirname + '/../fixtures/app/app.js',
89 jsFileName: 'app',
90 modulesDir: __dirname + '/../fixtures/modules'
91 };
92 moonboots = new Moonboots(options);
93 moonboots.on('ready', done);
94 });
95 Lab.test('module foo is in source', function (done) {
96 moonboots.jsSource(function (err, js) {
97 Lab.expect(js, 'js source').to.contain('"foo"');
98 done();
99 });
100 });
101});
102
103Lab.experiment('transforms', function () {
104 var transformRan = 0;
105 Lab.before(function (done) {
106 var options = {
107 main: __dirname + '/../fixtures/app/app.js',
108 jsFileName: 'app',
109 browserify: {
110 transforms: [
111 function () {
112 var through = require('through');
113 transformRan++;
114 return through(
115 function write() {},
116 function _end() {
117 this.queue(null);
118 }
119 );
120 }
121 ]
122 }
123 };
124 moonboots = new Moonboots(options);
125 moonboots.on('ready', done);
126 });
127 Lab.test('ran', function (done) {
128 Lab.expect(transformRan).to.equal(1);
129 done();
130 });
131});
132
133
134Lab.experiment('transforms with transform option', function () {
135 var transformRan = 0;
136 Lab.before(function (done) {
137 var options = {
138 main: __dirname + '/../fixtures/app/app.js',
139 jsFileName: 'app',
140 browserify: {
141 transform: [
142 function () {
143 var through = require('through');
144 transformRan++;
145 return through(
146 function write() {},
147 function _end() {
148 this.queue(null);
149 }
150 );
151 }
152 ]
153 }
154 };
155 moonboots = new Moonboots(options);
156 moonboots.on('ready', done);
157 });
158 Lab.test('ran', function (done) {
159 Lab.expect(transformRan).to.equal(1);
160 done();
161 });
162});
163
164Lab.experiment('sync beforeBuildJS', function () {
165 var beforeRan = false;
166 Lab.before(function (done) {
167 var options = {
168 main: __dirname + '/../fixtures/app/app.js',
169 jsFileName: 'app',
170 minify: false,
171 beforeBuildJS: function () {
172 beforeRan = true;
173 }
174 };
175 moonboots = new Moonboots(options);
176 moonboots.on('ready', done);
177 });
178 Lab.test('ran', function (done) {
179 Lab.expect(beforeRan).to.equal(true);
180 done();
181 });
182});