UNPKG

2.08 kBJavaScriptView Raw
1var request = require('supertest');
2var path = require('path');
3var liveServer = require('..').start({
4 root: path.join(__dirname, "data"),
5 port: 0,
6 open: false
7});
8
9describe('basic functional tests', function(){
10 it('should respond with index.html', function(done){
11 request(liveServer)
12 .get('/')
13 .expect('Content-Type', 'text/html; charset=UTF-8')
14 .expect(/hello world/i)
15 .expect(200, done);
16 });
17 it('should have injected script', function(done){
18 request(liveServer)
19 .get('/')
20 .expect('Content-Type', 'text/html; charset=UTF-8')
21 .expect(/<script [^]+?live reload enabled[^]+?<\/script>/i)
22 .expect(200, done);
23 });
24 it('should inject script when tags are in CAPS', function(done){
25 request(liveServer)
26 .get('/index-caps.htm')
27 .expect('Content-Type', 'text/html; charset=UTF-8')
28 .expect(/<script [^]+?live reload enabled[^]+?<\/script>/i)
29 .expect(200, done);
30 });
31 it('should inject to <head> when no <body>', function(done){
32 request(liveServer)
33 .get('/index-head.html')
34 .expect('Content-Type', 'text/html; charset=UTF-8')
35 .expect(/<script [^]+?live reload enabled[^]+?<\/script>/i)
36 .expect(200, done);
37 });
38 it('should inject also svg files', function(done){
39 request(liveServer)
40 .get('/test.svg')
41 .expect('Content-Type', 'image/svg+xml')
42 .expect(function(res) {
43 if (res.body.toString().indexOf("Live reload enabled") == -1)
44 throw new Error("injected code not found");
45 })
46 .expect(200, done);
47 });
48 it('should not inject html fragments', function(done){
49 request(liveServer)
50 .get('/fragment.html')
51 .expect('Content-Type', 'text/html; charset=UTF-8')
52 .expect(function(res) {
53 if (res.text.toString().indexOf("Live reload enabled") > -1)
54 throw new Error("injected code should not be found");
55 })
56 .expect(200, done);
57 });
58 xit('should have WebSocket connection', function(done){
59 done(); // todo
60 });
61 xit('should reload on page change', function(done){
62 done(); // todo
63 });
64 xit('should reload (without refreshing) on css change', function(done){
65 done(); // todo
66 });
67});