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 sass asset', ->
|
9 | app = null
|
10 |
|
11 | it 'should work with .scss', (done) ->
|
12 | compiled = fs.readFileSync "#{__dirname}/fixtures/sass/simple.css", 'utf8'
|
13 | app = express().http()
|
14 | app.use new rack.SassAsset
|
15 | filename: "#{__dirname}/fixtures/sass/simple.scss"
|
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 with .sass', (done) ->
|
24 | compiled = fs.readFileSync "#{__dirname}/fixtures/sass/simple.css", 'utf8'
|
25 | app = express().http()
|
26 | app.use new rack.SassAsset
|
27 | filename: "#{__dirname}/fixtures/sass/simple.sass"
|
28 | url: '/style.css'
|
29 | app.listen 7076, ->
|
30 | easyrequest 'http://localhost:7076/style.css', (error, response, body) ->
|
31 | response.headers['content-type'].should.equal 'text/css'
|
32 | body.should.equal compiled
|
33 | done()
|
34 |
|
35 | it 'should work compressed', (done) ->
|
36 | compiled = fs.readFileSync "#{__dirname}/fixtures/sass/simple.min.css", 'utf8'
|
37 | app = express().http()
|
38 | app.use new rack.SassAsset
|
39 | filename: "#{__dirname}/fixtures/sass/simple.scss"
|
40 | url: '/style.css'
|
41 | compress: true
|
42 | app.listen 7076, ->
|
43 | easyrequest 'http://localhost:7076/style.css', (error, response, body) ->
|
44 | response.headers['content-type'].should.equal 'text/css'
|
45 | body.should.equal compiled
|
46 | done()
|
47 |
|
48 | it 'should work with paths', (done) ->
|
49 | compiled = fs.readFileSync "#{__dirname}/fixtures/sass/another.css", 'utf8'
|
50 | app = express().http()
|
51 | app.use new rack.SassAsset
|
52 | filename: "#{__dirname}/fixtures/sass/another.scss"
|
53 | url: '/style.css'
|
54 | paths: ["#{__dirname}/fixtures/sass/more"]
|
55 | app.listen 7076, ->
|
56 | easyrequest 'http://localhost:7076/style.css', (error, response, body) ->
|
57 | response.headers['content-type'].should.equal 'text/css'
|
58 | body.should.equal compiled
|
59 | done()
|
60 |
|
61 | it 'should work with the rack', (done) ->
|
62 | app = express().http()
|
63 | app.use assets = new rack.AssetRack [
|
64 | new rack.Asset
|
65 | url: '/background.png'
|
66 | contents: 'not a real png'
|
67 | new rack.SassAsset
|
68 | filename: "#{__dirname}/fixtures/sass/simple.scss"
|
69 | url: '/simple.css'
|
70 | new rack.SassAsset
|
71 | filename: "#{__dirname}/fixtures/sass/another.scss"
|
72 | url: '/style.css'
|
73 | paths: ["#{__dirname}/fixtures/sass/more"]
|
74 | ]
|
75 | app.listen 7076, ->
|
76 | easyrequest 'http://localhost:7076/style.css', (error, response, body) ->
|
77 | backgroundUrl = assets.url('/background.png')
|
78 | body.indexOf(backgroundUrl).should.not.equal -1
|
79 | done()
|
80 |
|
81 | afterEach (done) -> process.nextTick ->
|
82 | app.server.close done
|