Skip to content

Commit

Permalink
Revert "Revert "added tests to UI""
Browse files Browse the repository at this point in the history
This reverts commit 5a398e4.
  • Loading branch information
grant-g committed Feb 3, 2016
1 parent 5a398e4 commit cb0cd77
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 0 deletions.
87 changes: 87 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use strict';

var _ = require('lodash');

var desireds = require('./desireds');

var gruntConfig = {
env: {
// dynamically filled
},
simplemocha: {
sauce: {
options: {
timeout: 60000,
reporter: 'spec-xunit-file',
},
src: ['tests_actual/test-cases.js']
},
sauce_node: {
options: {
timeout: 60000,
reporter: 'spec-xunit-file',
},
src: ['test/test-cases.js']
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
gruntfile: {
src: 'Gruntfile.js'
},
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/*.js']
},
},
concurrent: {
'test-sauce': [], // dynamically filled
},
watch: {
gruntfile: {
files: '<%= jshint.gruntfile.src %>',
tasks: ['jshint:gruntfile']
},
test: {
files: '<%= jshint.test.src %>',
tasks: ['jshint:test']
},
},
};

_.forIn(desireds,function(desired, key) {
gruntConfig.env[key] = {
DESIRED: JSON.stringify(desired)
};
//gruntConfig.concurrent['test-sauce'].push('test:sauce:' + key);
});

//console.log(gruntConfig);

module.exports = function(grunt) {

// Project configuration.
grunt.initConfig(gruntConfig);

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');

// Default task.
grunt.registerTask('default', ['test:sauce:' + _(desireds).keys().first()]);
grunt.registerTask('test_real', ['env:chrome', 'simplemocha:sauce:' + _(desireds).keys().first()]);
grunt.registerTask('test_fake', ['env:chrome', 'simplemocha:sauce_node:' + _(desireds).keys().first()]);

// _.forIn(desireds,function(desired, key) {
// grunt.registerTask('test:sauce:' + key, ['env:' + key, 'simplemocha:sauce']);
// });

// grunt.registerTask('test', ['concurrent:test-sauce']);
};
7 changes: 7 additions & 0 deletions desireds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
chrome: {browserName: 'chrome'},
firefox: {browserName: 'firefox'},
explorer: {browserName: 'internet explorer'}
};
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "MicroUITests",
"version": "0.1.5",
"description": "tests",
"dependencies": {
"express": "~4.12.0",
"chai": "latest",
"chai-as-promised": "latest",
"colors": "latest",
"grunt": "~0.4.5",
"grunt-concurrent": "latest",
"grunt-contrib-jshint": "latest",
"grunt-contrib-watch": "latest",
"grunt-env": "latest",
"grunt-simple-mocha": "latest",
"lodash": "latest",
"mocha": "^2.3.3",
"spec-xunit-file": "0.0.1-3",
"wd": "latest"
},
"engines": {
"node": "0.10.38"
}
}
98 changes: 98 additions & 0 deletions test/test-cases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
var wd = require('wd');
require('colors');
var _ = require("lodash");
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
var url = "https://nodejs.org";//process.env.APP_URL;

chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;

// checking sauce credential
if(!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY){
console.warn(
'\nPlease configure your sauce credential:\n\n' +
'export SAUCE_USERNAME=<SAUCE_USERNAME>\n' +
'export SAUCE_ACCESS_KEY=<SAUCE_ACCESS_KEY>\n\n'
);
throw new Error("Missing sauce credentials");
}

// http configuration, not needed for simple runs
wd.configureHttp( {
timeout: 60000,
retryDelay: 15000,
retries: 5
});

var desired = JSON.parse(process.env.DESIRED || '{browserName: "chrome"}');
desired.name = 'MicroUI with ' + desired.browserName;
desired.tags = ['MicroUI'];

describe('MicroUI(' + desired.browserName + ')', function() {
var browser;
var allPassed = true;

before(function(done) {
var username = process.env.SAUCE_USERNAME;
var accessKey = process.env.SAUCE_ACCESS_KEY;
browser = wd.promiseChainRemote(process.env.HOST, process.env.PORT, username, accessKey);
if(process.env.VERBOSE){
// optional logging
browser.on('status', function(info) {
console.log(info.cyan);
});
browser.on('command', function(meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
}
browser
.init(desired)
.nodeify(done);
});

afterEach(function(done) {
allPassed = allPassed && (this.currentTest.state === 'passed');
done();
});

after(function(done) {
browser
.quit()
.sauceJobStatus(allPassed)
.nodeify(done);
});

it("Have correct title", function(done) {
browser
.get(url)
.title()
.should.become("Node.js")
.nodeify(done);
});

it("should get main page", function(done) {
browser
.get(url)
.title()
.should.become("Node.js")
.nodeify(done);
});

it("should display loading icon", function(done) {
browser
.get(url)
.title()
.should.become("Node.js")
.nodeify(done);
});

it("should display correct microservices", function(done) {
browser
.get(url)
.title()
.should.become("Node.js")
.nodeify(done);
});
});
98 changes: 98 additions & 0 deletions tests_actual/test-cases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
var wd = require('wd');
require('colors');
var _ = require("lodash");
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
var url = process.env.APP_URL;

chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;

// checking sauce credential
if(!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY){
console.warn(
'\nPlease configure your sauce credential:\n\n' +
'export SAUCE_USERNAME=<SAUCE_USERNAME>\n' +
'export SAUCE_ACCESS_KEY=<SAUCE_ACCESS_KEY>\n\n'
);
throw new Error("Missing sauce credentials");
}

// http configuration, not needed for simple runs
wd.configureHttp( {
timeout: 60000,
retryDelay: 15000,
retries: 5
});

var desired = JSON.parse(process.env.DESIRED || '{browserName: "chrome"}');
desired.name = 'MicroUI with ' + desired.browserName;
desired.tags = ['MicroUI'];

describe('MicroUI(' + desired.browserName + ')', function() {
var browser;
var allPassed = true;

before(function(done) {
var username = process.env.SAUCE_USERNAME;
var accessKey = process.env.SAUCE_ACCESS_KEY;
browser = wd.promiseChainRemote(process.env.HOST, process.env.PORT, username, accessKey);
if(process.env.VERBOSE){
// optional logging
browser.on('status', function(info) {
console.log(info.cyan);
});
browser.on('command', function(meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
}
browser
.init(desired)
.nodeify(done);
});

afterEach(function(done) {
allPassed = allPassed && (this.currentTest.state === 'passed');
done();
});

after(function(done) {
browser
.quit()
.sauceJobStatus(allPassed)
.nodeify(done);
});

it("Have correct title", function(done) {
browser
.get(url)
.title()
.should.become("Node.js")
.nodeify(done);
});

it("should get main page", function(done) {
browser
.get(url)
.title()
.should.become("Node.js")
.nodeify(done);
});

it("should display loading icon", function(done) {
browser
.get(url)
.title()
.should.become("Node.js")
.nodeify(done);
});

it("should display correct microservices", function(done) {
browser
.get(url)
.title()
.should.become("Node.js")
.nodeify(done);
});
});

0 comments on commit cb0cd77

Please sign in to comment.