~stephen-stewart/+junk/add-grunt

« back to all changes in this revision

Viewing changes to node_modules/grunt-contrib-watch/node_modules/tiny-lr-fork/test/server.js

  • Committer: Stephen Stewart
  • Date: 2014-05-13 01:26:55 UTC
  • Revision ID: stephen.stewart@canonical.com-20140513012655-wx8xbwcdohofxoyj
add --production node_modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
var request = require('supertest');
 
3
var assert  = require('assert');
 
4
 
 
5
var Server = require('..').Server;
 
6
 
 
7
describe('tiny-lr', function() {
 
8
 
 
9
  beforeEach(function() {
 
10
    this.app = new Server;
 
11
    this.server = this.app.server;
 
12
  });
 
13
 
 
14
  describe('GET /', function() {
 
15
    it('respond with nothing, but respond', function(done){
 
16
      request(this.server)
 
17
        .get('/')
 
18
        .expect('Content-Type', /json/)
 
19
        .expect(/\{"tinylr":"Welcome","version":"0.0.[\d]+"\}/)
 
20
        .expect(200, done);
 
21
    });
 
22
 
 
23
    it('unknown route respond with proper 404 and error message', function(done){
 
24
      request(this.server)
 
25
        .get('/whatev')
 
26
        .expect('Content-Type', /json/)
 
27
        .expect('{"error":"not_found","reason":"no such route"}')
 
28
        .expect(404, done);
 
29
    });
 
30
  });
 
31
 
 
32
 
 
33
  describe('GET /changed', function() {
 
34
    it('with no clients, no files', function(done) {
 
35
      request(this.server)
 
36
        .get('/changed')
 
37
        .expect('Content-Type', /json/)
 
38
        .expect(/"clients":\[\]/)
 
39
        .expect(/"files":\[\]/)
 
40
        .expect(200, done);
 
41
    });
 
42
 
 
43
    it('with no clients, some files', function(done) {
 
44
      request(this.server)
 
45
        .get('/changed?files=gonna.css,test.css,it.css')
 
46
        .expect('Content-Type', /json/)
 
47
        .expect('{"clients":[],"files":["gonna.css","test.css","it.css"]}')
 
48
        .expect(200, done);
 
49
    });
 
50
  });
 
51
 
 
52
  describe('POST /changed', function() {
 
53
    it('with no clients, no files', function(done) {
 
54
      request(this.server)
 
55
        .post('/changed')
 
56
        .expect('Content-Type', /json/)
 
57
        .expect(/"clients":\[\]/)
 
58
        .expect(/"files":\[\]/)
 
59
        .expect(200, done);
 
60
    });
 
61
 
 
62
    it('with no clients, some files', function(done) {
 
63
      var data = { clients: [], files: ['cat.css', 'sed.css', 'ack.js'] };
 
64
 
 
65
      request(this.server)
 
66
        .post('/changed')
 
67
        .send({ files: data.files })
 
68
        .expect('Content-Type', /json/)
 
69
        .expect(JSON.stringify(data))
 
70
        .expect(200, done);
 
71
    });
 
72
  });
 
73
 
 
74
  describe('GET /livereload.js', function() {
 
75
    it('respond with livereload script', function(done) {
 
76
      request(this.server)
 
77
        .get('/livereload.js')
 
78
        .expect(/LiveReload/)
 
79
        .expect(200, done);
 
80
    });
 
81
  });
 
82
 
 
83
  describe('GET /kill', function() {
 
84
    it('shutdown the server', function(done) {
 
85
      var server = this.server;
 
86
      request(server)
 
87
        .get('/kill')
 
88
        .expect(200, function(err) {
 
89
          if(err) return done(err);
 
90
          assert.ok(!server._handle);
 
91
          done();
 
92
        });
 
93
    });
 
94
  });
 
95
 
 
96
});