{"id":13767060,"url":"https://github.com/hustcc/jest-electron","last_synced_at":"2025-04-06T12:10:52.193Z","repository":{"id":41384212,"uuid":"206456491","full_name":"hustcc/jest-electron","owner":"hustcc","description":"❯ ⚛️The easiest way to run and debug test cases in electron with jest.","archived":false,"fork":false,"pushed_at":"2022-07-01T09:33:03.000Z","size":53,"stargazers_count":154,"open_issues_count":13,"forks_count":25,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-26T17:41:28.278Z","etag":null,"topics":["debugger","electron","jest","jest-electron","jest-runner"],"latest_commit_sha":null,"homepage":"https://github.com/hustcc/jest-electron","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/hustcc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://paypal.me/hustcc","https://atool.vip"]}},"created_at":"2019-09-05T02:20:24.000Z","updated_at":"2024-02-03T17:44:46.000Z","dependencies_parsed_at":"2022-08-25T13:30:23.767Z","dependency_job_id":null,"html_url":"https://github.com/hustcc/jest-electron","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hustcc%2Fjest-electron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hustcc%2Fjest-electron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hustcc%2Fjest-electron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hustcc%2Fjest-electron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hustcc","download_url":"https://codeload.github.com/hustcc/jest-electron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478324,"owners_count":20945266,"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":["debugger","electron","jest","jest-electron","jest-runner"],"created_at":"2024-08-03T16:01:04.133Z","updated_at":"2025-04-06T12:10:52.165Z","avatar_url":"https://github.com/hustcc.png","language":"TypeScript","funding_links":["https://paypal.me/hustcc","https://atool.vip"],"categories":["Library","四、快速构建应用的工具","Tools"],"sub_categories":["Testing","4. 网络与文件处理","Using Electron"],"readme":"# jest-electron\n\n\u003e Easiest way to run jest unit test cases in electron.\n\nWhen we run unit test in Jest, it is actually running in the node environment, or virtual browser environment(e.g. `JSDOM`) mocked by NodeJS. Sometimes we need a lot of [Jest mocks](https://github.com/jest-community/awesome-jest#mocks) for running code with no throw, such as: jest-canvas-mock, jest-storage-mock, @jest/fake-timers and so on. This is solved by `Jest-Electron`.\n\n[![Build Status](https://github.com/hustcc/jest-electron/workflows/build/badge.svg)](https://github.com/hustcc/jest-electron/actions)\n[![npm](https://img.shields.io/npm/v/jest-electron.svg)](https://www.npmjs.com/package/jest-electron)\n[![npm](https://img.shields.io/npm/dm/jest-electron.svg)](https://www.npmjs.com/package/jest-electron)\n\n\n1. Technological ecology of `Jest`.\n2. Complete and real `browser environment`.\n3. `Multi-renderer` for running performance.\n4. `Running and debug` is better then mock.\n\n\n## Installation\n\n\n - Add into devDependencies\n\n```bash\n$ npm i --save-dev jest-electron\n```\n\n - Update Jest config\n\n```diff\n{\n  \"jest\": {\n+    \"runner\": \"jest-electron/runner\",\n+    \"testEnvironment\": \"jest-electron/environment\"\n  }\n}\n```\n\n**Notice**: update the `runner` configure, not `testRunner`.\n\n\n\n## Related\n\n\u003e Those will be helpful when run test case with `jest-electron`.\n\n - [jest-less-loader](https://github.com/hustcc/jest-less-loader): Run test cases with import `less`, `css` code.\n - [jest-url-loader](https://github.com/hustcc/jest-url-loader): Run test cases with import `svg`, `png`, `jpg` or other url file..\n\n\n\n## CI\n\n\u003e Run test cases with `jest-electron` for continuous integration.\n\n - **GitHub action**\n\nRunning on `macOS` will be ok.\n\n\n```diff\n- runs-on: ubuntu-latest\n+ runs-on: macOS-latest\n```\n\n\n - **travis**\n\nUpdate `.travis.yml` with electron supported.\n \n```diff\nlanguage: node_js\nnode_js:\n  - \"8\"\n  - \"9\"\n  - \"10\"\n  - \"11\"\n  - \"12\"\n+ addons:\n+   apt:\n+     packages:\n+       - xvfb\n+ install:\n+   - export DISPLAY=':99.0'\n+   - Xvfb :99 -screen 0 1024x768x24 \u003e /dev/null 2\u003e\u00261 \u0026\n+   - npm install\nscript:\n  - npm run test\n```\n\nDepending on your executor, you might need to disable sandbox and shared memory usage:\n\n```bash\nexport JEST_ELECTRON_STARTUP_ARGS='--disable-dev-shm-usage --no-sandbox'\nnpm run test\n```\n\n## Env\n\n - **debug mode**\n\nKeep the electron browser window for debugging, set process env `DEBUG_MODE=1`.\n\n\n```bash\nDEBUG_MODE=1 jest\n```\n\n - **additional startup arguments**\n\nRun electron with arbitrary arguments.\n\n```bash\nJEST_ELECTRON_STARTUP_ARGS='--disable-dev-shm-usage'\n```\n\nRun electron with `--no-sandbox`, set process env `JEST_ELECTRON_STARTUP_ARGS='--no-sandbox'`.\n\n```bash\nJEST_ELECTRON_STARTUP_ARGS='--no-sandbox' jest\n```\n\n\n## License\n\nMIT@[hustcc](https://github.com/hustcc).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhustcc%2Fjest-electron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhustcc%2Fjest-electron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhustcc%2Fjest-electron/lists"}