Skip to content

Commit

Permalink
Implement test, Change TAP specification
Browse files Browse the repository at this point in the history
  • Loading branch information
sideroad committed Apr 5, 2013
1 parent e070085 commit 6e5719e
Show file tree
Hide file tree
Showing 21 changed files with 2,546 additions and 117 deletions.
36 changes: 29 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,42 @@ module.exports = function(grunt) {
launch_in_ci : [
'firefox',
'safari'
],
tap : "tests.tap"
]
},
main : {
success : {
files : {
examples: [
'examples/1.html',
'examples/2.html'
'test/actual/success.tap': [
'test/source/success-*.html'
]
}
},
failed: {
files : {
'test/actual/failed.tap': [
'test/source/failed-*.html'
]
},
options: {
force: true
}
}
},

clean: {
tests: ['test/actual/*']
},

// Unit tests.
nodeunit: {
tests: ['test/*_test.js']
}
});

grunt.loadTasks('tasks');
grunt.registerTask('default', 'testem');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-nodeunit');

grunt.registerTask('test', ['clean', 'testem', 'nodeunit']);
grunt.registerTask('default', ['testem']);

};
20 changes: 4 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ This plugin requires Grunt `~0.4.0`
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

```shell
npm install -g testem
npm install -g grunt
npm install -g testem grunt
npm install grunt-testem
```

Expand All @@ -31,14 +30,12 @@ grunt.initConfig({
launch_in_ci : [
'firefox',
'safari'
],
tap : "tests.tap"
]
},
main : {
files : {
examples: [
'examples/1.html',
'examples/2.html'
'tests.tap': [
'examples/*.html'
]
}
}
Expand All @@ -47,15 +44,6 @@ grunt.initConfig({
```

### Options

#### options.tap
Type: `String`
Default value: `undefined`

TAP file path, if you want to output test result which file formatted TAP.

#### other options
You cant specified options, if you want to other options of testem
see also [testem](https://github.com/airportyh/testem)


Expand Down
8 changes: 0 additions & 8 deletions examples/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ test( "hello test", function() {
ok( 1 == "1", "Passed!" );
});

test("fail test", function(){
ok( false, "Will failed!" );
});

module("test module2");
test( "hello test", function() {
ok( 1 == "1", "Passed!" );
});

test("fail test", function(){
ok( false, "Will failed!" );
});
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-testem",
"description": "A grunt plugin for testem.",
"version": "0.3.2",
"version": "0.3.3",
"homepage": "https://github.com/sideroad/grunt-testem",
"author": "sideroad <sideroad.jp@gmail.com> (http://sideroad.secret.jp/)",
"repository": {
Expand Down Expand Up @@ -29,17 +29,20 @@
"node": "*"
},
"scripts": {
"test": "grunt testem"
"test": "grunt test --verbose --force"
},
"dependencies": {
"async" : "~0.1.22",
"underscore" : "~1.4.2",
"testem-multi" : "~0.1.1"
"testem-multi" : "~0.1.2"
},
"devDependencies": {
"async" : "~0.1.22",
"underscore" : "~1.4.2",
"testem-multi" : "~0.1.1"
"testem-multi" : "~0.1.2",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-nodeunit": "~0.1.2",
"grunt": "0.4.0"
},
"keywords": [
"gruntplugin","grunt","grunt","testem"
Expand Down
38 changes: 38 additions & 0 deletions src
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
TAP version 13
not ok 1 - test/source/failed-1.html - Firefox test module: fail test
---
message: "Will failed!"
...
not ok 2 - test/source/failed-1.html - Firefox test module2: fail test
---
message: "Will failed!"
...
not ok 3 - test/source/failed-1.html - Safari test module: fail test
---
message: "Will failed!"
...
not ok 4 - test/source/failed-1.html - Safari test module2: fail test
---
message: "Will failed!"
...
not ok 5 - test/source/failed-2.html - Firefox test module: fail test
---
message: "Will failed!"
...
not ok 6 - test/source/failed-2.html - Firefox test module2: fail test
---
message: "Will failed!"
...
not ok 7 - test/source/failed-2.html - Safari test module: fail test
---
message: "Will failed!"
...
not ok 8 - test/source/failed-2.html - Safari test module2: fail test
---
message: "Will failed!"
...

1..8
# tests 8
# pass 0
# fail 8
68 changes: 33 additions & 35 deletions tasks/testem.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,55 @@ module.exports = function(grunt) {

var async = require('async'),
_ = require('underscore'),
testemMulti = require('testem-multi'),
fs = require('fs');

grunt.registerMultiTask( 'testem', 'Execute testem.', function() {
var done = this.async(),
that = this,
options = this.options(),
tap,
files = [];

if(options.json){
options = _.extend({}, JSON.parse( fs.readFileSync(options.json, 'utf-8').replace(/\n/,'')), options);
}
tap = options.tap;
grunt.log.writeln('Now testing...');

this.files.forEach(function(f) {
files = files.concat( f.src.filter(function(filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}));
});
var tap = f.dest,
files = f.src.filter(function(filepath) {
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}),
testemMulti = require('testem-multi');

options.files = files;
testemMulti.exec(options);
testemMulti.on('data', function( data ){
grunt.verbose.write(''+data);
});
testemMulti.on('exit', function( results, memo ){
var tests = memo.tests,
pass = memo.pass,
not = memo.not,
fail = memo.fail;
options.files = files;
testemMulti.exec(options);
testemMulti.on('data', function( data ){
grunt.verbose.write(''+data);
});
testemMulti.on('exit', function( results, memo ){
var tests = memo.tests,
pass = memo.pass,
not = memo.not,
fail = memo.fail;

if(tap){
fs.writeFileSync(tap, results, 'utf-8');
}
if( tests != pass ||
fail ) {
grunt.log.error(not.join('\n'));
grunt.log.error(''+fail+'/'+tests+' assertions failed');
done(false);
} else {
grunt.log.ok(''+tests+' assertions passed');
done(true);
}
if(tap){
fs.writeFileSync(tap, results, 'utf-8');
}
if( tests != pass ||
fail ) {
grunt.log.error(not.join('\n'));
grunt.log.error(''+fail+'/'+tests+' assertions failed');
done(options.force || false);
} else {
grunt.log.ok(''+tests+' assertions passed');
done(true);
}
});
});
});

Expand Down
38 changes: 38 additions & 0 deletions test/actual/failed.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
TAP version 13
not ok 1 - test/source/failed-1.html - Firefox test module: fail test
---
message: "Will failed!"
...
not ok 2 - test/source/failed-1.html - Firefox test module2: fail test
---
message: "Will failed!"
...
not ok 3 - test/source/failed-1.html - Safari test module: fail test
---
message: "Will failed!"
...
not ok 4 - test/source/failed-1.html - Safari test module2: fail test
---
message: "Will failed!"
...
not ok 5 - test/source/failed-2.html - Firefox test module: fail test
---
message: "Will failed!"
...
not ok 6 - test/source/failed-2.html - Firefox test module2: fail test
---
message: "Will failed!"
...
not ok 7 - test/source/failed-2.html - Safari test module: fail test
---
message: "Will failed!"
...
not ok 8 - test/source/failed-2.html - Safari test module2: fail test
---
message: "Will failed!"
...

1..8
# tests 8
# pass 0
# fail 8
14 changes: 14 additions & 0 deletions test/actual/success.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
TAP version 13
ok 1 - test/source/success-1.html - Firefox test module: hello test
ok 2 - test/source/success-1.html - Firefox test module2: hello test
ok 3 - test/source/success-1.html - Safari test module: hello test
ok 4 - test/source/success-1.html - Safari test module2: hello test
ok 5 - test/source/success-2.html - Firefox test module: hello test
ok 6 - test/source/success-2.html - Firefox test module2: hello test
ok 7 - test/source/success-2.html - Safari test module: hello test
ok 8 - test/source/success-2.html - Safari test module2: hello test

1..8
# tests 8
# pass 8
# fail 0
38 changes: 38 additions & 0 deletions test/expected/failed.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
TAP version 13
not ok 1 - test/source/failed-1.html - Firefox test module: fail test
---
message: "Will failed!"
...
not ok 2 - test/source/failed-1.html - Firefox test module2: fail test
---
message: "Will failed!"
...
not ok 3 - test/source/failed-1.html - Safari test module: fail test
---
message: "Will failed!"
...
not ok 4 - test/source/failed-1.html - Safari test module2: fail test
---
message: "Will failed!"
...
not ok 5 - test/source/failed-2.html - Firefox test module: fail test
---
message: "Will failed!"
...
not ok 6 - test/source/failed-2.html - Firefox test module2: fail test
---
message: "Will failed!"
...
not ok 7 - test/source/failed-2.html - Safari test module: fail test
---
message: "Will failed!"
...
not ok 8 - test/source/failed-2.html - Safari test module2: fail test
---
message: "Will failed!"
...

1..8
# tests 8
# pass 0
# fail 8
14 changes: 14 additions & 0 deletions test/expected/success.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
TAP version 13
ok 1 - test/source/success-1.html - Firefox test module: hello test
ok 2 - test/source/success-1.html - Firefox test module2: hello test
ok 3 - test/source/success-1.html - Safari test module: hello test
ok 4 - test/source/success-1.html - Safari test module2: hello test
ok 5 - test/source/success-2.html - Firefox test module: hello test
ok 6 - test/source/success-2.html - Firefox test module2: hello test
ok 7 - test/source/success-2.html - Safari test module: hello test
ok 8 - test/source/success-2.html - Safari test module2: hello test

1..8
# tests 8
# pass 8
# fail 0
Loading

0 comments on commit 6e5719e

Please sign in to comment.