Skip to content

Commit

Permalink
First CasperJS test -- woohoo
Browse files Browse the repository at this point in the history
  • Loading branch information
pcottle committed Mar 23, 2015
1 parent 6ac9ed2 commit 65480b4
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 10 deletions.
6 changes: 4 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,17 @@ module.exports = function(grunt) {
browserify: {
options: {
ignore: [
'src/js/__tests__/create.js'
'src/__tests__/casperjs/*.js',
'src/js/__tests__/create.js',
'src/js/__tests__/*.js'
],
},
dist: {
files: {
'build/bundle.js': ['src/**/*.js', 'src/js/**/*.js'],
},
}
}
},
});

// all my npm helpers
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
"name": "LearnGitBranching",
"version": "0.8.0",
"devDependencies": {
"browserify": "~3.14.1",
"grunt": "~0.4.2",
"jasmine-node": "~1.12.0",
"grunt-browserify": "~1.3.0",
"grunt-jasmine-node": "~0.1.0",
"grunt-hash": "~0.5.0",
"prompt": "0.2.9",
"browserify": "~3.14.1",
"grunt-casperjs": "^2.1.0",
"grunt-cli": "~0.1.11",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-uglify": "~0.2.7",
"grunt-hash": "~0.5.0",
"grunt-jasmine-node": "~0.1.0",
"grunt-lib-phantomjs": "~0.4.0",
"grunt-shell-spawn": "~0.3.0"
"grunt-shell-spawn": "~0.3.0",
"jasmine-node": "~1.12.0",
"prompt": "0.2.9"
},
"dependencies": {
"backbone": "~0.9.9",
Expand Down
34 changes: 34 additions & 0 deletions src/__tests__/casperjs/casperHelp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var CasperHelp = {

getRoot: function() {
// Unfortunately this is hardcoded for now :*( cant get the path
// variable while in a casper context
return '/Users/pcottle/Dropbox/wip/learnGitBranching/';
},

getUrl: function () {
return 'file://localhost/' + this.getRoot() + '/index.html?NODEMO';
},

getUrlForCommands: function(commands) {
return this.getUrl() + '&command=' + commands.join(';');
},

waits: {
jsMount: function() {
return this.evaluate(function() {
return document.querySelectorAll('div.BaseHelperBar').length > 0;
});
},

allCommandsFinished: function () {
return this.evaluate(function() {
return document.querySelectorAll('p.commandLine').length ===
document.querySelectorAll('p.finished').length;
});
},
},

};

exports.CasperHelp = CasperHelp;
46 changes: 46 additions & 0 deletions src/__tests__/casperjs/sanity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var CasperHelp = require('./casperHelp').CasperHelp;

var visibleIDs = [
'commandLineHistory',
'terminal',
'interfaceWrapper',
'mainVisSpace',
'commandLineBar'
];

var selectors = [
'div.visBackgroundColor',
'p.commandLine'
];

var doneSelectors = [
'p.finished'
];

casper.start(
CasperHelp.getUrlForCommands([
'git commit',
]),
function() {
this.test.assertTitle('Learn Git Branching');

casper.waitFor(CasperHelp.waits.jsMount, function then() {
visibleIDs.forEach(function(id) {
this.test.assertVisible('#' + id);
}.bind(this));

selectors.forEach(function(selector) {
this.test.assertExists(selector);
}.bind(this));

this.test.done();
})
.waitFor(CasperHelp.waits.allCommandsFinished, function then() {
doneSelectors.forEach(function(selector) {
this.test.assertExists(selector);
}.bind(this));
});

});

casper.run();

0 comments on commit 65480b4

Please sign in to comment.