Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding initial tests
  • Loading branch information
davglass committed Apr 25, 2012
1 parent 8b3ab82 commit 0bc3a8c
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
6 changes: 6 additions & 0 deletions package.json
Expand Up @@ -11,5 +11,11 @@
"colors": "*",
"yuitest": "*"
},
"devDependencies": {
"yuitest": "*"
},
"scripts": {
"test": "./node_modules/.bin/yuitest ./tests/test.js"
},
"preferGlobal": "true"
}
Binary file added tests/.test.js.swp
Binary file not shown.
33 changes: 33 additions & 0 deletions tests/html/bad.html
@@ -0,0 +1,33 @@
<!doctype html>
<html>
<head>
<title>Test One</title>
</head>
<body>
<script src="http://davglass.homelinux.com/yui/yui3/build/yui/yui-min.js"></script>
<script>
YUI().use('test', function(Y) {
var suite = new Y.Test.Suite('Suite Bad');

for (var i = 1; i <= 5; i++) {
suite.add(new Y.Test.Case({
name: "Case #" + i,
'test: bogus test - ': function() {
Y.Assert.isTrue(true);
}
}));
}
for (i = 1; i <= 5; i++) {
suite.add(new Y.Test.Case({
name: "Case #" + i,
'test: bogus failed - ': function() {
Y.Assert.isTrue(false);
}
}));
}
Y.Test.Runner.add(suite);
Y.Test.Runner.run();
});
</script>
</body>
</html>
25 changes: 25 additions & 0 deletions tests/html/good.html
@@ -0,0 +1,25 @@
<!doctype html>
<html>
<head>
<title>Test One</title>
</head>
<body>
<script src="http://davglass.homelinux.com/yui/yui3/build/yui/yui-min.js"></script>
<script>
YUI().use('test', function(Y) {
var suite = new Y.Test.Suite('Suite #1');

for (var i = 1; i <= 50; i++) {
suite.add(new Y.Test.Case({
name: "Case #" + i,
'test: bogus test - ': function() {
Y.Assert.isTrue(true);
}
}));
}
Y.Test.Runner.add(suite);
Y.Test.Runner.run();
});
</script>
</body>
</html>
57 changes: 57 additions & 0 deletions tests/test.js
@@ -0,0 +1,57 @@
#!/usr/bin/env node

process.chdir(__dirname);

var YUITest = require('yuitest'),
path = require('path'),
exec = require('child_process').exec;

var Assert = YUITest.Assert;

var wrapper = path.join(__dirname, '../lib/wrapper.js');

var runTest = function(file, cb) {
var cmd = 'phantomjs ' + wrapper + ' ' + file;
exec(cmd, cb);
};

var suite = new YUITest.TestSuite('Grover');

suite.add(new YUITest.TestCase({
name: 'Good Results',
'Check Results': function() {
var test = this;

runTest('./html/good.html', function(err, stdout) {
test.resume(function() {
var json = JSON.parse(stdout);
Assert.areSame('Suite #1', json.name, 'Suite Name Incorrect');
Assert.areEqual(50, json.passed, 'A test failed');
Assert.areEqual(0, json.failed, 'A test failed');
});
});

this.wait();
}
}));

suite.add(new YUITest.TestCase({
name: 'Failed Results',
'Failed Tests': function() {
var test = this;

runTest('./html/bad.html', function(err, stdout) {
test.resume(function() {
var json = JSON.parse(stdout);
Assert.areSame('Suite Bad', json.name, 'Suite Name Incorrect');
Assert.areEqual(5, json.passed, 'A test failed');
Assert.areEqual(5, json.failed, 'A test failed');
});
});

this.wait();
}
}));


YUITest.TestRunner.add(suite);

0 comments on commit 0bc3a8c

Please sign in to comment.