https://github.com/meteor-community-packages/meteor-browser-tests
A helper package for Meteor test driver packages. Runs client tests in a headless browser.
https://github.com/meteor-community-packages/meteor-browser-tests
hacktoberfest meteor testing
Last synced: about 1 year ago
JSON representation
A helper package for Meteor test driver packages. Runs client tests in a headless browser.
- Host: GitHub
- URL: https://github.com/meteor-community-packages/meteor-browser-tests
- Owner: Meteor-Community-Packages
- License: mit
- Created: 2017-02-17T14:42:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-05-30T11:43:41.000Z (about 1 year ago)
- Last Synced: 2025-05-30T13:16:13.388Z (about 1 year ago)
- Topics: hacktoberfest, meteor, testing
- Language: JavaScript
- Homepage:
- Size: 116 KB
- Stars: 12
- Watchers: 5
- Forks: 22
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# meteortesting:browser-tests

[](https://github.com/Meteor-Community-Packages/meteor-browser-tests/actions/workflows/lint.yml)
[](https://github.com/Meteor-Community-Packages/meteor-browser-tests/actions/workflows/github-code-scanning/codeql)
[](https://biomejs.dev/)

_Formerly published as aldeed:browser-tests_
This package exports a `startBrowser` function for server code, which runs your client tests within a headless browser page. Meteor test driver packages can depend on this package. See the example implementation here: https://github.com/DispatchMe/meteor-mocha
NOTE: This package replaces [dispatch:phantomjs-tests](https://github.com/DispatchMe/meteor-phantomjs-tests). This package supports PhantomJS as well as others, and can be easily updated to support more.
## Usage
In your test driver package `package.js` file, add
```js
api.use('meteortesting:browser-tests@1.6.0', 'server');
```
Then in your server code, do something similar to this:
```js
import { startBrowser } from 'meteor/meteortesting:browser-tests';
function start() {
startBrowser({
stdout(data) {
console.log(data.toString());
},
stderr(data) {
console.log(data.toString());
},
done(failureCount) {
// Your code to run when client tests are done running
},
});
}
export { start };
```
And in your client code, you need to set some properties on `window` so that the browser script knows what is happening. Here is an example using Mocha:
```js
// Run the client tests. Meteor calls the `runTests` function exported by
// the driver package on the client.
function runTests() {
// These `window` properties are all used by the browser script to
// know what is happening.
window.testsAreRunning = true;
mocha.run((failures) => {
window.testsAreRunning = false;
window.testFailures = failures;
window.testsDone = true;
});
}
export { runTests };
```
## Dependencies
When using your test driver package, you will need to install the necessary NPM package dependency and indicate which headless browser you want to use.
### Puppeteer
`puppeteer@^19.11.1` is the latest version with Node 14 compatibility (Meteor 2.x is set to use Node.js version 14.x by default).
```bash
$ npm i --save-dev puppeteer@^19.11.1
$ TEST_BROWSER_DRIVER=puppeteer meteor test --once --driver-package
```
### Playwright
#### Meteor 2.x:
`playwright@^1.33.0` is the latest version with Node 14 compatibility (Meteor 2.x is set to use Node.js version 14.x by default).
```bash
$ npm i --save-dev playwright@^1.33.0
$ TEST_BROWSER_DRIVER=playwright meteor test --once --driver-package
```
#### Meteor 3.x:
```bash
$ npm i --save-dev playwright
$ npx playwright install
# additionally it might ask you to install dependencies for the browsers:
$ sudo meteor npx playwright install-deps
$ TEST_BROWSER_DRIVER=playwright meteor test --once --driver-package
```
Playwright supports multiple browsers, including Chromium, Firefox, and WebKit.
You can specify which browser to use by setting the `PLAYWRIGHT_BROWSER` environment variable.
The available options are `chromium`, `firefox`, and `webkit`.
By default, it uses `chromium`.
### Selenium ChromeDriver
General note: make sure your chrome driver version matches your installed Chrome version.
You can check the version of Chrome you have installed by going to `chrome://version/` in your browser.
#### Meteor 1.6+:
```bash
$ meteor npm i --save-dev selenium-webdriver chromedriver
$ TEST_BROWSER_DRIVER=chrome meteor test --once --driver-package
```
Chrome will run headless unless you export `TEST_BROWSER_VISIBLE=1`.
Additional command-line arguments for Chrome can be specified using the `TEST_CHROME_ARGS` environment variable. Multiple arguments are supported, separated by spaces.
If you need to include a space inside an individual argument, use `%20` instead of the space.
#### Meteor < 1.6:
**NOTE: Currently you must pin to exactly version 3.0.0-beta-2 of selenium-webdriver for earlier versions of Meteor because the latest webdriver package only works on Node 6.x+. The `-E` in the command below is important!**
```bash
$ meteor npm i -E --save-dev selenium-webdriver@3.0.0-beta-2
$ meteor npm i --save-dev chromedriver
$ TEST_BROWSER_DRIVER=chrome meteor test --once --driver-package
```
### Nightmare/Electron
```bash
$ npm i --save-dev nightmare
$ TEST_BROWSER_DRIVER=nightmare meteor test --once --driver-package
```
You can export `TEST_BROWSER_VISIBLE=1` to show the Electron window while tests run.
### PhantomJS
> Please note: Support for PhantomJS has been deprecated because it's development is suspended.
> For more information on why it got suspended, please take a look at [the repository](https://github.com/ariya/phantomjs)
```bash
$ npm i --save-dev phantomjs-prebuilt
$ TEST_BROWSER_DRIVER=phantomjs meteor test --once --driver-package
```