Skip to content
This repository has been archived by the owner on Dec 15, 2019. It is now read-only.

Commit

Permalink
Gruntfile task with Hello World test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Droogans committed Nov 12, 2013
1 parent d6da34c commit a595c05
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
28 changes: 28 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,28 @@
'use strict';

function loadConfig(path) {
var glob = require('glob');
var object = {};
var key;

glob.sync('*', {cwd: path}).forEach(function(option) {
key = option.replace(/\.js$/,'');
object[key] = require(path + option);
});

return object;
}

module.exports = function(grunt) {
// load all grunt tasks
require('load-grunt-tasks')(grunt);
grunt.loadTasks('tasks');

var config = {
pkg: grunt.file.readJSON('package.json'),
env: process.env
};

grunt.util._.extend(config, loadConfig('./tasks/options/'));
grunt.initConfig(config);
};
11 changes: 11 additions & 0 deletions package.json
@@ -0,0 +1,11 @@
{
"devDependencies": {
"grunt": "~0.4.1",
"astrolabe": "~0.3.0-alpha",
"glob": "~3.2.7",
"lodash": "~2.3.0",
"load-grunt-tasks": "~0.2.0",
"protractor": "~0.12.1",
"grunt-shell": "~0.5.0"
}
}
22 changes: 22 additions & 0 deletions tasks/options/shell.js
@@ -0,0 +1,22 @@
var grunt = require('grunt');

module.exports = {
protractor: {
options: {
stdout: true
},
command: function (file) {
var localConfigFile = 'test/protractor.conf.local.js';
var defaultConfigFile = 'test/protractor.conf.js';
var configFile = grunt.file.isFile(localConfigFile) ? localConfigFile : defaultConfigFile;
var cmd = 'protractor ' + configFile;

if (file && grunt.file.isFile(file)) {
cmd += ' --specs ' + file;
}

console.log('Command: ' + cmd);
return cmd;
}
}
};
23 changes: 23 additions & 0 deletions tasks/test.js
@@ -0,0 +1,23 @@
module.exports = function (grunt) {
grunt.registerTask('test', 'Runs unit and midway tests - grunt unit:dev will run continously',
function(type, file) {
var protractorFile = file ? ':' + file : '';

// define types of tests to run
var types = {
'mid': 'shell:protractor' + protractorFile
};


// set default to run unit and func test a single time
var tasks = types.mid;

// check if param passed in (e.g. 'grunt test:unit')
if (typeof type === 'string') {
// overwrite default tasks with single task
tasks = types[type];
}

grunt.task.run(tasks);
});
};
5 changes: 5 additions & 0 deletions test/pages/Base.js
@@ -0,0 +1,5 @@
var Page = require('astrolabe').Page;

module.exports = Page.create({
url: { value: '/home' }
});
26 changes: 26 additions & 0 deletions test/protractor.conf.js
@@ -0,0 +1,26 @@
exports.config = {
// The address of a running selenium server. If this is specified,
// seleniumServerJar and seleniumPort will be ignored.
seleniumAddress: 'http://localhost:4444/wd/hub',

// A base URL for your application under test. Calls to protractor.get()
// with relative paths will be prepended with this.
baseUrl: 'http://beta.epikvote.com',

specs: [
'./stories/*.js'
],

// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'firefox'
},

// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
isVerbose: true,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 10000
}
};
11 changes: 11 additions & 0 deletions test/stories/frontPage.js
@@ -0,0 +1,11 @@
var basePage = require('../pages/Base');

describe('Main page', function() {

basePage.go();

it('should be at the correct URL', function() {
expect(basePage.currentUrl).toEqual(browser.baseUrl + basePage.url);
});

});

0 comments on commit a595c05

Please sign in to comment.