{"id":28480028,"url":"https://github.com/dreamlab/taws","last_synced_at":"2025-07-03T18:31:44.212Z","repository":{"id":22431396,"uuid":"96208204","full_name":"DreamLab/taws","owner":"DreamLab","description":"A library for testing responses of HTTP requests","archived":false,"fork":false,"pushed_at":"2022-02-11T00:47:14.000Z","size":251,"stargazers_count":11,"open_issues_count":4,"forks_count":0,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-06-04T11:23:35.678Z","etag":null,"topics":["http","rest","rest-api","testing","testing-tools"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DreamLab.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}},"created_at":"2017-07-04T10:54:10.000Z","updated_at":"2021-04-07T09:09:05.000Z","dependencies_parsed_at":"2022-08-07T10:15:40.727Z","dependency_job_id":null,"html_url":"https://github.com/DreamLab/taws","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/DreamLab/taws","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DreamLab%2Ftaws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DreamLab%2Ftaws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DreamLab%2Ftaws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DreamLab%2Ftaws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DreamLab","download_url":"https://codeload.github.com/DreamLab/taws/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DreamLab%2Ftaws/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263379150,"owners_count":23457801,"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":["http","rest","rest-api","testing","testing-tools"],"created_at":"2025-06-07T18:34:03.423Z","updated_at":"2025-07-03T18:31:44.203Z","avatar_url":"https://github.com/DreamLab.png","language":"JavaScript","readme":"# Taws - simple tester of your http respones\n\n[![NPM](https://nodei.co/npm/taws.png)](https://nodei.co/npm/taws/)\n\n*Library for runnning tests suite on http request responses.*\n\n\n### Getting Started\n\n\n1. Install Taws in your project\n   `$ npm intall taws`\n2. Copy \u0026 paste below code\n```js\n    const { TestsRunner } = require('taws');\n    //example tests suite configuration\n    const params = {\n        \"name\" : \"example_tests_suite\",\n        \"config\" : [{\n            \"type\" : \"request\",\n            \"options\" : {\n                \"method\" : \"GET\",\n                \"url\" : \"https://restcountries.eu/rest/v2/name/Poland\",\n                \"headers\" : {}\n            },\n            \"tests\" : [{\n                \"type\" : \"regexp\",\n                \"key\" : \"[0].name\",\n                \"value\" : \"Poland\"\n            }]\n        }]\n    };\n    \n    const runner = new TestsRunner();\n    let promiseChain = runner.run(params.config);\n    \n    promiseChain\n        .then((result) =\u003e {\n            console.info('TEST - %s - name=%s tests_overall=%s tests_failed=%s duration=%s ms',\n                result.testsSuiteId,\n                params.name,\n            result.testsRun,\n                result.testsFail,\n            result.endTime - result.startTime\n            )\n        })\n        .catch((error) =\u003e {\n            console.error(error);\n    });\n```\n\n3. Run your code with node\u003e6.x.x\n\nBy default, logging of processing tests is enabled, if you want to disable this,\npass object with `silentModel` property set to true  to `TestRunner` constructor.\n\n```js\n    //example tests suite configuration\n    const options={\n        silentMode: true\n    };\n    \n    const runner = new TestsRunner(options);\n```\n\n\n### Tests suite definition\n\nTaws `TestsRunner` *run* method accepts tests suite to run. \n\n*Example of tests suite definition:*\n \n```json\n{\n    \"name\" : \"pulse2story_save\",\n    \"config\" : [{\n            \"type\" : \"request\",\n            \"options\" : {\n                \"method\" : \"GET\",\n                \"url\" : \"https://restcountries.eu/rest/v2/name/Poland\",\n                \"headers\" : {\n                    \"cache-control\" : \"no-cache\"\n                }\n            },\n            \"tests\" : [{\n                    \"type\" : \"regexp\",\n                    \"key\" : \"[0].name\",\n                    \"value\" : \"Poland\"\n                }\n            ]\n        },\n        {\n            \"type\": \"delay\",\n            \"time\": 6000\n        }\n    ]\n}\n```\nTests suite consists of two keys: `name` and `config`\n\n`name` is a name of tests suite\n`config` is a set of action definitions to perform within the tests suite. See [action-definition](#action-definition) for more information.\n\n#### Action definition\n\nTests suite configuration consist of actions that are executed synchronously in defined order.\n \n There are two types of actions to use\n1. `request` type - run http request\n    \n    __Requires `options` key with request definition ( see https://github.com/request/request )__\n    \n    ```json\n    {\n        \"type\" : \"request\",\n        \"options\" : {\n            \"method\" : \"GET\",\n            \"url\" : \"https://restcountries.eu/rest/v2/name/Poland\",\n            \"headers\" : {\n                \"cache-control\" : \"no-cache\"\n            }\n    }\n    ```\n    \n    If you want to retry request when error occurs, add `retries` key with the desired number of retries\n    \n    ```json\n    {\n        \"type\" : \"request\",\n        \"retries\": 2,\n        \"options\" : {\n            \"method\" : \"GET\",\n            \"url\" : \"https://restcountries.eu/rest/v2/name/Poland\",\n            \"headers\" : {\n                \"cache-control\" : \"no-cache\"\n            }\n    }\n    ```\n    \n    This action accepts a tests definition to run on a response of request.\n    \n    See [test-definition](#test-definition) section. \n    \n2. `delay` type - wait specified time before executing next action\n    \n    Requires `time` key with number of miliseconds to wait\n    \n    ```json\n     {\n         \"type\": \"delay\",\n         \"time\": 6000\n     }\n    ```\n    \n##### Tests definition\n    \nEvery \"request\" step allows to specify tests, that will be run in order to check correctness of the response. Tests property is an array, where every object represents one condition.\n\n*Example*:\n```\n    \"tests\" : \n    [{\n        \"type\" : \"regexp\",\n        \"key\" : \"[0].name\",\n        \"value\" : \"Poland\"\n        }, {\n        \"type\" : \"regexp\",\n        \"key\" : \"[0].capital\",\n        \"value\" : \"Warsaw\"\n        }, {\n        \"type\" : \"regexp\",\n        \"key\" : \"[0].region\",\n        \"value\" : \"(Europe|europe)\"\n        }]\n```\n    \nSingle test definition consist of following key:\n    \n`type` - Type of test. Only `regexp` type is available.\n`key` - Path in response's object, which value will be tested against regexp\n`value` -  Regexp to test the value.\n\n---\n\n#### Accessing responses of previous requests\n\nEvery request action and tests definition can use data from previous requests response.\nResponses of previous requests are available under `response[index]` variable, where `index`\ncorresponds to requests order. \n\nFor example, to access response of first request use `response[0]` variable, for second `response[1]` etc..\n\nBelow you find common use examples:\n\n*Using `name` key from response of first request in URL of the next*\n```json\n     {\n         \"type\" : \"request\",\n         \"options\" : {\n             \"method\" : \"POST\",\n             \"url\" : \"https://myexampleapiendoint.com/${response[0].name}\",\n             \"headers\" : {\n                 \"cache-control\" : \"no-cache\",\n                 \"my-custom-header\": \"example-header\"\n             },\n             \"body\" : {\n                 \"data\": {\n                    \"age\": 25\n                 }\n             }\n         }\n     }\n```\n#### Validating tests suite\n\nTo validate tests suite definition, `validateConfig` method is available.\n\nArguments:\n\n`testConfig` - test suite definition\n`throwError` - decides if excepion should be trowed when validation of tests suite fail\n\n*Example*:\n```js\n    const { validateConfig } = require('taws');\n\n    try {\n        validateConfig(testConfig, true);\n    } catch (error) {\n        console.warn('Schema validation error:', error);\n    }\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdreamlab%2Ftaws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdreamlab%2Ftaws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdreamlab%2Ftaws/lists"}