UNPKG

5.3 kBJavaScriptView Raw
1var Lab = require('lab');
2var Moonboots = require('..');
3var domain = require('domain');
4var moonboots;
5
6Lab.experiment('error states', function () {
7 Lab.test('missing main options', function (done) {
8 function initBad() {
9 moonboots = new Moonboots({});
10 }
11 Lab.expect(initBad).to.throw(Error);
12 done();
13 });
14 Lab.test('invalid options', function (done) {
15 function initEmpty() {
16 moonboots = new Moonboots();
17 }
18 Lab.expect(initEmpty).to.throw(Error);
19 done();
20 });
21 Lab.test('invalid build directory', function (done) {
22 moonboots = new Moonboots({
23 main: __dirname + '/../fixtures/app/app.js',
24 stylesheets: [
25 __dirname + '/../fixtures/stylesheets/style.css'
26 ],
27 buildDirectory: __dirname + '/nonexistant'
28 });
29 moonboots.on('ready', function () {
30 var context = moonboots.htmlContext();
31 Lab.expect(context.jsFileName).to.equal('app.794c89f5.min.js');
32 done();
33 });
34 });
35 Lab.test('unreadable build js file', function (done) {
36 moonboots = new Moonboots({
37 main: __dirname + '/../fixtures/app/app.js',
38 stylesheets: [
39 __dirname + '/../fixtures/stylesheets/style.css'
40 ],
41 buildDirectory: __dirname + '/../fixtures/build1'
42 });
43 moonboots.on('ready', function () {
44 var context = moonboots.htmlContext();
45 Lab.expect(context.jsFileName).to.equal('app.794c89f5.min.js');
46 done();
47 });
48 });
49 Lab.test('unreadable build css file', function (done) {
50 moonboots = new Moonboots({
51 main: __dirname + '/../fixtures/app/app.js',
52 buildDirectory: __dirname + '/../fixtures/build2'
53 });
54 moonboots.on('ready', function () {
55 var context = moonboots.htmlContext();
56 Lab.expect(context.jsFileName).to.equal('app.248957fa.min.js');
57 done();
58 });
59 });
60 Lab.test('browserify error in development mode', function (done) {
61 moonboots = new Moonboots({
62 main: __dirname + '/../fixtures/app/badapp.js',
63 developmentMode: true
64 });
65 moonboots.on('ready', function () {
66 moonboots.jsSource(function (err, source) {
67 Lab.expect(source.indexOf('document.write'), 'inline error').to.equal(0);
68 Lab.expect(source.indexOf("Error: Cannot find module 'not-a-module' from"), 'inline error').to.not.equal(-1);
69 done();
70 });
71 });
72 });
73 Lab.test('browserify error not in development mode should throw', function (done) {
74 var errDomain = domain.create();
75
76 errDomain.run(function () {
77 moonboots = new Moonboots({
78 main: __dirname + '/../fixtures/app/badapp.js'
79 });
80 });
81
82 errDomain.on('error', function (e) {
83 Lab.expect(e.message).to.match(/not found/);
84 done();
85 });
86 });
87 Lab.test('beforeBuildJS error in development mode', function (done) {
88 var errMsg = 'This is a before build error!';
89 moonboots = new Moonboots({
90 main: __dirname + '/../fixtures/app/app.js',
91 developmentMode: true,
92 beforeBuildJS: function (cb) {
93 cb(new Error(errMsg));
94 }
95 });
96 moonboots.on('ready', function () {
97 moonboots.jsSource(function (err, source) {
98 Lab.expect(source.indexOf('document.write'), 'inline error').to.equal(0);
99 Lab.expect(source.indexOf(errMsg), 'inline error').to.not.equal(-1);
100 done();
101 });
102 });
103 });
104 Lab.test('beforeBuildJS errors without an error object', function (done) {
105 var errMsg = 'This is a before build error!';
106 var errMsgKey = 'errorMessage';
107 moonboots = new Moonboots({
108 main: __dirname + '/../fixtures/app/app.js',
109 developmentMode: true,
110 beforeBuildJS: function (cb) {
111 var err = {};
112 err[errMsgKey] = errMsg;
113 cb(err);
114 }
115 });
116 moonboots.on('ready', function () {
117 moonboots.jsSource(function (err, source) {
118 Lab.expect(source.indexOf('document.write'), 'inline error').to.equal(0);
119 Lab.expect(source.indexOf(errMsg), 'inline error').to.not.equal(-1);
120 Lab.expect(source.indexOf(errMsgKey), 'inline error').to.not.equal(-1);
121 done();
122 });
123 });
124 });
125 Lab.test('beforeBuildJS error not in development mode should throw', function (done) {
126 var errDomain = domain.create();
127 var errMsg = 'This is a before build error!';
128
129 errDomain.run(function () {
130 moonboots = new Moonboots({
131 main: __dirname + '/../fixtures/app/app.js',
132 beforeBuildJS: function (cb) {
133 cb(new Error(errMsg));
134 }
135 });
136 });
137
138 errDomain.on('error', function (e) {
139 Lab.expect(e.message).to.equal(errMsg);
140 done();
141 });
142 });
143});