Run your tests with randomization, splitting, and parallelization for beautiful tests.
Installations
npm install ember-exam
Score
58.1
Supply Chain
58.1
Quality
75.4
Maintenance
100
Vulnerability
95.1
License
Developer
ember-cli
Developer Guide
Module System
Unable to determine the module system for this package.
Min. Node Version
>= 18
Typescript Support
No
Node Version
18.19.0
NPM Version
10.2.3
Statistics
286 Stars
1,228 Commits
61 Forks
12 Watching
27 Branches
48 Contributors
Updated on 28 Nov 2024
Languages
JavaScript (97.64%)
Handlebars (1.36%)
HTML (0.85%)
CSS (0.15%)
Total Downloads
Cumulative downloads
Total Downloads
15,966,764
Last day
-39.3%
7,704
Compared to previous day
Last week
-10%
46,277
Compared to previous week
Last month
3.4%
216,694
Compared to previous month
Last year
16.8%
3,252,202
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
13
Peer Dependencies
3
Dev Dependencies
48
Ember Exam
Ember Exam is an addon to allow you more control over how you run your tests when used in conjunction with 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 for your tests!
The documentation website contains examples and API information.
Table of Contents
Compatibility
- Ember.js v4.8 or above
- Ember CLI v4.8 or above
- Node.js v18 or above
Installation
Installation is as easy as running:
1$ 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
.
1$ ember exam 2$ ember exam --filter='acceptance' 3$ ember exam --server 4$ ember exam --load-balance --parallel=1
For more information and examples, please visit the documentation website.
1# A value of filter is acceptance 2$ ember exam --filter 'acceptance' 3 4# A value of parallel is 2 5$ ember exam --load-balance --parallel=2 --server 6 7# 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 8# In this instance, the value of parallel is --server 9$ 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
in test-helper.js
with start()
from ember-exam
:
1// test-helper.js 2import start from 'ember-exam/test-support/start'; 3 4// Options passed to `start` will be passed-through to ember-qunit 5start();
Version < 3.0.0
Prior to 2.1.0
, Ember Exam must be loaded by importing addon-test-support/load.js
and calling loadEmberExam
:
1// test-helper.js 2import loadEmberExam from 'ember-exam/test-support/load'; 3 4loadEmberExam(); 5
Randomization
1$ 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:
1$ ember exam --random 2$ Randomizing tests with seed: liv5d1ixkco6qlatl6o7mbo6r 3 4$ ember exam --random=this_is1337 5$ 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:
1# don't do this 2ember exam --random --split=2 3Randomizing tests with seed: --split=2 # this is not what we wanted 4 5# do this instead 6ember exam --split=2 --random 7Randomizing tests with seed: hwr74nkk55vzpvi
_Note: You must be using QUnit version 1.23.0
or greater for this feature to work properly.
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.
1$ 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:
1$ 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:
1$ ember exam:iterate <num> --options <options>
The options
should be a string matching what you would use via the CLI.
Generating Module Metadata File For Test Execution
1$ ember exam --write-module-metadata-file 2$ 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:
1[ 2 { 3 "moduleName": "Module-name", 4 "total": "Total number of tests in the module", 5 "passed": "A number of passed tests in the module", 6 "failed": "A number of failed tests in the module", 7 "skipped": "A number of skipped tests in the module", 8 "duration": "ms in Total duration to execute the module", 9 "failedTests": "A list of failed tests" 10 } 11]
and it looks something like below:
1[ 2 { 3 "moduleName": "Slowest-module", 4 "total": 12, 5 "passed": 9, 6 "failed": 1, 7 "skipped": 2, 8 "duration": 153, 9 "failedTests": ["failed-test-1"] 10 }, 11 { 12 "moduleName": "Fastest-module", 13 "total": 2, 14 "passed": 1, 15 "failed": 0, 16 "skipped": 0, 17 "duration": 123, 18 "failedTests": [] 19 } 20]
Splitting
1$ 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.
1$ 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.:
1$ ember exam --split=4 --partition=1 --partition=2
_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.
Split Test Parallelization
1$ 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:
1ok 1 PhantomJS 1.9 - Exam Partition 1 - some test 2ok 2 PhantomJS 1.9 - Exam Partition 3 - some other other test 3ok 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:
1# container 1 2ember exam --split=3 --partition=1,2 --parallel
1# container 2 2ember 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.
1$ 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 define("<module-path>", others..
.
The value for module-path
can have either string or regular expression, for instance:
1# When module path value is string. This will run all modules which match with the passed value 2$ ember exam --module-path='dummy/tests/helpers/module-for-acceptance' 3 4# When module path value is regex. This will run all modules which have `dummy` in it 5$ 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.
1# This will run tests that are defined in `/my-application/tests/unit/my-test.js` 2$ ember exam --file-path='/my-application/tests/unit/my-test.js' 3 4# This will run all test files that are under `/my-application/tests/unit/` 5$ ember exam --file-path='/my-application/tests/unit/*.js'
Test Load Balancing
1$ 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, 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:
1# ember exam --parallel=3 --load-balance 2ok 1 Chrome 66.0 - Browser Id 1 - some test 3ok 2 Chrome 66.0 - Browser Id 2 - some another test 4ok 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.
1$ 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:
1# ember exam --split=2 --partition=1 --parallel=3 --load-balance 2ok 1 Chrome 66.0 - Exam Partition 1 - browser Id 1 - some test 3ok 2 Chrome 66.0 - Exam Partition 1 - browser Id 2 - another test 4ok 3 Chrome 66.0 - Exam Partition 1 - browser Id 3 - some the other test
Important information on Load Balancing
- The
--load-balance
option is currently only supported in CI mode and for that reason no-launch cannot be used with load-balance. - You must be using
ember-cli
version 3.2.0 or greater for load balancing and test failure reproduction features to work properly. - You must be using
ember-qunit
version 4.1.1 or greater for this feature to work properly. - You must be using
qunit
version 2.13.0 or greater for this feature to work properly.
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.
1# 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. 2$ ember exam --parallel=<num> --load-balance --wef 3$ 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:
1# The command will read a test execution file specified for `replay-execution` and execute a browser Id(s) from `replay-browser` 2$ 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.
1# The command will read test-execution-000000.json and load the list of modules mapped to browserId 1 2$ 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.
1# The command will read test-execution-000000.json and load the list of module mapped to browserId 1 and 2 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.
1# The command will read test-execution-000000.json and load the list of modules mapped to browserIds from failedBrowser in the json file. 2$ 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.
1# 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 2$ ember exam --replay-execution=test-execution-000000.json
Important information on --replay-execution
and --replay-browser
- You must be using
ember-cli
version 3.2.0 or greater for load-balnce and test failure reproduction features to work properly. - You must be using
ember-qunit
version 4.1.1 or greater for this feature to work properly. - You must be using
qunit
version 2.8.0 or greater for this feature to work properly.
Preserve Test Name
When using --split
and/or --load-balance
the output will look something like:
1# ember exam --split=2 --partition=1 --parallel=3 --load-balance 2ok 1 Chrome 66.0 - Exam Partition 1 - browser Id 1 - some test 3ok 2 Chrome 66.0 - Exam Partition 1 - browser Id 2 - another test 4ok 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.
1# ember exam --split=2 --partition=1 --parallel=2 --load-balance 2ok 1 Chrome 66.0 - Exam Partition 1 - browser Id 2 - some test 3ok 2 Chrome 66.0 - Exam Partition 1 - browser Id 1 - another test 4ok 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.
1# ember exam --split=2 --partition=1 --parallel=3 --load-balance --preserve-test-name 2ok 1 Chrome 66.0 - some test 3ok 2 Chrome 66.0 - another test 4ok 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:
1// config/ember-try.js 2module.exports = { 3 command: 'ember exam --split 3 --parallel', 4 // ... 5};
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:
1module.exports = { 2 command: 'ember exam --split 20 --partition ' + process.env.PARTITION, 3 // ... 4};
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:
1const command = [ 'ember', 'exam', '--random' ]; 2const pr = process.env.TRAVIS_PULL_REQUEST; 3 4if (pr) { 5 command.push(pr); 6} 7 8module.exports = { 9 command: command.join(' '), 10 // ... 11};
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:
1{ 2 "test_page": [ 3 "tests/index.html?filter=acceptance", 4 "tests/index.html?filter=!acceptance" 5 ] 6}
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.
No vulnerabilities found.
Reason
30 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
packaging workflow detected
Details
- Info: Project packages its releases by way of GitHub Actions.: .github/workflows/release.yml:9
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:35: update your workflow using https://app.stepsecurity.io/secureworkflow/ember-cli/ember-exam/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/ember-cli/ember-exam/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:49: update your workflow using https://app.stepsecurity.io/secureworkflow/ember-cli/ember-exam/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/ember-cli/ember-exam/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:76: update your workflow using https://app.stepsecurity.io/secureworkflow/ember-cli/ember-exam/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:77: update your workflow using https://app.stepsecurity.io/secureworkflow/ember-cli/ember-exam/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/ember-cli/ember-exam/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/ember-cli/ember-exam/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/ember-cli/ember-exam/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/ember-cli/ember-exam/release.yml/main?enable=pin
- Info: 0 out of 10 GitHub-owned GitHubAction dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Reason
38 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-whgm-jr23-g3j9
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-jcpv-g9rr-qxrc
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-6vfc-qv3f-vr6c
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-wrvr-8mpx-r7pp
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3
- Warn: Project is vulnerable to: GHSA-gqgv-6jq5-jjj9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-7xfp-9c55-5vqj
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-xc7v-wxcw-j472
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
3.8
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More