{"id":15350131,"url":"https://github.com/mars/episode-7","last_synced_at":"2025-10-06T23:41:46.928Z","repository":{"id":57226386,"uuid":"62601974","full_name":"mars/episode-7","owner":"mars","description":"A facade for side-effects: write test-friendly, async/await-style, JS code","archived":false,"fork":false,"pushed_at":"2020-04-13T13:31:14.000Z","size":34,"stargazers_count":10,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T15:48:23.861Z","etag":null,"topics":["async-programming","es2015","generator","promises"],"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/mars.png","metadata":{"files":{"readme":"README.markdown","changelog":"CHANGELOG.markdown","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":"2016-07-05T03:04:36.000Z","updated_at":"2019-03-30T17:49:04.000Z","dependencies_parsed_at":"2022-08-24T11:00:59.686Z","dependency_job_id":null,"html_url":"https://github.com/mars/episode-7","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mars%2Fepisode-7","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mars%2Fepisode-7/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mars%2Fepisode-7/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mars%2Fepisode-7/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mars","download_url":"https://codeload.github.com/mars/episode-7/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813803,"owners_count":21165634,"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":["async-programming","es2015","generator","promises"],"created_at":"2024-10-01T11:57:36.449Z","updated_at":"2025-10-06T23:41:46.848Z","avatar_url":"https://github.com/mars.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Episode 7 📺\n============\nA facade for side-effects: write test-friendly, async/await-style, JS code.\n\n[![Build Status](https://travis-ci.org/mars/episode-7.svg?branch=master)](https://travis-ci.org/mars/episode-7)\n[![npm Module](https://img.shields.io/npm/v/episode-7.svg)](https://www.npmjs.com/package/episode-7)\n\n\nCare about unit testing around [side-effects](https://en.wikipedia.org/wiki/Side_effect_(computer_science))? You may fall in love with Episode 7.\n\n### Episode 7 is a simpler way\n\n* spy on, intercept, \u0026 fake async function calls\n* avoid brittle HTTP mocks\n* confidently handle async errors\n\n### A tiny library 🐿\n\n* no production npm dependencies\n* \u003c100-lines-of-code (without comments)\n\n### Functional in nature 🌲\n\nInspired by the test-friendly [generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator) architecture of [`redux-saga`](https://github.com/yelouafi/redux-saga) and the pure side-effects of [Elm](http://elm-lang.org).\n\nRequires\n--------\n\n[ES6/Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator) support.\n\n* Known to work in [Node.js](https://nodejs.org) 6.2\n* Should work in any ES6-compliant JavaScript environment\n\nInstall\n-------\n\n```bash\nnpm install episode-7 --save\n```\n\nChanges\n-------\n\nSee: [CHANGELOG](CHANGELOG.markdown)\n\nUsage\n-----\n\n```javascript\nconst Episode7 = require('episode-7');\nconst fetch = require('node-fetch');\n\n// Compose an Episode 7 Generator for an async call sequence.\n//\nfunction* findFirstMovie(searchTerm) {\n\n  // Wrap side-effects with Episode 7's `call`\n  //\n  let results = yield Episode7.call(\n    fetchJson,\n    `http://www.omdbapi.com/?s=${encodeURIComponent(searchTerm)}`\n  );\n\n  // Do something programmatic with the result.\n  //\n  let firstResultId = results.Search[0].imdbID;\n  \n  // Use that transformed value to make the next call.\n  //\n  let movie = yield Episode7.call(\n    fetchJson,\n    `http://www.omdbapi.com/?i=${encodeURIComponent(firstResultId)}`\n  );\n\n  return movie;\n}\n\n// Side-effect function,\n// a barebones helper to fetch \u0026 decode JSON.\n//\nfunction fetchJson(url) {\n  return fetch(url).then( response =\u003e response.json() );\n}\n\n// Run the generator with Episode 7, returning a promise.\n//\nEpisode7.run(findFirstMovie, 'Episode 7')\n  .then( movie =\u003e console.log(movie.Title) )\n  .catch( error =\u003e console.error(error) )\n```\n\n### Smooth running tips 🚝\n\n#### Handle errors\n\n[`catch`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch) after `Episode7.run` to handle errors from the async flow (log|exit|retry).\n\nAvoid catching within side-effect functions. Allow their errors to bubble up.\n\n#### Name generator functions\n\nDeclare generator functions as [named function expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function); this makes stacktraces \u0026 error messages more meaningful.\n\n\nBackground\n----------\nI created this module to make it easy to code \u0026 test sequences of web service API requests interleaved with programmatic logic. I'm pulling the essence of [`redux-saga`](https://github.com/yelouafi/redux-saga) into the smallest, plainest surface area conceivable.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmars%2Fepisode-7","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmars%2Fepisode-7","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmars%2Fepisode-7/lists"}