{"id":17321780,"url":"https://github.com/avoidwork/tiny-httptest","last_synced_at":"2025-04-14T16:24:28.165Z","repository":{"id":55858305,"uuid":"82202458","full_name":"avoidwork/tiny-httptest","owner":"avoidwork","description":"Lightweight HTTP test framework","archived":false,"fork":false,"pushed_at":"2024-10-10T06:33:23.000Z","size":790,"stargazers_count":8,"open_issues_count":9,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-18T07:29:49.744Z","etag":null,"topics":["capture-cookies","cookie","cors","etag","http","https","test-automation","test-framework"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avoidwork.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-16T16:39:36.000Z","updated_at":"2024-09-04T11:44:37.000Z","dependencies_parsed_at":"2023-11-17T14:15:33.612Z","dependency_job_id":"36b901f3-7000-4618-b775-90bf0cfa385f","html_url":"https://github.com/avoidwork/tiny-httptest","commit_stats":{"total_commits":132,"total_committers":2,"mean_commits":66.0,"dds":0.007575757575757569,"last_synced_commit":"a09b832e6edc1af2771c48a7449a0af771ed00ff"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-httptest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-httptest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-httptest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-httptest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avoidwork","download_url":"https://codeload.github.com/avoidwork/tiny-httptest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248915016,"owners_count":21182546,"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":["capture-cookies","cookie","cors","etag","http","https","test-automation","test-framework"],"created_at":"2024-10-15T13:39:34.169Z","updated_at":"2025-04-14T16:24:28.136Z","avatar_url":"https://github.com/avoidwork.png","language":"JavaScript","readme":"# Tiny HTTP Test\n\ntiny-httptest is a lightweight HTTP test framework that makes it easy to validate CORS is working, capture cookies \u0026 HTTP response headers (including etags) and reuse them for sequential tests.\n\n## Using the factory\n\n```javascript\nimport {httptest} from \"tiny-httptest\";\n\ndescribe('HTTP Tests', () =\u003e {\n it(\"GET /somefile (Captured the etag)\", function () {\n  return httptest({url: `http://localhost:${port}/somefile`})\n          .etags()\n          .expectStatus(200)\n          .end();\n });\n\n it(\"GET /somefile (Reused the ETag)\", function () {\n  return httptest({url: `http://localhost:${port}/somefile`})\n          .etags()\n          .expectStatus(304)\n          .end();\n });\n\n it(\"GET /invalid-file\", function () {\n  return httptest({url: `http://localhost:${port}/invalid-file`})\n          .expectStatus(404)\n          .end();\n });\n});\n```\n\n## Using the Class\n\n```javascript\nimport {HTTPTest} from \"tiny-httptest\";\nclass MyTestRunner extends HTTPTest {}\n```\n\n## Testing\n\nTiny HTTP Test has 100% code coverage with its tests.  Run `npm run test-setup` after installing modules.\n\n```console\n  Implicit proofs\n    √ Starting test server\n    √ GET / (captures cookie, CSRF token)\n    √ HEAD / (reuses cookie)\n    √ POST / (reuses cookie \u0026 CSRF token)\n    √ POST / (reuses cookie \u0026 CSRF token + body)\n    √ POST / (reuses cookie \u0026 CSRF token + body)\n    √ GET / (CORS Pre-flight)\n    √ GET / (CORS)\n    √ GET /invalid (CORS)\n    √ GET / (Basic Auth)\n    √ GET https://google.com/ (HTTPS) (94ms)\n    √ GET /assets/css/style.css\n    √ GET /assets/css/style.css (ETag)\n    √ Stopping test server\n\n  Error proofs\n    √ Starting test server\n    √ GET https://invalid.local.dev/ (DNS error)\n    √ INVALID / (Invalid HTTP method)\n    √ GET /hello (Error thrown)\n    √ GET /assets/css/style.css (Invalid 404)\n    √ Stopping test server\n\n\n  20 passing (160ms)\n\n-------------------|---------|----------|---------|---------|-----------------------------------------------------------\nFile               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s\n-------------------|---------|----------|---------|---------|-----------------------------------------------------------\nAll files          |     100 |    81.13 |     100 |     100 |                                                          \n tiny-httptest.cjs |     100 |    81.13 |     100 |     100 | 16-22,111,125-130,177,193,211-227,247,262,303,318-323,371\n-------------------|---------|----------|---------|---------|-----------------------------------------------------------\n```\n\n## Options\n\n### body\n\nHTTP request body, defaults to `null` but can be `String`, `Object` or `Array`.\n\n### headers\n\nHTTP request headers, defaults to `{}`.\n\n### method\n\nHTTP request method, defaults to `GET`.\n\n### timeout\nHTTP request timeout as milliseconds, defaults to `30000`.\n\n### url\nURL \u0026 port to request, defaults to `http://localhost`.\n\n## API\n\n### captureHeader(name)\n\nCaptures a header to be reused by another instance of `TinyHTTPTest`.\n\n### cookies([state = true])\n\nEnables or disables cookie capture \u0026 reuse.\n\n### cors([hostname, success = true])\n\nSets request \u0026 response header expectations, defaults to request `hostname` if optional argument is not supplied.\n\nIf testing an error case, you must specify the second parameter as `false` to not expect CORS headers.\n\n### end()\n\nEnds the request, `Promise` resolves with `TinyHTTPTest` instance or rejects with `Error`.\n\n### etags([state = true])\n\nEnables or disables ETag capture \u0026 reuse.\n\n### expectBody([value = /\\w+/])\n\nSets an expectation of the response body, default value is a `RegExp` which tests if there is a response body.\n\n### expectHeader(name, [value = /\\w+/])\n\nSets an expectation of a response header, default value is a `RegExp` which tests if there is a header value.\n\n### expectJson()\n\nSets an expectation of response header `content-type`, supports correct and common incorrect header values.\n\n### expectStatus([value = 200])\n\nSets an expectation of response status code, default value is `200`.\n\n### json([arg])\n\nSets request \u0026 response to `JSON`, sends `arg` if not `undefined`.\n\n### process()\n\nProcesses the response of the `TinyHTTPTest` instance.\n\n### reuseHeader(name)\n\nReuses a captured header from another instance of `TinyHTTPTest`.\n\n### send(arg)\n\nDecorates `arg` as request body \u0026 sets request headers.\n\n### test(arg, value, err)\n \nValidates that `arg` is equal to or passes `value` test, throws `Error` with `err` as message if invalid.\n\n## License\nCopyright (c) 2024 Jason Mulligan\nLicensed under the BSD-3 license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favoidwork%2Ftiny-httptest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favoidwork%2Ftiny-httptest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favoidwork%2Ftiny-httptest/lists"}