test.js 835 B

12345678910111213141516171819202122232425262728
  1. const { spawn } = require('child_process');
  2. const got = require('got');
  3. const test = require('tape');
  4. // Start the app
  5. const env = Object.assign({}, process.env, {PORT: 5000});
  6. const child = spawn('node', ['index.js'], {env});
  7. test('responds to requests', (t) => {
  8. t.plan(4);
  9. // Wait until the server is ready
  10. child.stdout.on('data', _ => {
  11. // Make a request to our app
  12. (async () => {
  13. const response = await got('http://127.0.0.1:5000');
  14. // stop the server
  15. child.kill();
  16. // No error
  17. t.false(response.error);
  18. // Successful response
  19. t.equal(response.statusCode, 200);
  20. // Assert content checks
  21. t.notEqual(response.body.indexOf("<title>Node.js </title>"), -1);
  22. t.notEqual(response.body.indexOf("Getting Started on Heroku with Node.js"), -1);
  23. })();
  24. });
  25. });