2
var request = require('supertest');
3
var assert = require('assert');
5
var Server = require('..').Server;
7
describe('tiny-lr', function() {
9
beforeEach(function() {
10
this.app = new Server;
11
this.server = this.app.server;
14
describe('GET /', function() {
15
it('respond with nothing, but respond', function(done){
18
.expect('Content-Type', /json/)
19
.expect(/\{"tinylr":"Welcome","version":"0.0.[\d]+"\}/)
23
it('unknown route respond with proper 404 and error message', function(done){
26
.expect('Content-Type', /json/)
27
.expect('{"error":"not_found","reason":"no such route"}')
33
describe('GET /changed', function() {
34
it('with no clients, no files', function(done) {
37
.expect('Content-Type', /json/)
38
.expect(/"clients":\[\]/)
39
.expect(/"files":\[\]/)
43
it('with no clients, some files', function(done) {
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"]}')
52
describe('POST /changed', function() {
53
it('with no clients, no files', function(done) {
56
.expect('Content-Type', /json/)
57
.expect(/"clients":\[\]/)
58
.expect(/"files":\[\]/)
62
it('with no clients, some files', function(done) {
63
var data = { clients: [], files: ['cat.css', 'sed.css', 'ack.js'] };
67
.send({ files: data.files })
68
.expect('Content-Type', /json/)
69
.expect(JSON.stringify(data))
74
describe('GET /livereload.js', function() {
75
it('respond with livereload script', function(done) {
77
.get('/livereload.js')
83
describe('GET /kill', function() {
84
it('shutdown the server', function(done) {
85
var server = this.server;
88
.expect(200, function(err) {
89
if(err) return done(err);
90
assert.ok(!server._handle);