src: don't error at startup when cwd doesn't exist
[platform/upstream/nodejs.git] / test / parallel / test-http-res-write-end-dont-take-array.js
1 var common = require('../common');
2 var assert = require('assert');
3 var http = require('http');
4
5 var test = 1;
6
7 var server = http.createServer(function(req, res) {
8   res.writeHead(200, {'Content-Type': 'text/plain'});
9   if (test === 1) {
10     // write should accept string
11     res.write('string');
12     // write should accept buffer
13     res.write(new Buffer('asdf'));
14
15     // write should not accept an Array
16     assert.throws(function() {
17       res.write(['array']);
18     }, TypeError, 'first argument must be a string or Buffer');
19
20     // end should not accept an Array
21     assert.throws(function() {
22       res.end(['moo']);
23     }, TypeError, 'first argument must be a string or Buffer');
24
25     // end should accept string
26     res.end('string');
27   } else if (test === 2) {
28     // end should accept Buffer
29     res.end(new Buffer('asdf'));
30   }
31 });
32
33 server.listen(common.PORT, function() {
34   // just make a request, other tests handle responses
35   http.get({port: common.PORT}, function(res) {
36     res.resume();
37     // lazy serial test, because we can only call end once per request
38     test += 1;
39     // do it again to test .end(Buffer);
40     http.get({port: common.PORT}, function(res) {
41       res.resume();
42       server.close();
43     });
44   });
45 });