forked from statianzo/webpack-livereload-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
99 lines (91 loc) · 2.38 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var test = require('tape');
var LiveReloadPlugin = require('./index');
test('default options', function(t) {
var plugin = new LiveReloadPlugin();
t.equal(plugin.port, 35729);
t.equal(plugin.ignore, null);
t.equal(plugin.isRunning, false);
t.equal(plugin.quiet, false);
t.end();
});
test('not running', function(t) {
var plugin = new LiveReloadPlugin();
t.equal(plugin.isRunning, false);
t.end();
});
test('running after start', function(t) {
var plugin = new LiveReloadPlugin();
plugin.start(null, function() {
t.notLooseEqual(plugin.server, null);
t.ok(plugin.isRunning);
plugin.server.on('close', function() {
t.end();
});
plugin.server.close();
});
});
test('notifies when done', function(t) {
var plugin = new LiveReloadPlugin();
var stats = {
compilation: {
assets: {'b.js': '123', 'a.js': '456', 'c.css': '789'},
hash: 'hash',
children: []
}
};
plugin.server = {
notifyClients: function(files) {
t.deepEqual(files.sort(), ['a.js', 'b.js', 'c.css']);
t.equal(plugin.lastHash, stats.compilation.hash);
t.end();
}
};
plugin.done(stats);
});
test('filters out ignored files', function(t) {
var plugin = new LiveReloadPlugin({
ignore: /\.css$/
});
var stats = {
compilation: {
assets: {'b.js': '123', 'a.js': '456', 'c.css': '789'},
children: []
}
};
plugin.server = {
notifyClients: function(files) {
t.deepEqual(files.sort(), ['a.js', 'b.js']);
t.end();
}
};
plugin.done(stats);
});
test('children trigger notification', function(t) {
var plugin = new LiveReloadPlugin();
var stats = {
compilation: {
assets: {'b.js': '123', 'a.js': '456', 'c.css': '789'},
hash: null,
children: [{hash:'hash'}]
}
};
plugin.server = {
notifyClients: function(files) {
t.deepEqual(plugin.lastChildHashes, stats.compilation.children.map(function(child) {
return child.hash;
}));
t.end();
}
};
plugin.done(stats);
});
test('autoloadJs hostname defaults to location.hostname', function(t) {
var plugin = new LiveReloadPlugin();
t.assert(plugin.autoloadJs().match(/ \+ location\.hostname \+ /));
t.end();
});
test('autoloadJs contains hostname option', function(t) {
var plugin = new LiveReloadPlugin({hostname: 'example.com'});
t.assert(plugin.autoloadJs().match(/example.com/));
t.end();
});