1 | var expect = require('chai').expect;
|
2 | var extend = require('util')._extend;
|
3 | var path = require('path');
|
4 |
|
5 | var Plugin = require('../index');
|
6 |
|
7 | describe('Plugin', function() {
|
8 |
|
9 | beforeEach(function() {
|
10 | this.subject = function(config) {
|
11 | return new Plugin({ persistent: true, plugins: { autoReload: config || {} } })
|
12 | };
|
13 | });
|
14 |
|
15 | it('should be an object', function() {
|
16 | expect(this.subject()).to.be.ok;
|
17 | });
|
18 |
|
19 | it('should has #onCompile method', function() {
|
20 | expect(this.subject().onCompile).to.be.an.instanceof(Function);
|
21 | });
|
22 |
|
23 | describe('SSL support', function() {
|
24 | it('should not start an HTTPS server', function() {
|
25 | var plugin = this.subject();
|
26 | expect(plugin.ssl).to.not.be.ok;
|
27 | expect(plugin.httpsServer).to.be.undefined;
|
28 | });
|
29 |
|
30 | context('keyPath and certPath present', function() {
|
31 | var sslOptions = {
|
32 | enabled: true,
|
33 | keyPath: path.join(__dirname, './lvh.me.key'),
|
34 | certPath: path.join(__dirname, './lvh.me.cert')
|
35 | };
|
36 |
|
37 | it('should start an HTTPS server', function() {
|
38 | var plugin = this.subject(sslOptions);
|
39 | expect(plugin).to.be.ok;
|
40 | expect(plugin.ssl).to.be.true;
|
41 | expect(plugin.httpsServer).to.be.ok;
|
42 | });
|
43 |
|
44 | context('plugin disabled', function() {
|
45 | it('should not start an HTTPS server', function() {
|
46 | var plugin = this.subject(extend(sslOptions, { enabled: false }));
|
47 | expect(plugin.ssl).to.be.true;
|
48 | expect(plugin.httpsServer).to.be.undefined;
|
49 | });
|
50 | });
|
51 | });
|
52 | });
|
53 |
|
54 | describe('with match option', function () {
|
55 | it('matches "stylesheet" by default', function() {
|
56 | var messages = [];
|
57 | var plugin = this.subject();
|
58 | plugin.connections = [ mockConnection(msg => messages.push(msg)) ];
|
59 | plugin.onCompile([ { path: 'abc.css' } ]);
|
60 | expect(messages).to.eql([ 'stylesheet' ]);
|
61 | });
|
62 |
|
63 | it('matches "javascript" by default', function() {
|
64 | var messages = [];
|
65 | var plugin = this.subject({ liveJs: true });
|
66 | plugin.connections = [ mockConnection(msg => messages.push(msg)) ];
|
67 | plugin.onCompile([ { path: 'abc.js' } ]);
|
68 | expect(messages).to.eql([ 'javascript', 'stylesheet' ]);
|
69 | });
|
70 |
|
71 | it('matches "page" for unknowns', function() {
|
72 | var messages = [];
|
73 | var plugin = this.subject();
|
74 | plugin.connections = [ mockConnection(msg => messages.push(msg)) ];
|
75 | plugin.onCompile([ { path: 'abc.xyz' } ]);
|
76 | expect(messages).to.eql([ 'page' ]);
|
77 | });
|
78 |
|
79 | it('honors match.stylesheets', function() {
|
80 | var messages = [];
|
81 | var plugin = this.subject({ match: { stylesheets: '*.scss' } });
|
82 | plugin.connections = [ mockConnection(msg => messages.push(msg)) ];
|
83 | plugin.onCompile([ { path: 'abc.scss' } ]);
|
84 | expect(messages).to.eql([ 'stylesheet' ]);
|
85 | });
|
86 |
|
87 | it('honors match.javascripts', function() {
|
88 | var messages = [];
|
89 | var plugin = this.subject({ match: { javascripts: '*.jsx' }, liveJs: true });
|
90 | plugin.connections = [ mockConnection(msg => messages.push(msg)) ];
|
91 | plugin.onCompile([ { path: 'abc.jsx' } ]);
|
92 | expect(messages).to.eql([ 'javascript', 'stylesheet' ]);
|
93 | });
|
94 |
|
95 | function mockConnection (fn) {
|
96 | return { readyState: 1, send: fn };
|
97 | }
|
98 | });
|
99 | });
|