{"id":20731668,"url":"https://github.com/tapjs/t-up","last_synced_at":"2025-04-23T22:06:01.620Z","repository":{"id":43546606,"uuid":"52250917","full_name":"tapjs/t-up","owner":"tapjs","description":"Tee up a test server in one file, tear it down in another","archived":false,"fork":false,"pushed_at":"2023-10-10T17:32:18.000Z","size":90,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-23T22:05:54.506Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tapjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":["isaacs"]}},"created_at":"2016-02-22T06:06:49.000Z","updated_at":"2023-11-30T17:13:20.000Z","dependencies_parsed_at":"2024-01-28T23:43:37.518Z","dependency_job_id":null,"html_url":"https://github.com/tapjs/t-up","commit_stats":{"total_commits":33,"total_committers":2,"mean_commits":16.5,"dds":0.06060606060606055,"last_synced_commit":"3e29d10677e3da5c998e640448f3401a0fb84ef6"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tapjs%2Ft-up","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tapjs%2Ft-up/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tapjs%2Ft-up/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tapjs%2Ft-up/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tapjs","download_url":"https://codeload.github.com/tapjs/t-up/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250522299,"owners_count":21444511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T05:16:20.568Z","updated_at":"2025-04-23T22:06:01.371Z","avatar_url":"https://github.com/tapjs.png","language":"JavaScript","funding_links":["https://github.com/sponsors/isaacs"],"categories":[],"sub_categories":[],"readme":"# t-up\n\nTee up a test server in one file, tear it down in another\n\nThis makes it easy to set up a server or child process in a test file\ncalled `00-setup.js` or something, and then tear it down in\n`zz-teardown.js`, so that you can get the benefits of running your\ntests in separate files, but still bang on the same server across the\nentire suite.\n\n## USAGE\n\nYou may have a setup file that starts a server, like so:\n\n```javascript\n// 00-setup.js\nvar tup = require('t-up')\n\ntup(function (done) {\n  var http = require('http')\n  http.createServer(function (req, res) {\n    if (req.url === '/ping') {\n      res.end('pong\\n')\n    } else {\n      res.statusCode = 404\n      res.end('not found\\n')\n    }\n  }).listen(1337, function () {\n    // standard node-style callback\n    // if you call this with an error, it'll blow up\n    done()\n  })\n})\n```\n\nThen, a bunch of tests that do things to that server:\n\n```javascript\n// test-ping.js\nvar t = require('tap')\nvar http = require('http')\n\nt.test('ping returns pong', function (t) {\n  http.get('http://localhost:1337/ping', function (res) {\n    t.equal(res.statusCode, 200)\n    var pong = ''\n    res.on('data', function (d) { pong += d })\n    res.on('end', function () {\n      t.equal(pong, 'pong\\n')\n      t.end()\n    })\n  })\n})\n```\n\nAnd of course, a negative test:\n\n```javascript\n// test-blerg.js\nt.test('anything else 404s', function (t) {\n  http.get('http://localhost:1337/blerg', function (res) {\n    t.equal(res.statusCode, 404)\n    var pong = ''\n    res.on('data', function (d) { pong += d })\n    res.on('end', function () {\n      t.equal(pong, 'not found\\n')\n      t.end()\n    })\n  })\n})\n```\n\nLast but not least, tear down the server when you're done:\n\n```javascript\n// zz-teardown.js\nvar tup = require('t-up')\ntup.close()\n```\n\n## CAVEATS\n\n- The module that calls `t-up` should probably not do anything else.\n  It's going to be run a second time in a child process, so any other\n  side-effects are bad.\n- You should use [tap](http://node-tap.org) for your tests, since this\n  module will output some TAP notes about how it's going.\n- Definitely clean up after yourself!  If you don't ever call\n  `tup.close()`, then you'll have a bunch of node processes lying\n  around.\n- The server MUST call the `done()` function when it's ready to move\n  onto the next test.  This writes a special key to standard output,\n  and prevents a race condition where the tests fail because the\n  server isn't up yet.  Otherwise, all stdio is completely lost,\n  because the child process is abandoned without access to that stuff.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftapjs%2Ft-up","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftapjs%2Ft-up","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftapjs%2Ft-up/lists"}