Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
feat(frameworks): add jasmine2 framework
Browse files Browse the repository at this point in the history
  • Loading branch information
hankduan committed Jan 5, 2015
1 parent 0a1f770 commit 1e60a95
Show file tree
Hide file tree
Showing 35 changed files with 186 additions and 14 deletions.
14 changes: 13 additions & 1 deletion docs/referenceConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ exports.config = {
// ----- The test framework --------------------------------------------------
// ---------------------------------------------------------------------------

// Test framework to use. This may be jasmine, cucumber, or mocha.
// Test framework to use. This may be jasmine, jasmine2, cucumber, or mocha.
//
// Jasmine is fully supported as a test and assertion framework.
// Mocha and Cucumber have limited beta support. You will need to include your
Expand All @@ -257,6 +257,18 @@ exports.config = {
defaultTimeoutInterval: 30000
},

// Options to be passed to jasmine2.
//
// See the full list at https://github.com/jasmine/jasmine-npm
jasmineNodeOpts: {
// If true, print colors to the terminal.
showColors: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 30000,
// Function called to print jasmine results
print: function() {},
},

// Options to be passed to Mocha.
//
// See the full list at http://visionmedia.github.io/mocha/
Expand Down
95 changes: 95 additions & 0 deletions lib/frameworks/jasmine2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
var q = require('q');

var RunnerReporter = function(emitter) {
this.emitter = emitter;
this.testResult = [],
this.failedCount = 0;
};

RunnerReporter.prototype.jasmineStarted = function() {
// Need to initiate startTime here, in case reportSpecStarting is not
// called (e.g. when fit is used)
this.startTime = new Date();
};

RunnerReporter.prototype.specStarted = function() {
this.startTime = new Date();
};

RunnerReporter.prototype.specDone = function(result) {
if (result.status == 'passed') {
this.emitter.emit('testPass');
} else if (result.status == 'failed') {
this.emitter.emit('testFail');
this.failedCount++;
}

var entry = {
description: result.description,
assertions: [],
duration: new Date().getTime() - this.startTime.getTime()
};

result.failedExpectations.forEach(function(item) {
entry.assertions.push({
passed: item.passed,
errorMsg: item.passed ? undefined : item.message,
stackTrace: item.passed ? undefined : item.stack
});
});
this.testResult.push(entry);
};

/**
* Execute the Runner's test cases through Jasmine.
*
* @param {Runner} runner The current Protractor Runner.
* @param {Array} specs Array of Directory Path Strings.
* @return {q.Promise} Promise resolved with the test results
*/
exports.run = function(runner, specs) {
var JasmineRunner = require('jasmine');
var jrunner = new JasmineRunner();
/* global jasmine */

require('jasminewd2');

// On timeout, the flow should be reset. This will prevent webdriver tasks
// from overflowing into the next test and causing it to fail or timeout
// as well. This is done in the reporter instead of an afterEach block
// to ensure that it runs after any afterEach() blocks with webdriver tasks
// get to complete first.
var reporter = new RunnerReporter(runner);
jasmine.getEnv().addReporter(reporter);

return runner.runTestPreparer().then(function() {
return q.promise(function (resolve, reject) {
var jasmineNodeOpts = runner.getConfig().jasmineNodeOpts;

if (jasmineNodeOpts && jasmineNodeOpts.defaultTimeoutInterval) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = jasmineNodeOpts.defaultTimeoutInterval;
}

var originalOnComplete = runner.getConfig().onComplete;
jasmineNodeOpts.onComplete = function(passed) {
try {
if (originalOnComplete) {
originalOnComplete(passed);
}
resolve({
failedCount: reporter.failedCount,
specResults: reporter.testResult
});
} catch(err) {
reject(err);
}
};

jrunner.configureDefaultReporter(jasmineNodeOpts);
jrunner.projectBaseDir = '';
jrunner.specDir = '';
jrunner.addSpecFiles(specs);
jrunner.execute();
});
});
};
2 changes: 2 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ Runner.prototype.run = function() {
var frameworkPath = '';
if (self.config_.framework === 'jasmine') {
frameworkPath = './frameworks/jasmine.js';
} else if (self.config_.framework === 'jasmine2') {
frameworkPath = './frameworks/jasmine2.js';
} else if (self.config_.framework === 'mocha') {
frameworkPath = './frameworks/mocha.js';
} else if (self.config_.framework === 'cucumber') {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"selenium-webdriver": "2.44.0",
"minijasminenode": "1.1.1",
"jasminewd": "1.1.0",
"jasminewd2": "0.0.2",
"jasmine": "2.1.1",
"saucelabs": "~0.1.0",
"glob": "~3.2",
"adm-zip": "0.4.4",
Expand Down
12 changes: 4 additions & 8 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node

var Executor = require('./test/test_util').Executor;
var glob = require('glob').sync;

var passingTests = [
'node lib/cli.js spec/basicConf.js',
Expand All @@ -26,14 +25,10 @@ var passingTests = [
'node lib/cli.js spec/interactionConf.js',
'node lib/cli.js spec/directConnectConf.js',
'node lib/cli.js spec/restartBrowserBetweenTestsConf.js',
'node lib/cli.js spec/getCapabilitiesConf.js'
'node lib/cli.js spec/getCapabilitiesConf.js',
'node node_modules/.bin/jasmine JASMINE_CONFIG_PATH=scripts/unit_test.json'
];

passingTests.push(
'node node_modules/minijasminenode/bin/minijn ' +
glob('spec/unit/*.js').join(' ') + ' ' +
glob('website/docgen/spec/*.js').join(' '));

var executor = new Executor();

passingTests.forEach(function(passing_test) {
Expand All @@ -56,7 +51,8 @@ executor.addCommandlineTest('node lib/cli.js spec/errorTest/singleFailureConf.js
executor.addCommandlineTest('node lib/cli.js spec/errorTest/timeoutConf.js')
.expectExitCode(1)
.expectErrors({
message: 'timeout: timed out after 1 msec waiting for spec to complete'
message: 'Timeout - Async callback was not invoked within timeout ' +
'specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'
})
.expectTestDuration(0, 100);

Expand Down
7 changes: 7 additions & 0 deletions scripts/unit_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"spec_dir": "",
"spec_files": [
"spec/unit/*.js",
"website/docgen/spec/*.js"
]
}
2 changes: 2 additions & 0 deletions spec/altRootConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var env = require('./environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

// Spec patterns are relative to this config.
specs: [
'altRoot/*_spec.js',
Expand Down
14 changes: 10 additions & 4 deletions spec/basic/locators_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ describe('locators', function() {

it('should allow custom expectations to expect an element', function() {
this.addMatchers({
toHaveText: function(actualText) {
return this.actual.getText().then(function(expectedText) {
return expectedText === actualText;
});
toHaveText: function() {
return {
compare: function(actual, expected) {
return {
pass: actual.getText().then(function(actual) {
return actual === expected;
})
};
}
};
}
});

Expand Down
2 changes: 2 additions & 0 deletions spec/basicConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var env = require('./environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

// Spec patterns are relative to this directory.
specs: [
'basic/*_spec.js'
Expand Down
2 changes: 2 additions & 0 deletions spec/ciConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ exports.config = {
sauceUser: process.env.SAUCE_USERNAME,
sauceKey: process.env.SAUCE_ACCESS_KEY,

framework: 'jasmine2',

// Spec patterns are relative to this directory.
specs: [
'basic/*_spec.js'
Expand Down
2 changes: 2 additions & 0 deletions spec/directConnectConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var env = require('./environment.js');
exports.config = {
directConnect: true,

framework: 'jasmine2',

capabilities: {
'browserName': 'chrome'
},
Expand Down
2 changes: 2 additions & 0 deletions spec/errorTest/afterLaunchChangesExitCodeConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var env = require('../environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

specs: [
'baseCase/single_failure_spec1.js'
],
Expand Down
2 changes: 2 additions & 0 deletions spec/errorTest/multiFailureConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var env = require('../environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

specs: [
'baseCase/single_failure_spec1.js',
'baseCase/single_failure_spec2.js'
Expand Down
2 changes: 2 additions & 0 deletions spec/errorTest/shardedFailureConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var env = require('../environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

specs: [
'baseCase/single_failure_spec1.js',
'baseCase/single_failure_spec2.js'
Expand Down
2 changes: 2 additions & 0 deletions spec/errorTest/singleFailureConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var env = require('../environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

specs: [
'baseCase/single_failure_spec1.js'
],
Expand Down
2 changes: 2 additions & 0 deletions spec/errorTest/timeoutConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var env = require('../environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

specs: [
'baseCase/timeout_spec.js'
],
Expand Down
2 changes: 2 additions & 0 deletions spec/interactionConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var env = require('./environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

// Spec patterns are relative to this directory.
specs: [
'interaction/*_spec.js'
Expand Down
2 changes: 2 additions & 0 deletions spec/junitOutputConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var env = require('./environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

specs: [
'basic/*_spec.js'
],
Expand Down
2 changes: 2 additions & 0 deletions spec/multiConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var env = require('./environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

// Spec patterns are relative to this directory.
specs: [
'basic/lib_spec.js'
Expand Down
1 change: 1 addition & 0 deletions spec/ngHintFailConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var env = require('./environment.js');

exports.config = {
seleniumAddress: env.seleniumAddress,
framework: 'jasmine2',
specs: ['ngHint/fail_spec.js'],
baseUrl: env.baseUrl,
plugins: [{
Expand Down
1 change: 1 addition & 0 deletions spec/ngHintSuccessConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var env = require('./environment.js');

exports.config = {
seleniumAddress: env.seleniumAddress,
framework: 'jasmine2',
specs: ['ngHint/success_spec.js'],
baseUrl: env.baseUrl,
plugins: [{
Expand Down
2 changes: 2 additions & 0 deletions spec/onCleanUpAsyncReturnValueConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var q = require('q');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

specs: [
'onCleanUp/*_spec.js'
],
Expand Down
2 changes: 2 additions & 0 deletions spec/onCleanUpNoReturnValueConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var env = require('./environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

specs: [
'onCleanUp/*_spec.js'
],
Expand Down
2 changes: 2 additions & 0 deletions spec/onCleanUpSyncReturnValueConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var env = require('./environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

specs: [
'onCleanUp/*_spec.js'
],
Expand Down
2 changes: 2 additions & 0 deletions spec/onPrepareConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var env = require('./environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

specs: [
'onPrepare/*_spec.js'
],
Expand Down
2 changes: 2 additions & 0 deletions spec/onPrepareFileConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var env = require('./environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

// Spec patterns are relative to this directory.
specs: [
'onPrepare/*_spec.js'
Expand Down
2 changes: 2 additions & 0 deletions spec/onPreparePromiseConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var q = require('q');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

specs: [
'onPrepare/*_spec.js'
],
Expand Down
2 changes: 2 additions & 0 deletions spec/onPreparePromiseFileConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var env = require('./environment.js');
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine2',

// Spec patterns are relative to this directory.
specs: [
'onPrepare/*_spec.js'
Expand Down
Loading

0 comments on commit 1e60a95

Please sign in to comment.