{"id":15734159,"url":"https://github.com/eemeli/mocha-selenium-bridge","last_synced_at":"2025-04-09T19:08:40.679Z","repository":{"id":49660133,"uuid":"180027257","full_name":"eemeli/mocha-selenium-bridge","owner":"eemeli","description":"Run tests in the browser, report results in Node","archived":false,"fork":false,"pushed_at":"2023-04-30T20:28:41.000Z","size":154,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-13T23:58:18.121Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eemeli.png","metadata":{"files":{"readme":"README.md","changelog":null,"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},"funding":{"github":"eemeli"}},"created_at":"2019-04-07T21:41:24.000Z","updated_at":"2022-09-11T17:25:03.000Z","dependencies_parsed_at":"2024-10-04T01:01:11.870Z","dependency_job_id":"99b2c3a8-8b1a-4828-82f1-6c926b90a078","html_url":"https://github.com/eemeli/mocha-selenium-bridge","commit_stats":{"total_commits":39,"total_committers":2,"mean_commits":19.5,"dds":0.02564102564102566,"last_synced_commit":"68c02959f2d8bd025db1911c7cd0766dc7dd012e"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fmocha-selenium-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fmocha-selenium-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fmocha-selenium-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fmocha-selenium-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eemeli","download_url":"https://codeload.github.com/eemeli/mocha-selenium-bridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239520128,"owners_count":19652633,"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":[],"created_at":"2024-10-04T01:00:53.965Z","updated_at":"2025-02-18T17:41:30.703Z","avatar_url":"https://github.com/eemeli.png","language":"JavaScript","funding_links":["https://github.com/sponsors/eemeli"],"categories":[],"sub_categories":[],"readme":"# mocha-selenium-bridge\n\nThis is a tool that allows you to run [Mocha] tests in browser environments from the command line, while also reporting the test results to your command line terminal. This allows you to take a pre-existing Node test suite and run it in multiple environments, or to define complex automated browser tests without needing to use the [selenium-webdriver] API.\n\nThe normal way of using Mocha and Selenium together is a bit tricky, as practically every test needs to undertake multiple operations to interact between the Node and browser environments. Our approach circumvents all of that by running Mocha entirely in the browser, and only sending the events one-way across the Selenium interface.\n\n## Setup\n\nFirst, install the package along with `mocha` itself:\n\n```\nnpm install --save-dev mocha-selenium-bridge mocha\n```\n\nNext, prepare your [browser-based tests] as usual. In addition to including mocha.js, also add our `Bridge` reporter:\n\n```html\n\u003cscript src=\"../node_modules/mocha-selenium-bridge/browser/reporter.js\"\u003e\u003c/script\u003e\n```\n\nAlternatively, the reporter is also available via [unpkg]:\n\n```html\n\u003cscript src=\"https://unpkg.com/mocha-selenium-bridge/browser/reporter.js\"\u003e\u003c/script\u003e\n```\n\nIf included after mocha.js, the reporter will automatically register itself. You may also register it manually:\n\n```js\nmocha.reporter(Bridge)\n```\n\nIn order to further configure Mocha, you should use the [Mocha JavaScript API], as the browser instance does not support command-line options or configuration files.\n\n## Usage\n\nAs your tests run, the Mocha test events will be queued in a buffer that'll be read by the Node part of `mocha-selenium-bridge`, and there reconstructed into corresponding events. These can then in turn be fed into any of the standard Mocha reporters.\n\nTo make that work, a CLI is provided. This command will spawn a new headless Chrome instance and open your local file `test.html` in it. Provided that it includes a `mocha.run()` call, the tests will automatically run, and on completion the browser will be closed:\n\n```\nnpx mocha-selenium-bridge test.html --browser chrome\n```\n\nBy default, messages logged to the browser console will be also logged to the terminal, and any calls to `console.error` will cause the test run to fail. To adjust this behaviour, use `--silent` and `--allow-console`.\n\nFor more complete documentation of the CLI, use its `--help` argument. Note in particular `--driver`, which allows you to define and build your own WebDriver for use e.g. with [BrowserStack] or other Selenium cloud providers.\n\n## JavaScript API\n\n```ts\nimport executeTests from 'mocha-selenium-bridge'\n\nconst executeTests: (driver: WebDriver, Reporter: Function, url: string, options?: {\n  eventsName = '_TEST_EVENTS';\n  runnerName = '_TEST_RUNNER';\n  interval = 100; // buffer poll interval: 100ms\n  timeout = 10000; // maximum time between events: 10s\n}) =\u003e Promise\u003cnumber\u003e\n```\n\nThe first three arguments are all required. `Reporter` should be a Mocha reporter; by default the CLI uses `require('mocha/lib/reporters').spec`. On success, the returned promise resolves to the count of failed tests, so may be used directly as an exit code. Your application code should take care of calling `driver.quit()` as appropriate.\n\n[mocha]: https://mochajs.org/\n[browser-based tests]: https://mochajs.org/#running-mocha-in-the-browser\n[mocha javascript api]: https://mochajs.org/api/mocha\n[selenium-webdriver]: https://www.npmjs.com/package/selenium-webdriver\n[unpkg]: https://unpkg.com/\n[browserstack]: https://www.browserstack.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feemeli%2Fmocha-selenium-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feemeli%2Fmocha-selenium-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feemeli%2Fmocha-selenium-bridge/lists"}