1 | assert = require 'assert'
|
2 | fetch = require './lib/fetch'
|
3 | Crixalis = require '../lib'
|
4 |
|
5 | port = +process.env.CRIXALIS_PORT + 15
|
6 |
|
7 | Crixalis
|
8 | .start('http', port)
|
9 | .unref()
|
10 |
|
11 | Crixalis.view = 'json'
|
12 |
|
13 | request = (options) ->
|
14 | options.host ?= 'localhost'
|
15 | options.port ?= port
|
16 | options.path ?= '/'
|
17 | options.method ?= 'GET'
|
18 |
|
19 | return ->
|
20 | fetch options, @callback
|
21 | return
|
22 |
|
23 | matches = (expected) ->
|
24 | return (error, response) ->
|
25 | assert.equal expected.code, response.statusCode
|
26 | assert.deepEqual expected.data, JSON.parse(response.body)
|
27 |
|
28 |
|
29 | defineRoute = (route) ->
|
30 | Crixalis.route route, ->
|
31 | @params.route = String(route)
|
32 | @stash.json = @params
|
33 |
|
34 | @render()
|
35 |
|
36 | defineRoute route for route in [
|
37 | '/',
|
38 | '/static',
|
39 | '/static/:action',
|
40 | '/static/*',
|
41 | '/:item',
|
42 | '/:item/:action',
|
43 | '/:item/*',
|
44 | '*'
|
45 | ]
|
46 |
|
47 | (require 'vows')
|
48 | .describe('placeholders')
|
49 | .addBatch
|
50 | root:
|
51 | topic: request
|
52 | path: '/'
|
53 |
|
54 | result: matches
|
55 | code: 200
|
56 | data:
|
57 | route: '/'
|
58 |
|
59 | static:
|
60 | topic: request
|
61 | path: '/static'
|
62 |
|
63 | result: matches
|
64 | code: 200
|
65 | data:
|
66 | route: '/static'
|
67 |
|
68 | action:
|
69 | topic: request
|
70 | path: '/static/index'
|
71 |
|
72 | result: matches
|
73 | code: 200
|
74 | data:
|
75 | route: '/static/:action'
|
76 | action: 'index'
|
77 |
|
78 | extension:
|
79 | topic: request
|
80 | path: '/static/index.txt'
|
81 |
|
82 | result: matches
|
83 | code: 200
|
84 | data:
|
85 | route: '/static/*'
|
86 |
|
87 | wildcard:
|
88 | topic: request
|
89 | path: '/static/files/index.txt'
|
90 |
|
91 | result: matches
|
92 | code: 200
|
93 | data:
|
94 | route: '/static/*'
|
95 |
|
96 | placeholder:
|
97 | topic: request
|
98 | path: '/index'
|
99 |
|
100 | result: matches
|
101 | code: 200
|
102 | data:
|
103 | route: '/:item'
|
104 | item: 'index'
|
105 |
|
106 | placeholder:
|
107 | topic: request
|
108 | path: '/index/files'
|
109 |
|
110 | result: matches
|
111 | code: 200
|
112 | data:
|
113 | route: '/:item/:action'
|
114 | item: 'index'
|
115 | action: 'files'
|
116 |
|
117 | extension:
|
118 | topic: request
|
119 | path: '/index/files.txt'
|
120 |
|
121 | result: matches
|
122 | code: 200
|
123 | data:
|
124 | route: '/:item/*'
|
125 | item: 'index'
|
126 |
|
127 | wildcard:
|
128 | topic: request
|
129 | path: '/index/files/list.txt'
|
130 |
|
131 | result: matches
|
132 | code: 200
|
133 | data:
|
134 | route: '/:item/*'
|
135 | item: 'index'
|
136 |
|
137 | extension:
|
138 | topic: request
|
139 | path: '/index.txt'
|
140 |
|
141 | result: matches
|
142 | code: 200
|
143 | data:
|
144 | route: '*'
|
145 |
|
146 | .export(module)
|