intern-yadda-loader
Yadda loader for Intern
Yadda is a plain-language BDD system for Javascript. Intern is a flexible Javascript test runner. This package loads Yadda features/scenarios/steps as Intern suites/tests.
Features
- Context tracking across scenario steps (unique per-scenario) using
this.ctx
. - Single, global step library similar to Cucumber and moonraker.
- Promise-based step definitions (or use the Intern
this.async()
api). - AMD syntax for better Intern integration.
Installation
See the Intern User Guide for information on setting up an intern project. Then install yadda
and intern-yadda-loader
:
$ npm install yadda intern-yadda-loader --save-dev
NOTE: Yadda is a peer dependency of intern-yadda-loader
.
Configuration
define({
environments: [{browserName: 'phantomjs'}],
loaderOptions: {
packages: [
{ name: 'yadda', location: './node_modules/intern-yadda-loader' },
{ name: 'steps', location: './test/steps' }
]
},
functionalSuites: [
'yadda!test/features/bottles.feature',
'yadda!test/features/google.feature'
],
yadda: {
steps: [
'steps/bottles-library',
'steps/google-library'
],
lang: 'English'
}
});
Examples
# `test/features/bottles.feature`
Feature: 100 Green Bottles
Scenario: Should fall from the wall
Given 100 green bottles are standing on the wall
When 1 green bottle accidentally falls
And another falls
Then there are 98 green bottles standing on the wall
define(function (require) {
var expect = require('intern/chai!expect');
return function (library) {
library
.given("$NUM green bottles are standing on the wall", function (number) {
expect(this.ctx.bottles).to.be.undefined;
this.ctx.bottles = parseInt(number);
})
.when("$NUM green bottle accidentally falls", function (number, next) {
var ctx = this.ctx;
setTimeout(function () {
ctx.bottles--;
next();
}, 200);
})
.define("And another falls", function () {
var ctx = this.ctx;
var deferred = this.async();
setTimeout(function () {
ctx.bottles--;
deferred.resolve();
}, 200);
})
.then("there are $NUM green bottles standing on the wall", function (number) {
expect(this.ctx.bottles).to.equal(parseInt(number));
});
};
});
# `test/features/google.feature`
Feature: Multilingual Google Search
Scenario: Searching Google For The First Time
When I open Google's fr search page
then the title is Google
and the search form exists
When I search for foo
then the title is foo - Recherche Google
and the search for foo was made
and 10 or more results were returned
Scenario: Searching Google Again
When I open Google's ie search page
then the title is Google
and the search form exists
When I search for bar
then the title is bar - Google Search
and the search for bar was made
and 10 or more results were returned
define(function (require) {
var expect = require('intern/chai!expect');
return function (library, dictionary) {
dictionary
.define('LOCALE', /(fr|es|ie)/)
.define('NUM', /(\d+)/);
library
.when("I open Google's $LOCALE search page", function(locale) {
return this.remote.get("http://www.google." + locale + "/");
})
.then("the title is $TITLE", function(title) {
return this.remote
.sleep(500)
.getPageTitle()
.then(function (pageTitle) {
expect(pageTitle).to.equal(title);
});
})
.then("the $ACTION form exists", function(action) {
return this.remote
.findByCssSelector('form[action="/' + action + '"]');
})
.when("I search for $TERM", function(term) {
return this.remote
.findByName('q')
.click()
.type(term + '\n');
})
.then("the search for $TERM was made", function(term) {
var regex = new RegExp('q=' + term);
return this.remote
.sleep(500)
.getCurrentUrl()
.then(function (url) {
expect(url).to.match(new RegExp('q=' + term));
});
})
.then("$NUM or more results were returned", function(number) {
return this.remote
.findAllByCssSelector('h3.r')
.then(function (elements) {
expect(elements).to.have.length.of.at.least(parseInt(number));
});
});
};
});
TODO