Skip to content

Commit

Permalink
Drop mocha support
Browse files Browse the repository at this point in the history
ember-mocha is not compatible with ember@5 and its support is dropped,
so, we can remove mocha support from ember-exam now.

@embroider/macros is not needed anymore as we can use static imports now
everywhere.

qunit and ember-qunit are required peer dependencies now.

Normalize test modules to use the same syntax: tests are defined in the
scope of module, use non-arrow functions in modules and tests definitions.

Normalize `ember-qunit` name everywhere in the docs.
  • Loading branch information
andreyfel committed Dec 29, 2023
1 parent 955d71d commit fdbff8c
Show file tree
Hide file tree
Showing 42 changed files with 402 additions and 1,402 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ module.exports = {
},
env: {
node: true,
mocha: true,
},
rules: {
'ember/no-test-support-import': 'off',
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@ jobs:
fail-fast: false
matrix:
ember-try-scenario:
- ember-default-with-mocha
- embroider-safe
- embroider-safe-with-mocha
- embroider-optimized
- embroider-optimized-with-mocha
- ember-lts-4.8
- ember-lts-4.12
- ember-release
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Code Climate](https://codeclimate.com/github/trentmwillis/ember-exam/badges/gpa.svg)](https://codeclimate.com/github/trentmwillis/ember-exam)
[![Node Test Coverage](https://codeclimate.com/github/trentmwillis/ember-exam/badges/coverage.svg)](https://codeclimate.com/github/trentmwillis/ember-exam/coverage)

Ember Exam is an addon to allow you more control over how you run your tests when used in conjunction with [Ember QUnit](https://github.com/emberjs/ember-qunit) or [Ember Mocha](https://github.com/emberjs/ember-mocha). It provides the ability to randomize, split, parallelize, and load-balance your test suite by adding a more robust CLI command.
Ember Exam is an addon to allow you more control over how you run your tests when used in conjunction with [ember-qunit](https://github.com/emberjs/ember-qunit). It provides the ability to randomize, split, parallelize, and load-balance your test suite by adding a more robust CLI command.

It started as a way to help reduce flaky tests and encourage healthy test driven development. It's like [Head & Shoulders](http://www.headandshoulders.com/) for your tests!

Expand Down Expand Up @@ -70,13 +70,13 @@ $ ember exam --load-balance --parallel --server

The idea is that you can replace `ember test` with `ember exam` and never look back.

To get the unique features of Ember Exam (described in-depth below), you will need to **replace** the use of `start()` from `Ember-Qunit` or `Ember-Mocha` in `test-helper.js` with `start()` from `ember-exam`:
To get the unique features of Ember Exam (described in-depth below), you will need to **replace** the use of `start()` from `ember-qunit` in `test-helper.js` with `start()` from `ember-exam`:

```js
// test-helper.js
import start from 'ember-exam/test-support/start';

// Options passed to `start` will be passed-through to ember-qunit or ember-mocha
// Options passed to `start` will be passed-through to ember-qunit
start();
```

Expand Down Expand Up @@ -121,7 +121,7 @@ ember exam --split=2 --random
Randomizing tests with seed: hwr74nkk55vzpvi
```

_Note: You must be using QUnit version `1.23.0` or greater for this feature to work properly. This feature is not currently supported by Mocha._
_Note: You must be using QUnit version `1.23.0` or greater for this feature to work properly.

#### Randomization Iterator

Expand All @@ -145,8 +145,6 @@ $ ember exam:iterate <num> --options <options>

The `options` should be a string matching what you would use via the CLI.

_Note: This feature is not currently supported by Mocha._

### Generating Module Metadata File For Test Execution

```bash
Expand Down Expand Up @@ -195,8 +193,6 @@ and it looks something like below:
]
```

_Note: This feature is not currently supported by Mocha._


### Splitting

Expand All @@ -216,7 +212,7 @@ The `partition` option allows you to specify which test group to run after using
$ ember exam --split=4 --partition=1 --partition=2
```

_Note: Ember Exam splits tests by modifying the Ember-QUnit/Ember-Mocha's `TestLoader` to bucket each test file into a partition, where each partition has an even number of test files. This makes it possible to have unbalanced partitions. To run your tests with balanced partitions, consider using `--load-balance`. For more info, see [_Test Load Balancing_](#test-load-balancing).
_Note: Ember Exam splits tests by modifying the ember-qunit's `TestLoader` to bucket each test file into a partition, where each partition has an even number of test files. This makes it possible to have unbalanced partitions. To run your tests with balanced partitions, consider using `--load-balance`. For more info, see [_Test Load Balancing_](#test-load-balancing).

#### Split Test Parallelization

Expand Down Expand Up @@ -325,7 +321,6 @@ ok 3 Chrome 66.0 - Exam Partition 1 - browser Id 3 - some the other test
2. You must be using `ember-cli` version 3.2.0 or greater for load balancing and test failure reproduction features to work properly.
3. You must be using `ember-qunit` version 4.1.1 or greater for this feature to work properly.
4. You must be using `qunit` version 2.13.0 or greater for this feature to work properly.
5. This feature is not currently supported by Mocha.

##### Test Failure Reproduction

Expand Down Expand Up @@ -380,7 +375,6 @@ $ ember exam --replay-execution=test-execution-000000.json
1. You must be using `ember-cli` version 3.2.0 or greater for load-balnce and test failure reproduction features to work properly.
2. You must be using `ember-qunit` version 4.1.1 or greater for this feature to work properly.
3. You must be using `qunit` version 2.8.0 or greater for this feature to work properly.
4. This feature is not currently supported by Mocha.

#### Preserve Test Name

Expand Down
87 changes: 0 additions & 87 deletions addon-test-support/-private/ember-exam-mocha-test-loader.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import QUnit from 'qunit';
* @class EmberExamQUnitTestLoader
* @extends {TestLoader}
*/
export default class EmberExamQUnitTestLoader extends TestLoader {
export default class EmberExamTestLoader extends TestLoader {
constructor(testem, urlParams, qunit = QUnit) {
super();
this._testModules = [];
Expand Down
30 changes: 0 additions & 30 deletions addon-test-support/-private/get-test-loader.js

This file was deleted.

4 changes: 2 additions & 2 deletions addon-test-support/load.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import EmberExamTestLoader from './-private/ember-exam-test-loader';
import { patchTestemOutput } from './-private/patch-testem-output';
import getTestLoader from './-private/get-test-loader';

let loaded = false;

Expand All @@ -17,7 +17,7 @@ export default function loadEmberExam() {
}

loaded = true;
const EmberExamTestLoader = getTestLoader();

const testLoader = new EmberExamTestLoader(window.Testem);

if (window.Testem) {
Expand Down
22 changes: 4 additions & 18 deletions addon-test-support/start.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import loadEmberExam from 'ember-exam/test-support/load';
import {
dependencySatisfies,
macroCondition,
importSync,
} from '@embroider/macros';
import { start as qunitStart } from 'ember-qunit';

/**
* Equivalent to ember-qunit or ember-mocha's loadTest() except this does not create a new TestLoader instance
* Equivalent to ember-qunit's loadTest() except this does not create a new TestLoader instance
*
* @function loadTests
* @param {*} testLoader
Expand All @@ -23,7 +19,7 @@ function loadTests(testLoader) {

/**
* Ember-exam's own start function to set up EmberExamTestLoader, load tests and calls start() from
* ember-qunit or ember-mocha
* ember-qunit
*
* @function start
* @param {*} qunitOptions
Expand All @@ -34,15 +30,5 @@ export default function start(qunitOptions) {

const testLoader = loadEmberExam();
loadTests(testLoader);

let emberTestFramework;
if (macroCondition(dependencySatisfies('ember-qunit', '*'))) {
emberTestFramework = importSync('ember-qunit');
} else if (macroCondition(dependencySatisfies('ember-mocha', '*'))) {
emberTestFramework = importSync('ember-mocha');
}

if (emberTestFramework.start) {
emberTestFramework.start(modifiedOptions);
}
qunitStart(modifiedOptions);
}
5 changes: 0 additions & 5 deletions bin/install-test-framework.sh

This file was deleted.

10 changes: 1 addition & 9 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,5 @@ module.exports = function (defaults) {
});

const { maybeEmbroider } = require('@embroider/test-setup');
return maybeEmbroider(app, {
packagerOptions: {
webpackConfig: {
externals: {
mocha: 'mocha',
},
},
},
});
return maybeEmbroider(app, {});
};
8 changes: 0 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,4 @@ module.exports = {
includedCommands() {
return require('./lib/commands');
},

init() {
this._super.init.apply(this, arguments);

this.options.autoImport = {
exclude: ['ember-mocha', 'mocha'],
};
},
};
24 changes: 1 addition & 23 deletions lib/commands/exam.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,10 @@ module.exports = TestCommand.extend({
*/
_validateOptions(commandOptions) {
const Validator = require('../utils/tests-options-validator');
const validator = new Validator(
commandOptions,
this._getTestFramework(),
this.emberCliVersion,
);
const validator = new Validator(commandOptions, this.emberCliVersion);
return validator.validateCommands();
},

/**
* Gets the name of the test framework being used by the project.
*
* @private
* @return {string}
*/
_getTestFramework() {
const pkg = this.project.pkg;
const dependencies = pkg.dependencies || {};
const devDependencies = pkg.devDependencies || {};

if (dependencies['ember-mocha'] || devDependencies['ember-mocha']) {
return 'mocha';
} else {
return 'qunit';
}
},

/**
* Validates the command options and then runs the original test command.
*
Expand Down
14 changes: 2 additions & 12 deletions lib/utils/tests-options-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ function validateElementsUnique(arr, typeOfValue) {
* @class TestsOptionsValidator
*/
module.exports = class TestsOptionsValidator {
constructor(options, framework, emberCliVersion) {
constructor(options, emberCliVersion) {
this.options = options;
this.framework = framework;
this.emberCliVersion = emberCliVersion;
}

Expand Down Expand Up @@ -210,16 +209,7 @@ module.exports = class TestsOptionsValidator {
* @return {boolean}
*/
validateRandom() {
const shouldRandomize = typeof this.options.random === 'string';

if (shouldRandomize && this.framework === 'mocha') {
// eslint-disable-next-line no-console
console.warn(
'Mocha does not currently support randomizing test order, so tests will run in normal order. Please see https://github.com/mochajs/mocha/issues/902 for more info.',
);
}

return shouldRandomize;
return typeof this.options.random === 'string';
}

/**
Expand Down
Loading

0 comments on commit fdbff8c

Please sign in to comment.