{"id":20364082,"url":"https://github.com/ekino/smuggler","last_synced_at":"2025-03-04T18:43:16.949Z","repository":{"id":54657428,"uuid":"334093549","full_name":"ekino/smuggler","owner":"ekino","description":"A simple interface to manipulate Nock HTTP mocks.","archived":false,"fork":false,"pushed_at":"2021-02-05T15:18:04.000Z","size":1053,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":10,"default_branch":"main","last_synced_at":"2024-04-14T12:50:58.720Z","etag":null,"topics":["http","http-requests","mock","nock","node-js"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@ekino/smuggler","language":"TypeScript","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/ekino.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":"2021-01-29T09:16:12.000Z","updated_at":"2021-12-28T08:34:46.000Z","dependencies_parsed_at":"2022-08-13T23:01:05.014Z","dependency_job_id":null,"html_url":"https://github.com/ekino/smuggler","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekino%2Fsmuggler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekino%2Fsmuggler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekino%2Fsmuggler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekino%2Fsmuggler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ekino","download_url":"https://codeload.github.com/ekino/smuggler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241904676,"owners_count":20040020,"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","http-requests","mock","nock","node-js"],"created_at":"2024-11-15T00:09:42.817Z","updated_at":"2025-03-04T18:43:16.909Z","avatar_url":"https://github.com/ekino.png","language":"TypeScript","readme":"# @ekino/smuggler\n[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/ekino/smuggler/build?style=flat-square)](https://github.com/ekino/smuggler/actions)\n[![Coveralls github branch](https://img.shields.io/coveralls/github/ekino/smuggler/main?style=flat-square)](https://coveralls.io/github/ekino/smuggler?branch=main)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n[![npm (scoped)](https://img.shields.io/npm/v/@ekino/smuggler?style=flat-square)](https://www.npmjs.com/package/@ekino/smuggler)\n\nThis library aims to provide a simple way to handle HTTP mock declarations through [Nock](https://github.com/nock/nock).\n\nIt has been thought as a simple component to load mock definitions from a directory. Then, the mocks could get activated on demand.\n\nFor instance, an express/koa middle could look for a `x-mock-id` header and when found load the mock associated with this id.\n\n## Mock definitions\n\nFor now, only `js` files could get imported, but we'll improve that in the future!\n\n### JavaScript\n\n```javascript\nconst nock = require('nock')\n\nmodule.exports = {\n    id: 'mock-id',\n    groupId: 'optional-mock-id',\n    declareMock: () =\u003e {\n        nock('http://foo.bar').get('/').reply(200)\n    }\n}\n```\n\n## Initializing\n\nIn order to initialize the `MockManager` (we'll talk about it right after), you just need to call the `initialize` method like so:\n\n```javascript\nconst { initialize } = require('@ekino/smuggler')\n\nvar mockManager = initialize()\n```\n\nBy default, this function will look for a `__mocks__` directory in the current directory and load any `js` file.\n\nIf you want to modify that, just pass in custom options:\n\n```javascript\nconst { initialize } = require('@ekino/smuggler')\n\nvar mockManager = initialize({\n    baseDirectory: '/absolute/path',\n    mocksDirectory: 'mocks-directory-name',\n    extensions: ['js']\n})\n```\n\n## The `MockManager`\n\nIt's the only component you should worry about as it's the one which will allow you to interact with the loaded definitions.\n\n### `MockManager#activateMock`\n\nIt looks for a mock with the given `id` and loads it if it has been found.\n\n```javascript\nmockManager.activateMock('mock-id')\n```\n\n### `MockManager#activateMocksGroup`\n\nIt looks for every mock with the given `group-id` and loads them all.\n\n```javascript\nmockManager.activateMocksGroup('group-id')\n```\n\n### `MockManager#listActiveMocks`\n\nIt lists all active mocks known to `nock` as a string array (see [nock.activeMocks()](https://github.com/nock/nock#pendingmocks)).\n\n```javascript\nmockManager.listActiveMocks()\n```\n\n### `MockManager#listPendingMocks`\n\nIt lists all pending mocks known to `nock` as a string array (see [nock.pendingMocks()](https://github.com/nock/nock#pendingmocks)).\n\n```javascript\nmockManager.listPendingMocks()\n```\n\n### `MockManager#checkNoPendingMocks`\n\nIt looks at nock pending mocks and if there's at least one it throws an error.\n\n```javascript\nmockManager.checkNoPendingMocks()\n```\n\n### `MockManager#resetMocks`\n\nIt will clean nock from any mocks (see [nock.cleanAll()](https://github.com/nock/nock#cleanall) and [nock.restore()](https://github.com/nock/nock#restoring)).\n\n```javascript\nmockManager.resetMocks()\n```\n\n## Examples\n\nYou can find examples of usage in the `examples` directory.\n\n### Express\n\n[Express example](./examples/express/README.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekino%2Fsmuggler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fekino%2Fsmuggler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekino%2Fsmuggler/lists"}