Skip to content

Extend bootstrap/teardown configuration options behaviour #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ Here is an overview of available options with their defaults:
* **helpers**: `{}` - list of enabled helpers
* **mocha**: `{}` - mocha options, [reporters](http://codecept.io/reports/) can be configured here
* **name**: `"tests"` - test suite name (not used)
* **bootstrap**: `"./bootstrap.js"` - JS file to be executed before tests
* **teardown**: - JS file to be executed after tests
* **bootstrap**: `"./bootstrap.js"` - an option to run code _before_ tests are run. It can either be:
* a path to a js file that will be executed (via `require`) before tests. If the file exports a
function, the function is called right away with a callback function as the only parameter. When the
callback is called with no arguments, tests are executed. If instead the callback is called with an
error as first argument, test execution is aborted and the process stops
* a function (dynamic configuration only). The function is called before tests with a callback function
as the only parameter. When the callback is called with no arguments, tests are executed. If instead
the callback is called with an error as first argument, test execution is aborted and the process stops
* **teardown**: - an option to run code _after_ tests are run. It can either be:
* a path to a js file that will be executed (via `require`) after tests. If the file exports a
function, the function is called right away
* a function (dynamic configuration only). The function is called after tests
* **translation**: - [locale](http://codecept.io/translation/) to be used to print steps output, as well as used in source code.

## Dynamic Configuration
Expand Down Expand Up @@ -59,4 +69,4 @@ For instance, with the config above we can change browser value using `profile`

```
codeceptjs run --profile firefox
```
```
13 changes: 10 additions & 3 deletions lib/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,27 @@ class Codecept {

// loading bootstrap
bootstrap(callback) {
if (this.config.bootstrap && fileExists(fsPath.join(codecept_dir, this.config.bootstrap))) {
if (typeof this.config.bootstrap === 'string' && fileExists(fsPath.join(codecept_dir, this.config.bootstrap))) {
var bootstrap = require(fsPath.join(codecept_dir, this.config.bootstrap));
if (typeof bootstrap === 'function') {
bootstrap(callback);
return;
}
callback();
} else if (typeof this.config.bootstrap === 'function') {
this.config.boostrap(callback);
}
}

// loading teardown
teardown() {
if (this.config.teardown && fileExists(fsPath.join(codecept_dir, this.config.teardown))) {
require(fsPath.join(codecept_dir, this.config.teardown));
if (typeof this.config.teardown === 'string' && fileExists(fsPath.join(codecept_dir, this.config.teardown))) {
var teardown = require(fsPath.join(codecept_dir, this.config.teardown));
if (typeof teardown === 'function') {
teardown();
}
} else if (typeof this.config.teardown === 'function') {
this.config.teardown();
}
}

Expand Down