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