forked from codeceptjs/CodeceptJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var Suite = require('mocha/lib/suite'); | ||
var Test = require('mocha/lib/test'); | ||
var event = require('../event'); | ||
var scenario = require('../scenario'); | ||
|
||
/** | ||
* Codecept-style interface: | ||
* | ||
* Feature('login') | ||
* Scenario('login as regular user', (I) { | ||
* I.fillField(); | ||
* I.click() | ||
* I.see('Hello, '+data.login); | ||
* }); | ||
* | ||
* @param {Suite} suite Root suite. | ||
*/ | ||
module.exports = function(suite) { | ||
var suites = [suite]; | ||
|
||
suite.on('pre-require', function(context, file, mocha) { | ||
var common = require('mocha/lib/interfaces/common')(suites, context); | ||
|
||
common.before('codeceptjs event', function() { | ||
event.dispatcher.emit(event.suite.before); | ||
}); | ||
|
||
common.after('codeceptjs event', function() { | ||
event.dispatcher.emit(event.suite.after); | ||
}); | ||
|
||
// create dispatcher | ||
|
||
context.BeforeAll = common.before; | ||
context.AfterAll = common.after; | ||
|
||
context.run = mocha.options.delay && common.runWithSuite(suite); | ||
/** | ||
* Describe a "suite" with the given `title` | ||
* and callback `fn` containing nested suites | ||
* and/or tests. | ||
*/ | ||
|
||
context.Feature = function(title) { | ||
var suite = Suite.create(suites[0], title); | ||
suite.file = file; | ||
suite.beforeEach('codeceptjs.before', scenario.setup); | ||
suite.afterEach('finialize codeceptjs', scenario.teardown); | ||
suites.unshift(suite); | ||
return suite; | ||
}; | ||
|
||
context.Background = context.Before = function(fn) { | ||
suites[0].beforeEach('Before', scenario.injected(fn)); | ||
} | ||
|
||
context.After = function(fn) { | ||
suites[0].afterEach('After', scenario.injected(fn)); | ||
} | ||
|
||
/** | ||
* Describe a specification or test-case | ||
* with the given `title` and callback `fn` | ||
* acting as a thunk. | ||
*/ | ||
|
||
context.Scenario = function(title, fn) { | ||
var suite = suites[0]; | ||
if (suite.pending) { | ||
fn = null; | ||
} | ||
suite.timeout(0); | ||
var test = new Test(title, fn); | ||
test.file = file; | ||
test.async = true; | ||
test.timeout(0); | ||
suite.addTest(scenario.test(test)); | ||
return test; | ||
}; | ||
|
||
/** | ||
* Exclusive test-case. | ||
*/ | ||
context.Scenario.only = function(title, fn) { | ||
var test = context.it(title, fn); | ||
var reString = '^' + escapeRe(test.fullTitle()) + '$'; | ||
mocha.grep(new RegExp(reString)); | ||
return test; | ||
}; | ||
|
||
/** | ||
* Pending test case. | ||
*/ | ||
context.xScenario = context.Scenario.skip = function(title) { | ||
context.Scenario(title); | ||
}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters