• Stars
    star
    286
  • Rank 144,690 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run your tests with randomization, splitting, and parallelization for beautiful tests.

Ember Exam

Build Status NPM Version Ember Observer Score Code Climate Node Test Coverage

Ember Exam is an addon to allow you more control over how you run your tests when used in conjunction with Ember QUnit or Ember Mocha. 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 for your tests!

Introduction to Ember Exam

The documentation website contains examples and API information.

Table of Contents

Installation

Installation is as easy as running:

$ ember install ember-exam

How To Use

Using Ember Exam is fairly straightforward as it extends directly from the default Ember-CLI test command. So, by default, it will work exactly the same as ember test.

$ ember exam
$ ember exam --filter='acceptance'
$ ember exam --server
$ ember exam --load-balance --parallel=1

For more information and examples, please visit the documentation website.

# A value of filter is acceptance
$ ember exam --filter 'acceptance'

# A value of parallel is 2
$ ember exam --load-balance --parallel=2 --server

# If a `=` is not used to pass a value to an option that requires a value, it will take anything passed after a space as it's value
# In this instance, the value of parallel is --server
$ 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:

// 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
start();

Version < 3.0.0

Prior to 2.1.0, Ember Exam must be loaded by importing addon-test-support/load.js and calling loadEmberExam:

// test-helper.js
import loadEmberExam from 'ember-exam/test-support/load';

loadEmberExam();

Randomization

$ ember exam --random[=<seed>]

The random option allows you to randomize the order in which your tests run. You can optionally specify a "seed" value from which to randomize your tests in order to reproduce results. The seed can be any string value. Regardless of whether you specify a seed or not, Ember Exam will log the seed value used for the randomization at the beginning of the test run:

$ ember exam --random
$ Randomizing tests with seed: liv5d1ixkco6qlatl6o7mbo6r

$ ember exam --random=this_is1337
$ Randomizing tests with seed: this_is1337

If you use random without specifying a seed, it must be the last argument you pass. Otherwise, Ember Exam will attempt to interpret any following arguments as the seed value. In other words:

# don't do this
ember exam --random --split=2
Randomizing tests with seed: --split=2 # this is not what we wanted

# do this instead
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.

Randomization Iterator

Randomization can be helpful for identifying non-atomic or order-dependent tests. To that end, Ember Exam provides an iterator to make it easy to test lots of variations in your test suite order quickly.

$ ember exam:iterate <num>

This command will build your application once, and then run the test suite with the random option for the specified number of iterations. You can optionally skip the build by using a previous build via the path option:

$ ember exam:iterate <num> --path <build-path>

Finally, you can pass additional options through to the exam command used to run the tests via the options flag:

$ 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

$ ember exam --write-module-metadata-file
$ ember exam --wmmf

The --write-module-metadata-file, wmmf as an alias, allows you to generate a module metadata file after a test run. The file provides metadata about the test modules executed.

It creates a json file, module-metadata-<timestamp>.json, which contains an array of elements representing metadata of modules executed by sorted by ascending order:

[
  {
    "moduleName": "Module-name",
    "total": "Total number of tests in the module",
    "passed": "A number of passed tests in the module",
    "failed": "A number of failed tests in the module",
    "skipped": "A number of skipped tests in the module",
    "duration": "ms in Total duration to execute the module",
    "failedTests": "A list of failed tests"
  }
]

and it looks something like below:

[
  {
    "moduleName": "Slowest-module",
    "total": 12,
    "passed": 9,
    "failed": 1,
    "skipped": 2,
    "duration": 153,
    "failedTests": ["failed-test-1"]
  },
  {
    "moduleName": "Fastest-module",
    "total": 2,
    "passed": 1,
    "failed": 0,
    "skipped": 0,
    "duration": 123,
    "failedTests": []
  }
]

Note: This feature is not currently supported by Mocha.

Splitting

$ ember exam --split=<num>

The split option allows you to specify the number of partitions greater than one to spread your tests across. Ember Exam will then proceed to run the first batch of tests.

$ ember exam --split=<num> --partition=<num>

The partition option allows you to specify which test group to run after using the split option. It is one-indexed, so if you specify a split of 3, the last group you could run is 3 as well. You can also run multiple partitions, e.g.:

$ 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.

Split Test Parallelization

$ ember exam --split=<num> --parallel

The parallel option allows you to run your split tests across multiple test pages in parallel in Testem. It will use a separate browser instance for each group of tests. So, if you specify a split of 3, then 3 browser instances will be spawned with the output looking something like:

ok 1 PhantomJS 1.9 - Exam Partition 1 - some test
ok 2 PhantomJS 1.9 - Exam Partition 3 - some other other test
ok 3 PhantomJS 1.9 - Exam Partition 2 - some other test

You can also combine the parallel option with the partition option to split tests, and then recombine partitions into parallel runs. This would, for example, allow you to run tests in multiple CI containers and have each CI container parallelize its list of tests.

For example, if you wanted to run your tests across two containers, but have one of them run twice as many tests as the other, and run them in parallel, you could do this:

# container 1
ember exam --split=3 --partition=1,2 --parallel
# container 2
ember exam --split=3 --partition=3 --parallel

Note 1: Ember Exam will respect the parallel setting of your Testem config file while running tests in parallel. The default value for parallel in Testem is 1, which means you'll need a non-default value to actually see parallel behavior.

Note 2: Ember Exam sets process.env.EMBER_EXAM_SPLIT_COUNT for convenience. You can use this in your Testem file.

Note 3: You must be using Testem version 1.5.0 or greater for this feature to work properly.

Filtering

Ember Exam provides options to filter test suites by two types - module path and test file path.

$ ember exam --module-path=<module-path>

The module-path option allows you to filter module paths by a given value. Module paths are mapped by test files and they are generated during ember build. After the build, tests.js file is created and it resides under /assets. The file is combined of all tests in an application and it has a form of define("<module-path>", others...

The value for module-path can have either string or regular expression, for instance:

# When module path value is string. This will run all modules which match with the passed value
$ ember exam --module-path='dummy/tests/helpers/module-for-acceptance'

# When module path value is regex. This will run all modules which have `dummy` in it
$ ember exam --module-path='!/dummy/'

The file-path option is to filter tests by test file path. The test file path is a location of the test file in a file system. You can specify file-path to a location of specific test file path or you can use wildcards in paths to target multiple test files.

# This will run tests that are defined in `/my-application/tests/unit/my-test.js`
$ ember exam --file-path='/my-application/tests/unit/my-test.js'

# This will run all test files that are under `/my-application/tests/unit/`
$ ember exam --file-path='/my-application/tests/unit/*.js'

Test Load Balancing

$ ember exam --parallel=<num> --load-balance

The load-balance option allows you to load balance test files against multiple browsers. It will order the test files by test types, e.g. acceptance | integration | unit | eslint, and load balance the ordered test files between the browsers dynamically rather than statically. Note: parallel must be used along with load-balance to specify a number of browser(s)

The load-balance option was added to version 1.1 to address execution performance when running against a large test suite.

Web browsers and the testem server communicate via promise in order to send and receive test file. The promise timeout value is set to 15 seconds, and is configurable by adding asyncTimeout=[timeout] as a querystring param in the test URL or adding to the test_page option in the testem config. For example, if you specify load-balance and parallel equals 3, then three browser instances will be created and the output will look something like:

# ember exam --parallel=3 --load-balance
ok 1 Chrome 66.0 - Browser Id 1 - some test
ok 2 Chrome 66.0 - Browser Id 2 - some another test
ok 3 Chrome 66.0 - Browser Id 3 - some the other test

You can also specify the split and partition options with load-balance to load a portion of test modules on multiple CI containers.

$ ember exam --split=<num> --partition=<num> --parallel=<num> --load-balance

This command will split test files and load-balance tests from the specified partition across the browsers. For example ember exam --split=2 --partition=1 --parallel=3 --load-balance, the complete list of test files are split into two halves. With the first half of the list load balanced against three browsers. The output will look something like below:

# ember exam --split=2 --partition=1 --parallel=3 --load-balance
ok 1 Chrome 66.0 - Exam Partition 1 - browser Id 1 - some test
ok 2 Chrome 66.0 - Exam Partition 1 - browser Id 2 - another test
ok 3 Chrome 66.0 - Exam Partition 1 - browser Id 3 - some the other test

Important information on Load Balancing

  1. The --load-balance option is currently only supported in CI mode and for that reason no-launch cannot be used with load-balance.
  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

Due to the dynamic nature of the load-balance option, test file execution order can vary between runs. In order to reproduce a past test execution, the execution must be recorded via passing --write-execution-file or --wef, which allows generating a JSON file that enables rerunning the past test execution. The option is only allowed when load-balance is passed.

# The command will load in test balanced mode with <num> of browser(s). After the test suite execution, it will generate a test-execution json file.
$ ember exam --parallel=<num> --load-balance --wef
$ ember exam --parallel=<num> --load-balance --write-execution-file

The file is stored in the root directory and the naming structure is test-execution-<timestamp>.json. To replay the test execution for particular browser(s), do the following:

# The command will read a test execution file specified for `replay-execution` and execute a browser Id(s) from `replay-browser`
$ ember exam --replay-execution=[string] --replay-browser=[num]

replay-execution allows you to specify a path to the json file to run execution against and replay-browser is to specify browser ID(s) to execute.

# The command will read test-execution-000000.json and load the list of modules mapped to browserId 1
$ ember exam --replay-execution=test-execution-000000.json --replay-browser=1

The above command will read test-execution-000000.json and load the list of modules which is mapped by browser ID #1.

replay-browser can be an array of browser IDs. For instance --replay-browser=1,2 will start two browsers and execute a list of modules which were previously run by browsers #1 and #2.

# The command will read test-execution-000000.json and load the list of module mapped to browserId 1 and 2
$ ember exam --replay-execution=test-execution-000000.json --replay-browser=1,2

When replay-browser value is not specified it will execute browserId(s) read from failedBrowser in the test execution file.

# The command will read test-execution-000000.json and load the list of modules mapped to browserIds from failedBrowser in the json file.
$ ember exam --replay-execution=test-execution-000000.json

When replay-browser value is not specified and there is no value for failedBrowser in the json file it will rerun all list of modules.

# The command will read test-execution-000000.json and load the list of module mapped to all browserIds when failedBrowser is none in the json file
$ ember exam --replay-execution=test-execution-000000.json

Important information on --replay-execution and --replay-browser

  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

When using --split and/or --load-balance the output will look something like:

# ember exam --split=2 --partition=1 --parallel=3 --load-balance
ok 1 Chrome 66.0 - Exam Partition 1 - browser Id 1 - some test
ok 2 Chrome 66.0 - Exam Partition 1 - browser Id 2 - another test
ok 3 Chrome 66.0 - Exam Partition 1 - browser Id 3 - some the other test

However, if you change the amount of parallelization, or randomize across partitions, the output will change for the same test, which may be an issue if you are tracking test insights over time.

# ember exam --split=2 --partition=1 --parallel=2 --load-balance
ok 1 Chrome 66.0 - Exam Partition 1 - browser Id 2 - some test
ok 2 Chrome 66.0 - Exam Partition 1 - browser Id 1 - another test
ok 3 Chrome 66.0 - Exam Partition 1 - browser Id 2 - some the other test

You can add --preserve-test-name to remove the dynamic segments of the output (partition and browser) to ensure the output test names are always the same.

# ember exam --split=2 --partition=1 --parallel=3 --load-balance --preserve-test-name
ok 1 Chrome 66.0 - some test
ok 2 Chrome 66.0 - another test
ok 3 Chrome 66.0 - some the other test

Advanced Configuration

Ember Exam does its best to allow you to run your test suite in a way that is effective for your individual needs. To that end, there are lots of advanced ways to configure your setup by integrating with other aspects of the Ember testing environment. The following sections will cover a few of the more common scenarios.

Ember Try & CI Integration

Integrating ember-exam with ember-try is remarkably easy. Define a command in your ember-try.js config that leverages the exam command:

// config/ember-try.js
module.exports = {
  command: 'ember exam --split 3 --parallel',
  // ...
};

Using environmental variables gives you flexibility in how you run your tests. For instance, you could distribute your tests across processes instead of parallelizing them by specifying a PARTITION variable in your process environment and then consuming it like so:

module.exports = {
  command: 'ember exam --split 20 --partition ' + process.env.PARTITION,
  // ...
};

If you are working with Travis CI then you can also easily set up seeded-random runs based on PR numbers. Similar to the following:

const command = [ 'ember', 'exam', '--random' ];
const pr = process.env.TRAVIS_PULL_REQUEST;

if (pr) {
  command.push(pr);
}

module.exports = {
  command: command.join(' '),
  // ...
};

You can refer to Travis' default environment variables to see what else you could possibly leverage for your test setup.

Test Suite Segmentation

Some test suites like to segment which tests run based on various facets such as type of test, feature being tested, and so on. This can be accomplished by leveraging Testem's ability to have multiple test pages:

{
  "test_page": [
    "tests/index.html?filter=acceptance",
    "tests/index.html?filter=!acceptance"
  ]
}

You can use this feature in conjunction with Ember Exam's features, which will allow you to segment your test suite but still gain benefits from randomization and splitting.

More Repositories

1

ember-cli

The Ember.js command line utility.
JavaScript
3,261
star
2

ember-cli-update

Update Ember CLI projects
JavaScript
277
star
3

ember-twiddle

JSFiddle type thing for ember-cli style code
JavaScript
268
star
4

eslint-plugin-ember

An ESLint plugin that provides set of rules for Ember applications based on commonly known good practices.
JavaScript
260
star
5

ember-ajax

Service for making AJAX requests in Ember applications
JavaScript
213
star
6

ember-page-title

Page title management for Ember.js Apps
JavaScript
188
star
7

ember-try

An ember-cli addon to test against multiple npm dependencies, such as ember and ember-data.
JavaScript
179
star
8

ember-fetch

HTML5 fetch polyfill from github wrapped and bundled for ember-cli users.
JavaScript
176
star
9

ember-cli-deprecation-workflow

JavaScript
165
star
10

ember-cli-mocha

Mocha and Chai tests for ember-cli applications
JavaScript
147
star
11

ember-cli-eslint

Ember CLI addon for linting Ember projects with ESLint
JavaScript
116
star
12

ember-new-output

Change history of new Ember-CLI apps
JavaScript
91
star
13

ember-resolver

JavaScript
87
star
14

broccoli-asset-rev

Broccoli plugin to add fingerprint checksums and CDN URLs to your assets
JavaScript
86
star
15

ember-rfc176-data

JSON data for Ember.js RFC #176
JavaScript
83
star
16

loader.js

minimal amd loader mostly stolen from wycats.
JavaScript
79
star
17

ember-cli-htmlbars

JavaScript
77
star
18

ember-template-imports

Template import support in Ember!
JavaScript
74
star
19

ember-cli-htmlbars-inline-precompile

📃 Precompile inline HTMLBars templates via ES6 tagged template strings
JavaScript
67
star
20

ember-cli-todos

JavaScript
67
star
21

babel-plugin-feature-flags

A babel transform for managing feature flags
JavaScript
57
star
22

ember-cli-app-version

Adds your app's version to Ember Inspector's Info tab
JavaScript
55
star
23

ember-cli-shims

DEPRECATED - ES6 import shims for Ember.js
JavaScript
46
star
24

ember-octane-blueprint

App and Addon blueprints for Ember Octane
JavaScript
46
star
25

rfcs

Archive of RFCs for changes to ember-cli (for current RFC repo see https://github.com/emberjs/rfcs)
45
star
26

ember-cli-babel-polyfills

Split-build polyfills for evergreen and legacy browsers
JavaScript
34
star
27

ember-cli-qunit

QUnit testing package for ember-cli applications
JavaScript
30
star
28

ember-compatibility-helpers

Helpers that allow you to write backwards compat Ember addons
JavaScript
24
star
29

ember-cli-version-checker

Dependency version checker for Ember CLI addons
JavaScript
24
star
30

broccoli-viz

library to read/parse and produce various visualizations of broccoli.
JavaScript
23
star
31

ember-cli-blueprint-test-helpers

Test helpers for testing ember-cli blueprints
JavaScript
23
star
32

ember-cli-terser

JavaScript minification for Ember-CLI
JavaScript
23
star
33

ember-cli-inject-live-reload

Ember CLI plugin that injects live-reload script into HTML content
JavaScript
22
star
34

ember-cli-chai

Chai assertions for Ember.js
JavaScript
21
star
35

babel-plugin-filter-imports

A babel transform for filtering out imports
JavaScript
18
star
36

broccoli-caching-writer

JavaScript
17
star
37

ember-addon-output

Change history of new Ember-CLI addons
JavaScript
16
star
38

core-object

JavaScript
16
star
39

babel-plugin-ember-modules-api-polyfill

Polyfill for Ember JS API
JavaScript
15
star
40

ember-load-initializers

JavaScript
14
star
41

console-ui

JavaScript
14
star
42

broccoli-es6modules

new es6 module transpiler
JavaScript
14
star
43

ember-export-application-global

JavaScript
14
star
44

babel-plugin-debug-macros

TypeScript
13
star
45

ember-cli.github.io

Our documentation site
SCSS
13
star
46

ember-router-generator

JavaScript
12
star
47

ember-welcome-page

Welcome page for Ember CLI applications
JavaScript
12
star
48

broccoli-terser-sourcemap

Broccoli filter to uglify with sourcemaps
JavaScript
10
star
49

broccoli-asset-rewrite

Broccoli plugin to rewrite a source tree from an asset map.
JavaScript
10
star
50

ember-cli-test-loader

JavaScript
10
star
51

ember-source-channel-url

JavaScript
10
star
52

stress-app

HTML
9
star
53

capture-exit

JavaScript
9
star
54

ember-next

A home for experiments that aim to become the defaults when running ember-new.
JavaScript
9
star
55

babel-plugin-htmlbars-inline-precompile

Babel plugin to replace tagged template strings with precompiled HTMLBars templates
JavaScript
9
star
56

broccoli-lint-eslint

Integrates JavaScript linting with ESLint as part of your Broccoli build pipeline.
JavaScript
8
star
57

blprnt

JavaScript
7
star
58

ember-cli-clean-css

CSS minification via clean-css for Ember CLI
JavaScript
6
star
59

exists-sync

Deprecated, please use fs.existsSync instead
JavaScript
6
star
60

ember-disable-prototype-extensions

Disables Ember's prototype extensions
JavaScript
6
star
61

silent-error

JavaScript
5
star
62

ember-cli-jshint

JSHint lint tests for your Ember CLI projects
JavaScript
5
star
63

create-ember-app

yarn create ember-app <name>
JavaScript
4
star
64

broccoli-middleware

Broccoli asset builder middleware
HTML
4
star
65

ember-cli-babili

JavaScript
4
star
66

ember-cli-update-codemods-manifest

Master list of codemods and their instructions used by ember-cli-update
JavaScript
4
star
67

amd-name-resolver

Algorithm for resolving AMD module names
JavaScript
3
star
68

ember-cli-string-utils

JavaScript
3
star
69

ember-cli-legacy-blueprints

Ember and Ember-Data specific blueprints for ember-cli projects not using the Ember and Ember-Data addons.
JavaScript
3
star
70

ember-cli-lodash-subset

JavaScript
2
star
71

ember-cli-default-packager

Default Packager for Ember CLI. More details in https://github.com/ember-cli/rfcs/pull/110.
TypeScript
2
star
72

codesandbox

Official Ember.js template for codesandbox.io
JavaScript
2
star
73

broccoli-amd-funnel

Funnel based on whether a module is AMD or not
JavaScript
1
star
74

broccoli-builder

JavaScript
1
star
75

calculate-cache-key-for-tree

ember-cli addon tree cache key builder
JavaScript
1
star
76

broccoli-funnel-reducer

JavaScript
1
star
77

app-blueprint-test

JavaScript
1
star
78

ember-cli-preprocess-registry

JavaScript
1
star
79

ember-cli-import-polyfill

Backports newer addon import API to older ember-cli versions.
JavaScript
1
star
80

node-modules-path

JavaScript
1
star
81

ember-build-utilities

A suite of build utilities for constructing Ember CLI build pipelines
JavaScript
1
star
82

ember-try-config

Config helper for ember-try
JavaScript
1
star
83

broccoli-config-replace

Simple templating using a config.json and regex patterns.
JavaScript
1
star
84

ember-cli-changelog

Tool used to generate changelogs for ember-cli.
JavaScript
1
star
85

create-ember-addon

yarn create ember-addon <name>
JavaScript
1
star