Commits

Damon Oehlman  committed c538d62

Server side implementation working

  • Participants
  • Parent commits 1109fdc
  • Tags v0.1.0

Comments (0)

Files changed (4)

 
     t.plan(2 + expected.length);
 
-    req = request.get(baseUrl + url);
+    req = request.get(url);
 
     req.on('response', function(res) {
       t.equal(res.statusCode, 200, 'got 200 OK');
       res.on('data', function handleData(data) {
         var testVal = expected.shift();
 
+        // if the test value is an object, stringify
+        if (typeof testVal == 'object' && (! (testVal instanceof String))) {
+          testVal = JSON.stringify(testVal);
+        }
+
         t.equal(
           data.toString(),
           'data: ' + testVal + '\n\n',
 
   // check if the url is a base url
   if (! reAbsoluteUrl.test(url)) {
-    url = runTests.baseurl + url;
+    url = checkEvents.baseurl + url;
   }
 
-  return runTests.server ? ? server : client;
+  return checkEvents.server ? server : client;
 };
 
 checkEvents.server = typeof window == 'undefined';
+require('./values');

File test/helpers/test-server.js

 
 exports.start = function(callback) {
   server.on('request', function(req, res) {
-    if (req.url === '/values') {
-      pull(
-        pull.values([1, 2, 3]),
-        sse(res)
-      );
+    var source;
+
+    if (req.url === '/numbers') {
+      source = pull.values([1, 2, 3]);
+    }
+    else if (req.url === '/strings') {
+      source = pull.values(['a', 'b', 'c']);
     }
+    else if (req.url === '/objects') {
+      source = pull.values([{ a: 1 }, { b: 2 }]);
+    }
+
+    pull(source, sse(res));
   });
 
   server.listen(3000, callback);

File test/values.js

 var test = require('tape');
 var checkEvents = require('..');
-var testServer = require('./helpers/test-server')();
-var isBrowser = typeof window != 'undefined';
+var isServer = typeof window == 'undefined';
+var testServer = isServer && require('./helpers/test-server');
 
-isBrowser || test('start server', function(t) {
+testServer && test('start server', function(t) {
   t.plan(1);
   testServer.start(function(err) {
     t.ifError(err, 'started');
   });
 });
 
-test('check events', )
+test('string values', checkEvents('/strings', ['a', 'b', 'c']));
+test('numeric values', checkEvents('/numbers', [1, 2, 3]));
+test('object values', checkEvents('/objects', [ { a: 1 }, { b: 2 }]));
 
-isBrowser || test('stop server', function(t) {
+testServer && test('stop server', function(t) {
   t.plan(1);
   t.ok(testServer.stop(), 'stopped');
 });