|
1 | 1 | var sys = require('sys'); |
| 2 | +var path = require('path'); |
2 | 3 | module.exports = function(grunt) { |
3 | 4 | grunt.initConfig({ |
4 | 5 | pkg: grunt.file.readJSON('package.json'), |
@@ -106,89 +107,24 @@ module.exports = function(grunt) { |
106 | 107 | src: ['src/**/*.js'] |
107 | 108 | } |
108 | 109 | }, |
109 | | - connect: { |
110 | | - server: { |
| 110 | + express: { |
| 111 | + testServer: { |
111 | 112 | options: { |
112 | | - port: 8000, |
113 | | - base: './test', |
114 | | - middleware: function(connect, options, middlewares) { |
115 | | - middlewares.push(function(req, res, next) { |
116 | | - if (req.url === '/data/test-json' && req.method === 'GET') { |
117 | | - res.setHeader('Content-Type', 'application/json'); |
118 | | - res.end(JSON.stringify({abc: 123})); |
119 | | - return true; |
120 | | - } else { |
121 | | - return next(); |
122 | | - } |
123 | | - }); |
124 | | - middlewares.push(function(req, res, next) { |
125 | | - if (req.url === '/data/test-bad-json' && req.method === 'GET') { |
126 | | - res.setHeader('Content-Type', 'application/json'); |
127 | | - res.end('lllll'); |
128 | | - return true; |
129 | | - } else { |
130 | | - return next(); |
131 | | - } |
132 | | - }); |
133 | | - middlewares.push(function(req, res, next) { |
134 | | - if (req.url === '/data/test-empty-json' && req.method === 'GET') { |
135 | | - res.setHeader('Content-Type', 'application/json'); |
136 | | - res.end(''); |
137 | | - return true; |
138 | | - } else { |
139 | | - return next(); |
140 | | - } |
141 | | - }); |
142 | | - middlewares.push(function(req, res, next) { |
143 | | - if (req.url === '/test-post' && req.method === 'POST') { |
144 | | - res.setHeader('Content-Type', 'application/json'); |
145 | | - res.end(JSON.stringify({abc: 123})); |
146 | | - return true; |
147 | | - } else { |
148 | | - return next(); |
149 | | - } |
150 | | - }); |
151 | | - middlewares.push(function(req, res, next) { |
152 | | - if (req.url === '/data/test' && req.method === 'GET') { |
153 | | - res.end("Hi There"); |
154 | | - return true; |
155 | | - } else { |
156 | | - return next(); |
157 | | - } |
158 | | - }); |
159 | | - middlewares.push(function(req, res, next) { |
160 | | - if (req.url === '/data/test/weird-status' && req.method === 'GET') { |
161 | | - res.statusCode = 444; |
162 | | - res.end("Hi There"); |
163 | | - return true; |
164 | | - } else { |
165 | | - return next(); |
166 | | - } |
167 | | - }); |
168 | | - middlewares.push(function(req, res, next) { |
169 | | - if (req.url === '/data/test/server-error' && req.method === 'GET') { |
170 | | - res.statusCode = 500; |
171 | | - res.end("Hi There"); |
172 | | - return true; |
173 | | - } else { |
174 | | - return next(); |
175 | | - } |
176 | | - }); |
177 | | - return middlewares; |
178 | | - } |
| 113 | + server: path.resolve(__dirname, 'test/server.js'), |
| 114 | + port: 8000 |
179 | 115 | } |
180 | 116 | } |
181 | 117 | } |
182 | 118 | }); |
183 | 119 |
|
184 | | - grunt.loadNpmTasks('grunt-contrib-connect'); |
185 | 120 | grunt.loadNpmTasks('grunt-requirejs'); |
186 | 121 | grunt.loadNpmTasks('grunt-contrib-jshint'); |
187 | 122 | grunt.loadNpmTasks('grunt-contrib-qunit'); |
188 | 123 | grunt.loadNpmTasks('grunt-contrib-watch'); |
189 | 124 | grunt.loadNpmTasks('grunt-contrib-clean'); |
| 125 | + grunt.loadNpmTasks('grunt-express'); |
190 | 126 |
|
191 | 127 | grunt.registerTask('test', ['jshint', 'requirejs:compile', 'requirejs:compileForTest', 'qunit', 'clean']); |
192 | | - grunt.registerTask('build', ['connect', 'jshint', 'requirejs:compile', 'qunit']); |
193 | | - grunt.registerTask('default', ['connect', 'watch']); |
| 128 | + grunt.registerTask('build', ['express', 'test']); //jshint', 'requirejs:compile', 'requirejs:compileForTest', 'qunit', 'clean']); |
| 129 | + grunt.registerTask('default', ['express', 'watch']); |
194 | 130 | }; |
0 commit comments