1 |
|
2 | should = require('chai').should()
|
3 | rack = require '../.'
|
4 | express = require 'express.io'
|
5 | easyrequest = require 'request'
|
6 | fs = require 'fs'
|
7 |
|
8 | describe 'a less asset', ->
|
9 | app = null
|
10 |
|
11 | it 'should work', (done) ->
|
12 | compiled = fs.readFileSync "#{__dirname}/fixtures/less/simple.css", 'utf8'
|
13 | app = express().http()
|
14 | app.use new rack.LessAsset
|
15 | filename: "#{__dirname}/fixtures/less/simple.less"
|
16 | url: '/style.css'
|
17 | app.listen 7076, ->
|
18 | easyrequest 'http://localhost:7076/style.css', (error, response, body) ->
|
19 | response.headers['content-type'].should.equal 'text/css'
|
20 | body.should.equal compiled
|
21 | done()
|
22 |
|
23 | it 'should work compressed', (done) ->
|
24 | compiled = fs.readFileSync "#{__dirname}/fixtures/less/simple.min.css", 'utf8'
|
25 | app = express().http()
|
26 | app.use new rack.LessAsset
|
27 | filename: "#{__dirname}/fixtures/less/simple.less"
|
28 | url: '/style.css'
|
29 | compress: true
|
30 | app.listen 7076, ->
|
31 | easyrequest 'http://localhost:7076/style.css', (error, response, body) ->
|
32 | response.headers['content-type'].should.equal 'text/css'
|
33 | body.should.equal compiled
|
34 | done()
|
35 |
|
36 | it 'should work with paths', (done) ->
|
37 | compiled = fs.readFileSync "#{__dirname}/fixtures/less/another.css", 'utf8'
|
38 | app = express().http()
|
39 | app.use new rack.LessAsset
|
40 | filename: "#{__dirname}/fixtures/less/another.less"
|
41 | url: '/style.css'
|
42 | paths: ["#{__dirname}/fixtures/less/more"]
|
43 | app.listen 7076, ->
|
44 | easyrequest 'http://localhost:7076/style.css', (error, response, body) ->
|
45 | response.headers['content-type'].should.equal 'text/css'
|
46 | body.should.equal compiled
|
47 | done()
|
48 |
|
49 | it 'should work with the rack', (done) ->
|
50 | app = express().http()
|
51 | app.use assets = new rack.AssetRack [
|
52 | new rack.Asset
|
53 | url: '/background.png'
|
54 | contents: 'not a real png'
|
55 | new rack.LessAsset
|
56 | filename: "#{__dirname}/fixtures/less/simple.less"
|
57 | url: '/simple.css'
|
58 | new rack.LessAsset
|
59 | filename: "#{__dirname}/fixtures/less/dependency.less"
|
60 | url: '/style.css'
|
61 | ]
|
62 | app.listen 7076, ->
|
63 | easyrequest 'http://localhost:7076/style.css', (error, response, body) ->
|
64 | backgroundUrl = assets.url('/background.png')
|
65 | body.indexOf(backgroundUrl).should.not.equal -1
|
66 | done()
|
67 | it 'should throw a meaningful error', (done) ->
|
68 | should.Throw ->
|
69 | app.use assets = new rack.AssetRack [
|
70 | asset = new rack.LessAsset
|
71 | filename: "#{__dirname}/fixtures/less/syntax-error.less"
|
72 | url: '/style.css'
|
73 | ]
|
74 | should.Throw ->
|
75 | app.use assets = new rack.AssetRack [
|
76 | asset = new rack.LessAsset
|
77 | contents : """
|
78 | @import "file-that-doesnt-exist.less";
|
79 | body {
|
80 | background-color: blue;
|
81 | div {
|
82 | background-color: pink;
|
83 | }
|
84 | }
|
85 | """
|
86 | url: 'style.css'
|
87 | ]
|
88 |
|
89 | app = express().http()
|
90 | app.listen 7076, ->
|
91 | done()
|
92 | afterEach (done) -> process.nextTick ->
|
93 | app.server.close done
|