NOTE: This is a fork of electron-ava
The source for electron-ava used to be on GitHub, but has since been deleted. The contents of this repo were pulled from npm for the sole purpose of upgrading Electron so that a dependent project could upgrade Electron.
All the simpleness of AVA tests for Electron.
If you are already using ava
, you can just replace ava
with electron-ava
in your package.json
(assuming all your tests run in the main process. If
not, see renderer tests).
Otherwise, you can install electron-ava
with the following command:
$ npm install electron-ava --save-dev
Or, if you prefer yarn:
$ yarn add electron-ava -D
Then add the following in your package.json
:
"scripts": {
"test": "electron-ava"
}
It should now look a bit like this:
{
"scripts": {
"test": "electron-ava"
},
"devDependencies": {
"electron-ava": "^0.1.0"
}
}
That's all! You can now run your Electron tests in AVA using yarn test
or npm test
.
Usage
electron-ava [<file|directory|glob> ...]
Options
--fail-fast Stop after first test failure
--serial, -s Run tests serially
--tap, -t Generate TAP output
--verbose, -v Enable verbose output
--no-cache Disable the transpiler cache
--no-power-assert Disable Power Assert
--match, -m Only run tests with matching title (Can be repeated)
--watch, -w Re-run tests when tests and source files change
--source, -S Pattern to match source files so tests can be re-run (Can be repeated)
--timeout, -T Set global timeout
--concurrency, -c Maximum number of test files running at the same time (EXPERIMENTAL)
--update-snapshots, -u Update snapshots
--renderer Run the tests in the renderer process
Examples
electron-ava
electron-ava test.js test2.js
electron-ava test-*.js
electron-ava test
Default patterns when no arguments:
test.js test-*.js test/**/*.js **/__tests__/**/*.js **/*.test.js
The CLI has the same options as the
AVA CLI,
except for the options --init
and --renderer
. --init
has not yet been added and
--renderer
has been added.
--renderer
allows you to run the tests in the renderer process instead of the main process.
If you want to run your tests in the renderer process, you can add the renderer
option to the electron-ava
section in your package.json
and give it the value true
.
This config works the same as the ava
config.
Your package.json
then should look like this:
{
"scripts": {
"test": "electron-ava"
},
"devDependencies": {
"electron-ava": "^0.1.0"
},
"electron-ava": {
"renderer": true
}
}
If you want to pass options to the browser window for the renderer process, you can do this by
adding the windowOptions
option to your config. This object will then be passed to the
BrowserWindow
constructor.
For example, if you want to have with the title My fancy tests
, you could update your package.json
to look like this:
{
"scripts": {
"test": "electron-ava"
},
"devDependencies": {
"electron-ava": "^0.1.0"
},
"electron-ava": {
"renderer": true,
"windowOptions": {
"title": "My fancy tests"
}
}
}