Skip to content

Instantly share code, notes, and snippets.

@mandric
Last active May 2, 2019 19:36
Show Gist options
  • Select an option

  • Save mandric/b1a95e81718a4a3814730432f2054d3c to your computer and use it in GitHub Desktop.

Select an option

Save mandric/b1a95e81718a4a3814730432f2054d3c to your computer and use it in GitHub Desktop.

Revisions

  1. mandric revised this gist May 2, 2019. No changes.
  2. mandric created this gist May 2, 2019.
    28 changes: 28 additions & 0 deletions test.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    const { spawn } = require('child_process');
    const request = require('request');
    const test = require('tape');

    // Start the app
    const env = Object.assign({}, process.env, {PORT: 5000});
    const child = spawn('node', ['index.js'], {env});

    test('responds to requests', (t) => {
    t.plan(4);

    // Wait until the server is ready
    child.stdout.on('data', _ => {
    // Make a request to our app
    request('http://127.0.0.1:5000', (error, response, body) => {
    // stop the server
    child.kill();

    // No error
    t.false(error);
    // Successful response
    t.equal(response.statusCode, 200);
    // Assert content checks
    t.notEqual(body.indexOf("<title>Node.js Getting Started on Heroku</title>"), -1);
    t.notEqual(body.indexOf("Getting Started with Node on Heroku"), -1);
    });
    });
    });