Skip to content

Commit

Permalink
Merge pull request #780 from janhancic/develop-port-br-test-to-commonjs
Browse files Browse the repository at this point in the history
Port the "test" lib to CommonJS style
  • Loading branch information
Andy Berry committed Jul 1, 2014
2 parents 3f63e5b + 30a4291 commit eea8f7b
Show file tree
Hide file tree
Showing 75 changed files with 1,678 additions and 1,551 deletions.
Original file line number Diff line number Diff line change
@@ -1,63 +1,65 @@
'use strict';

var br = require('br/Core');
var Errors = require('br/Errors');
var Fixture = require('br/test/Fixture');

/**
* @name br.test.AlertFixture
* @class
* The <code>AlertFixture</code> allows for testing of browser alerts.
* @interface
*/
br.test.AlertFixture = function()
{

function AlertFixture() {
};
br.inherit(AlertFixture, Fixture);

br.Core.inherit(br.test.AlertFixture, br.test.Fixture);

br.test.AlertFixture.prototype.setUp = function()
{
AlertFixture.prototype.setUp = function() {
this.m_pAlertStack = [];
this.m_fOriginalWindowAlertFunction = window.alert;

var oThis = this;
window.alert = function(sAlert)
{
oThis.m_pAlertStack.push(sAlert);

var self = this;
window.alert = function(alertMessage) {
self.m_pAlertStack.push(alertMessage);
};
};

br.test.AlertFixture.prototype.tearDown = function()
{
AlertFixture.prototype.tearDown = function() {
window.alert = this.m_fOriginalWindowAlertFunction;
assertTrue("there were alerts triggered that were not expected in the test", this.m_pAlertStack.length === 0);
assertTrue('there were alerts triggered that were not expected in the test', this.m_pAlertStack.length === 0);
};

br.test.AlertFixture.prototype.doGiven = function(sPropertyName, vValue)
{
throw new br.Errors.CustomError(br.Errors.INVALID_TEST, "given is not supported by AlertFixture");
AlertFixture.prototype.doGiven = function(propertyNameName, value) {
throw new Errors.InvalidTestError('given is not supported by AlertFixture');
};

br.test.AlertFixture.prototype.doWhen = function(sPropertyName, vValue)
{
throw new br.Errors.CustomError(br.Errors.INVALID_TEST, "when is not supported by AlertFixture");
AlertFixture.prototype.doWhen = function(propertyNameName, value) {
throw new Errors.InvalidTestError('when is not supported by AlertFixture');
};

br.test.AlertFixture.prototype.doThen = function(sPropertyName, vValue)
{
AlertFixture.prototype.doThen = function(propertyNameName, value) {
if (this.m_pAlertStack.length < 1) {
fail("no alerts were triggered");
fail('no alerts were triggered');
}
assertEquals("expected alert message '" + vValue + "', but was '" + this.m_pAlertStack[0] + "'", vValue, this.m_pAlertStack[0]);

assertEquals(
"expected alert message '" + value + "', but was '" + this.m_pAlertStack[0] + "'",
value,
this.m_pAlertStack[0]
);

this.m_pAlertStack.shift();
};

br.test.AlertFixture.prototype.addSubFixtures = function(oFixtureRegistry)
{
AlertFixture.prototype.addSubFixtures = function(fixtureRegistry) {
};


br.test.AlertFixture.prototype.canHandleExactMatch = function()
{
AlertFixture.prototype.canHandleExactMatch = function() {
return true;
};

br.test.AlertFixture.prototype.canHandleProperty = function(sProperty)
{
AlertFixture.prototype.canHandleProperty = function(propertyName) {
return false;
};

module.exports = AlertFixture;
Original file line number Diff line number Diff line change
@@ -1,91 +1,89 @@
'use strict';

var Errors = require('br/Errors');

/**
* @name br.test.Fixture
* @interface
* @class
* <code>Fixture</code> is the interface for individual fixtures added to the GWTTestRunner. The purpose of
* a Fixture is to enable tests to manipulate and access a specific area of the system under tests using the
* GWT (given-when-then) BDD format.
* <code>Fixture</code> is the interface for individual fixtures added to the GWTTestRunner. The purpose of a Fixture
* is to enable tests to manipulate and access a specific area of the system under tests using the GWT
* (given-when-then) BDD format.
*/
br.test.Fixture = function()
{
};
function Fixture() {
}

/**
* This method is called just before a GWT test. This optional interface method can be implemented if the fixture
* is required to correctly set up the system-under-test before each test.
* This method is called just before a GWT test. This optional interface method can be implemented if the fixture is
* required to correctly set up the system-under-test before each test.
*/
br.test.Fixture.prototype.setUp = function()
{
Fixture.prototype.setUp = function() {
// optional interface method
};

/**
* This method is called just after a GWT test. This optional interface method can be implemented if the fixture
* is required to correctly tear down the system-under-test after each test or to reset any state held in the fixture's
* implementation.
* This method is called just after a GWT test. This optional interface method can be implemented if the fixture is
* required to correctly tear down the system-under-test after each test or to reset any state held in the fixture's
* implementation.
*/
br.test.Fixture.prototype.tearDown = function()
{
Fixture.prototype.tearDown = function() {
// optional interface method
};

/**
* This optional interface method can be implemented by a Fixture for a complex system which can be conceptually
* decomposed into separate sub-systems, enabling the fixture to delegate the handling of some fixture properties
* to the sub-fixtures. This method is called by the GWTTestRunner.
*
* @param {br.test.FixtureRegistry} oFixtureRegistry The registry to which the fixtures should be registered.
* decomposed into separate sub-systems, enabling the fixture to delegate the handling of some fixture properties to
* the sub-fixtures. This method is called by the GWTTestRunner.
*
* @param {br.test.FixtureRegistry} fixtureRegistry The registry to which the fixtures should be registered.
*/
br.test.Fixture.prototype.addSubFixtures = function(oFixtureRegistry)
{
Fixture.prototype.addSubFixtures = function(fixtureRegistry) {
// optional interface method
};

br.test.Fixture.prototype.canHandleExactMatch = function()
{
throw new br.Errors.CustomError(br.Errors.UNIMPLEMENTED_INTERFACE, "Fixture.canHandleExactMatch() has not been implemented.");
Fixture.prototype.canHandleExactMatch = function() {
throw new Errors.UnimplementedInterfaceError('Fixture.canHandleExactMatch() has not been implemented.');
};

/**
* This method is called by the GWTTestRunner to check whether a property used in a GWT test is supported by
* the fixture.
*
* @param {String} sProperty the property name to check.
* @returns {Boolean} true if the fixture handles the property; false otherwise
* This method is called by the GWTTestRunner to check whether a property used in a GWT test is supported by the
* fixture.
*
* @param {String} propertyName the property name to check.
* @returns {Boolean} true if the fixture handles the property; false otherwise.
*/
br.test.Fixture.prototype.canHandleProperty = function(sProperty)
{
throw new br.Errors.CustomError(br.Errors.UNIMPLEMENTED_INTERFACE, "Fixture.canHandleProperty() has not been implemented.");
Fixture.prototype.canHandleProperty = function(propertyName) {
throw new Errors.UnimplementedInterfaceError('Fixture.canHandleProperty() has not been implemented.');
};

/**
* This method is called in order to manipulate a property on the system under test in a given clause.
*
* @param {String} sPropertyName The property to be changed.
* @param {String} vValue The new value of the property.
*
* @param {String} propertyName The property to be changed.
* @param {String} value The new value of the property.
*/
br.test.Fixture.prototype.doGiven = function(sPropertyName, vValue)
{
throw new br.Errors.CustomError(br.Errors.UNIMPLEMENTED_INTERFACE, "Fixture.doGiven() has not been implemented.");
Fixture.prototype.doGiven = function(propertyName, value) {
throw new Errors.UnimplementedInterfaceError('Fixture.doGiven() has not been implemented.');
};

/**
* This method is called in order to manipulate a property on the system under test in a when clause.
*
* @param {String} sPropertyName The property to be changed.
* @param {String} vValue The new value of the property.
*
* @param {String} propertyName The property to be changed.
* @param {String} value The new value of the property.
*/
br.test.Fixture.prototype.doWhen = function(sPropertyName, vValue)
{
throw new br.Errors.CustomError(br.Errors.UNIMPLEMENTED_INTERFACE, "Fixture.doWhen() has not been implemented.");
Fixture.prototype.doWhen = function(propertyName, value) {
throw new Errors.UnimplementedInterfaceError('Fixture.doWhen() has not been implemented.');
};

/**
* This method is called in order to assert a property's value on the system under test.
*
* @param {String} sPropertyName The property name to assert.
* @param {String} vValue The value to assert.
*
* @param {String} propertyName The property name to assert.
* @param {String} value The value to assert.
*/
br.test.Fixture.prototype.doThen = function(sPropertyName, vValue)
{
throw new br.Errors.CustomError(br.Errors.UNIMPLEMENTED_INTERFACE, "Fixture.doThen() has not been implemented.");
Fixture.prototype.doThen = function(propertyName, value) {
throw new Errors.UnimplementedInterfaceError('Fixture.doThen() has not been implemented.');
};

module.exports = Fixture;
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
'use strict';

var Errors = require('br/Errors');

/**
* Constructs a <code>FixtureFactory</code> .
* @name br.test.FixtureFactory
* Constructs a <code>FixtureFactory</code>.
* @constructor
* @interface
* @class
* An implementing FixtureFactory can have an optional <code>setUp</code> method which will be called
* before each test is executed and can be used to reset the state of a test and its stubs.
* An implementing FixtureFactory can have an optional <code>setUp</code> method which will be called before each test
* is executed and can be used to reset the state of a test and its stubs.
*/
br.test.FixtureFactory = function()
{
function FixtureFactory() {
};

/**
* This method is called once by the test-runner after the FixtureFactory is constructed. The implementation
* should add to the test runner all the fixtures that are needed by the tests.
*
* @param {br.test.FixtureRegistry} oFixtureRegistry The registry to which the fixtures should be registered.
* This method is called once by the test-runner after the FixtureFactory is constructed. The implementation should add
* to the test runner all the fixtures that are needed by the tests.
*
* @param {br.test.FixtureRegistry} fixtureRegistry The registry to which the fixtures should be registered.
*/
br.test.FixtureFactory.prototype.addFixtures = function(oFixtureRegistry)
{
throw new br.Errors.CustomError(br.Errors.UNIMPLEMENTED_INTERFACE, "FixtureFactory.addFixtures() has not been implemented.");
FixtureFactory.prototype.addFixtures = function(fixtureRegistry) {
throw new Errors.UnimplementedInterfaceError('FixtureFactory.addFixtures() has not been implemented.');
};

module.exports = FixtureFactory;
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
'use strict';

/**
* @name br.test.FixtureRegistry
* @class
* The <code>FixtureRegistry</code> allows for registration of fixtures for a
* specified scope.
* The <code>FixtureRegistry</code> allows for registration of fixtures for a specified scope.
* @interface
*/
br.test.FixtureRegistry = function()
{
function FixtureRegistry() {
};

/**
* Adds a fixture to the registry.
* Adds a fixture to the registry.
*
* @param {String} sScope The scope to which the fixture should be registered.
* @param {br.test.Fixture} oFixture The fixture to register.
* @param {String} scope The scope to which the fixture should be registered.
* @param {br.test.Fixture} fixture The fixture to register.
*/
br.test.FixtureRegistry.prototype.addFixture = function(sScope, oFixture)
{
FixtureRegistry.prototype.addFixture = function(scope, fixture) {
};

module.exports = FixtureRegistry;
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
/**
* @private
*/
br.test.GwtFailureMessage = function() {
_errorMsg = "";
_statck = "";
}
br.test.GwtFailureMessage.prototype.setMessage = function(sMsg) {
this._errorMsg = sMsg;
'use strict';

/** @private */
function GwtFailureMessage() {
this._errorMsg = '';
this._statck = '';
}
br.test.GwtFailureMessage.prototype.getMessage = function() {

GwtFailureMessage.prototype.setMessage = function(message) {
this._errorMsg = message;
};

GwtFailureMessage.prototype.getMessage = function() {
return this._errorMsg;
}
br.test.GwtFailureMessage.prototype.setStack = function(sStack) {
this._statck = sStack;
}
br.test.GwtFailureMessage.prototype.getStack = function() {
};

GwtFailureMessage.prototype.setStack = function(stack) {
this._statck = stack;
};

GwtFailureMessage.prototype.getStack = function() {
return this._statck;
}
};

module.exports = GwtFailureMessage;
Loading

0 comments on commit eea8f7b

Please sign in to comment.