1 |
|
2 | should = require('chai').should()
|
3 | rack = require '../.'
|
4 | express = require 'express.io'
|
5 | easyrequest = require 'request'
|
6 | fs = require 'fs'
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | describe 'a jade asset', ->
|
12 | app = null
|
13 | fixturesDir = "#{__dirname}/fixtures/jade"
|
14 |
|
15 | beforeEach (done) ->
|
16 | app = express().http()
|
17 | app.listen 7076, done
|
18 |
|
19 | it 'should work', (done) ->
|
20 | app.use new rack.JadeAsset
|
21 | dirname: fixturesDir
|
22 | url: '/templates.js'
|
23 | easyrequest 'http://localhost:7076/templates.js', (error, response, body) ->
|
24 | response.headers['content-type'].should.equal 'text/javascript'
|
25 | window = {}
|
26 | eval(body)
|
27 | testFile = fs.readFileSync "#{fixturesDir}/test.html", 'utf8'
|
28 | window.Templates.test().should.equal testFile
|
29 | userFile = fs.readFileSync "#{fixturesDir}/user.html", 'utf8'
|
30 | window.Templates.user(users: ['fred', 'steve']).should.equal userFile
|
31 | done()
|
32 |
|
33 | it 'should work in a rack', (done) ->
|
34 | compiled = fs.readFileSync "#{fixturesDir}/templates-rack.js", 'utf8'
|
35 | app.use new rack.AssetRack [
|
36 | new rack.Asset
|
37 | url: '/image.png'
|
38 | contents: fs.readFileSync "#{fixturesDir}/image.png", 'utf8'
|
39 | new rack.JadeAsset
|
40 | dirname: fixturesDir
|
41 | url: '/templates-rack.js'
|
42 | ]
|
43 | easyrequest 'http://localhost:7076/templates-rack.js', (error, response, body) ->
|
44 | response.headers['content-type'].should.equal 'text/javascript'
|
45 | window = {}
|
46 | eval(body)
|
47 | testFile = fs.readFileSync "#{fixturesDir}/test.html", 'utf8'
|
48 | window.Templates.test().should.equal testFile
|
49 | userFile = fs.readFileSync "#{fixturesDir}/user.html", 'utf8'
|
50 | window.Templates.user(users: ['fred', 'steve']).should.equal userFile
|
51 | dependencyFile = fs.readFileSync "#{fixturesDir}/dependency.html", 'utf8'
|
52 | window.Templates.dependency().should.equal dependencyFile
|
53 | done()
|
54 |
|
55 | it 'should work compressed', (done) ->
|
56 | compiled = fs.readFileSync "#{fixturesDir}/templates.min.js", 'utf8'
|
57 | app.use new rack.Rack [
|
58 | new rack.JadeAsset
|
59 | dirname: "#{fixturesDir}"
|
60 | url: '/templates.js'
|
61 | new rack.JadeAsset
|
62 | dirname: "#{fixturesDir}"
|
63 | url: '/templates.min.js'
|
64 | compress: true
|
65 | ]
|
66 |
|
67 | easyrequest 'http://localhost:7076/templates.min.js', (error, response, body) ->
|
68 | response.headers['content-type'].should.equal 'text/javascript'
|
69 | window = {}
|
70 | eval(body)
|
71 | testFile = fs.readFileSync "#{fixturesDir}/test.html", 'utf8'
|
72 | window.Templates.test().should.equal testFile
|
73 | userFile = fs.readFileSync "#{fixturesDir}/user.html", 'utf8'
|
74 | window.Templates.user(users: ['fred', 'steve']).should.equal userFile
|
75 | easyrequest 'http://localhost:7076/templates.js', (error, response, bodyLong) ->
|
76 | bodyLong.length.should.be.above(body.length)
|
77 | done()
|
78 |
|
79 | afterEach (done) ->
|
80 | app.server.close done
|
81 |
|