UNPKG

3.34 kBJavaScriptView Raw
1var path = require('path'),
2 web_routes = require ('../lib/webapp/routes.js'),
3 request = require('request'),
4 assert = require('assert'),
5 fs = require('fs');
6
7describe ('static assets', function(){
8 var app;
9 var port = 4444;
10 before(function(){
11 app = require('express')();
12 var configPath = path.join(process.cwd(), 'test', 'fixtures', 'config','log-disabled.json');
13 var config = require('../lib/config-manager')(configPath);
14 config.wallboardAssetFolder = path.join(process.cwd(), 'test', 'fixtures', 'assets');
15 web_routes(app, null, null, config);
16 app.listen(port);
17 });
18
19 after(function(){
20 //app.close(); //close method in express.js 3.x?
21 });
22
23 describe ('images', function(){
24 it('should return atlasboard images', function(done){
25 request('http://localhost:' + port + '/images/red-up.png', function(err, response, body){
26 assert.ok(!err);
27 assert.equal(200, response.statusCode);
28 assert.ok(body);
29 done();
30 });
31 });
32
33 it('should not return non existant atlasboard images', function(done){
34 request('http://localhost:' + port + '/images/red-upxxxxxx.png', function(err, response, body){
35 assert.ok(!err);
36 assert.equal(404, response.statusCode);
37 done();
38 });
39 });
40
41 it('should return wallboard images', function(done){
42 request('http://localhost:' + port + '/images/green-down-wallboard-asset.png', function(err, response, body){
43 assert.ok(!err);
44 assert.equal(200, response.statusCode);
45 assert.ok(body);
46 done();
47 });
48 });
49
50 it('should return wallboard images over atlasboard ones if the name is the same', function(done){
51 request('http://localhost:' + port + '/images/red-up.png', function(err, response, body){
52 assert.ok(!err);
53 assert.equal(200, response.statusCode);
54 // this file is not a valid image. It contains just one character to be able to assert
55 // that we are fetching the one in the wallboard folder and not the one in atlasboard.
56 assert.equal(1, body.length);
57 done();
58 });
59 });
60 });
61
62 describe ('css and stylus', function(){
63 it('should render and return stylus', function(done){
64 request('http://localhost:' + port + '/stylesheets/application.css', function(err, response, body){
65 assert.ok(!err);
66 assert.equal(200, response.statusCode);
67 assert.ok(body);
68 done();
69 });
70 });
71
72 it('should cache stylus output so the second request should be blazing fast', function(done){
73 this.timeout(50);
74 request('http://localhost:' + port + '/stylesheets/application.css', function(err, response, body){
75 assert.ok(!err);
76 assert.equal(200, response.statusCode);
77 assert.ok(body);
78 done();
79 });
80 });
81
82 it('should render the output in compiled folder', function(done){
83 var compiledCSSPath = path.join(process.cwd(), '/test/fixtures/assets/compiled/stylesheets/application.css');
84 fs.exists(compiledCSSPath, function(exist){
85 assert.ok(exist);
86 fs.unlink(compiledCSSPath, function(err){
87 assert.ifError(err);
88 done();
89 })
90 });
91 });
92
93 });
94});