Simplify Mocha npm scripts (#12313)

The npm scripts used to run Mocha scripts have been greatly simplified.
As we transition more tests from Mocha to Jest it was becoming
increasingly difficult to update the CLI arguments to keep all of these
scripts working correctly. This reorganization should make that process
much simpler.

The base Mocha options are in `.mocharc.js` - all except for the target
tests to run. Those are still given via the CLI. There is a second
config file specifically for the `test:unit:lax` tests (i.e. the Mocha
tests that have no coverage requirements) because it requires a change
to the `ignored` configuration property. We can create an additional
configuration file for each test script we add that needs further
configuration changes.

The `test:unit:path` script used to be used to run Mocha tests at a
given path. Now that can be done using `yarn mocha` instead, so this
script has been removed.

The `yarn watch` command has been broken for some time now, so it has
been removed as well. Mocha tests can still be run with a file watcher
using `yarn mocha --watch <path>` or `yarn test:unit:mocha --watch`.

The README has been updated to remove references about the `watch`
command that was removed. I considered explaining the other test
scripts there as well, but they were difficult to explain I will
attempt to update the README after making further simplifications
instead.
feature/default_network_editable
Mark Stacey 3 years ago committed by GitHub
parent b07354af52
commit e4cf12674e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      .mocharc.js
  2. 5
      .mocharc.lax.js
  3. 4
      README.md
  4. 10
      package.json
  5. 7
      test/e2e/run-e2e-test.js

@ -0,0 +1,7 @@
module.exports = {
// TODO: Remove the `exit` setting, it can hide broken tests.
exit: true,
ignore: ['./app/scripts/migrations/*.test.js'],
recursive: true,
require: ['test/env.js', 'test/setup.js'],
}

@ -0,0 +1,5 @@
const baseConfig = require('./.mocharc');
module.exports = Object.assign({}, baseConfig, {
ignore: [...baseConfig.ignore, './app/scripts/controllers/permissions/*.test.js']
});

@ -46,9 +46,7 @@ To start the [React DevTools](https://github.com/facebook/react-devtools) and [R
### Running Unit Tests and Linting
Run unit tests and the linter with `yarn test`.
To run just unit tests, run `yarn test:unit`. To run unit tests continuously with a file watcher, run `yarn watch`.
Run unit tests and the linter with `yarn test`. To run just unit tests, run `yarn test:unit`.
You can run the linter by itself with `yarn lint`, and you can automatically fix some lint problems with `yarn lint:fix`. You can also run these two commands just on your local changes to save time with `yarn lint:changed` and `yarn lint:changed:fix` respectively.

@ -26,11 +26,10 @@
"dapp-forwarder": "concurrently -k -n forwarder,dapp -p '[{time}][{name}]' 'yarn forwarder' 'yarn dapp'",
"test:unit": "./test/test-unit-combined.sh",
"test:unit:jest": "./test/test-unit-jest.sh",
"test:unit:global": "mocha --exit --require test/env.js --require test/setup.js --recursive test/unit-global/*.test.js",
"test:unit:mocha": "mocha --exit --require test/env.js --require test/setup.js --ignore './app/scripts/migrations/*.test.js' --recursive './app/**/*.test.js'",
"test:unit:lax": "mocha --exit --require test/env.js --require test/setup.js --ignore './app/scripts/controllers/permissions/*.test.js' --ignore './app/scripts/migrations/*.test.js' --recursive './app/**/*.test.js'",
"test:unit:strict": "mocha --exit --require test/env.js --require test/setup.js --recursive './app/scripts/controllers/permissions/*.test.js'",
"test:unit:path": "mocha --exit --require test/env.js --require test/setup.js --recursive",
"test:unit:global": "mocha test/unit-global/*.test.js",
"test:unit:mocha": "mocha './app/**/*.test.js'",
"test:unit:lax": "mocha --config '.mocharc.lax.js' './app/**/*.test.js'",
"test:unit:strict": "mocha './app/scripts/controllers/permissions/*.test.js'",
"test:e2e:chrome": "SELENIUM_BROWSER=chrome node test/e2e/run-all.js",
"test:e2e:chrome:metrics": "SELENIUM_BROWSER=chrome node test/e2e/run-e2e-test.js test/e2e/metrics.spec.js",
"test:e2e:firefox": "SELENIUM_BROWSER=firefox node test/e2e/run-all.js",
@ -55,7 +54,6 @@
"verify-locales": "node ./development/verify-locale-strings.js",
"verify-locales:fix": "node ./development/verify-locale-strings.js --fix",
"mozilla-lint": "addons-linter dist/firefox",
"watch": "mocha --watch --require test/env.js --require test/setup.js --reporter min --recursive \"test/unit/**/*.js\" \"ui/**/*.test.js\"",
"devtools:react": "react-devtools",
"devtools:redux": "remotedev --hostname=localhost --port=8000",
"start:dev": "concurrently -k -n build,react,redux yarn:start yarn:devtools:react yarn:devtools:redux",

@ -74,7 +74,12 @@ async function main() {
}
await retry({ retries }, async () => {
await runInShell('yarn', ['mocha', '--no-timeouts', e2eTestPath]);
await runInShell('yarn', [
'mocha',
'--no-config',
'--no-timeouts',
e2eTestPath,
]);
});
}

Loading…
Cancel
Save