Skip to content
This repository has been archived by the owner on Jan 10, 2020. It is now read-only.

Commit

Permalink
Fixes #15 - Normalizing test results for tap reporting (tests added)
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Jul 17, 2013
1 parent 66be217 commit f5b1f91
Show file tree
Hide file tree
Showing 21 changed files with 257 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ npm-debug.log
coverage
tests/out/*.info
tests/report/
tests/tap/output.tap
21 changes: 18 additions & 3 deletions lib/process.js
Expand Up @@ -14,23 +14,38 @@ module.exports = function(results, type) {
});
};

results.forEach(handle);

if (Array.isArray(results) && results.length === 1) {
handle(results[0]);
} else {
results.forEach(function(d, index) {
if (index === 0) {
handle(d);
} else {
var name = d.name;
data[name] = data[name] || {};
Object.keys(d).forEach(function(key) {
if (!data[name][key]) {
data[name][key] = d[key];
}
if (data[name][key] && (typeof data[name][key] === 'number')) {
data[name][key] += d[key];
}
});
}
});
}

//Fixes #9 - YUITest knows nothing about Istanbul data, so we need to remove it first
if (data.coverage && data.coverageType && data.coverageType === 'istanbul' && type !== 'JSON') {
delete data.coverage;
}

/*
I know this is bad, but YUITest.TestRunner doesn't allow
me to add results in a public way, so I have to "work around" it :)
*/
YUITest.TestRunner._lastResults = data;


str = YUITest.TestRunner.getResults(YUITest.TestFormat[type]);
if (type === 'JSON') {
str = JSON.stringify(JSON.parse(str), null, 4) + '\n';
Expand Down
40 changes: 40 additions & 0 deletions tests/9-yuitest.js
Expand Up @@ -4,6 +4,7 @@ var vows = require('vows'),
fs = require('fs'),
path = require('path'),
util = require('../lib/index'),
rimraf = require('rimraf'),
cover = require('../lib/coverage'),
exists = fs.existsSync || path.existsSync,
grover = require('../lib/grover'),
Expand All @@ -21,6 +22,7 @@ var vows = require('vows'),
options.push(i);
});
}

grover.process(options, function(err, json) {
cb(err, json[0]);
});
Expand Down Expand Up @@ -103,6 +105,44 @@ var tests = {
},
'and should have 0 failed tests': function(json) {
assert.equal(json.failed, 0);
},
'should execute multiple tests and report proper results': {
topic: function() {
var self = this,
tapFile = path.join(__dirname, './tap/output.tap'),
_exit = util.exit;
util.exit = function() {};
process.chdir(__dirname);

if (exists(tapFile)) {
rimraf.sync(tapFile);
}

runTest('tap/mymodule/tests/unit/index.html', [
'--tap',
'-o',
tapFile,
path.join(__dirname, './tap/myothermodule/tests/unit/index.html')
], function(err, json) {
util.exit = _exit;
var data = {
file: exists(tapFile),
str: fs.readFileSync(tapFile).toString()
};
self.callback(err, data);
});
},
'and write tap file': function(topic) {
assert.isTrue(topic.file);
},
'and tap file contains 6 tests': function(topic) {
var line = topic.str.split('\n')[0];
assert.equal(line, '1..6');
},
'and should have 11 lines': function(topic) {
var lines = topic.str.trim().split('\n').length;
assert.equal(lines, 11);
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/tap/mymodule/HISTORY.md
@@ -0,0 +1,2 @@
mymodule
========
2 changes: 2 additions & 0 deletions tests/tap/mymodule/README.md
@@ -0,0 +1,2 @@
mymodule
========
10 changes: 10 additions & 0 deletions tests/tap/mymodule/build.json
@@ -0,0 +1,10 @@
{
"name": "mymodule",
"builds": {
"mymodule": {
"jsfiles": [
"js/mymodule.js"
]
}
}
}
11 changes: 11 additions & 0 deletions tests/tap/mymodule/docs/component.json
@@ -0,0 +1,11 @@
{
"name" : "mymodule",
"displayName": "Gallery: mymodule",
"description": "*Summary Goes Here*",
"author" : [ "" ],
"use" : [ "mymodule" ],

"tags": [ "gallery" ],

"examples": []
}
16 changes: 16 additions & 0 deletions tests/tap/mymodule/docs/index.mustache
@@ -0,0 +1,16 @@
<div class="intro">
<p>
*Summary Goes Here*
</p>
</div>

{{>getting-started}}

<h2>Description</h2>

<p>*Module Description Goes Here*</p>

```
//Module example code
```

4 changes: 4 additions & 0 deletions tests/tap/mymodule/js/mymodule.js
@@ -0,0 +1,4 @@

/**
Your Code Goes Here
*/
7 changes: 7 additions & 0 deletions tests/tap/mymodule/meta/mymodule.json
@@ -0,0 +1,7 @@
{
"mymodule": {
"requires": [
"yui-base"
]
}
}
25 changes: 25 additions & 0 deletions tests/tap/mymodule/tests/unit/index.html
@@ -0,0 +1,25 @@
<!doctype html>
<html>
<head>
<title>mymodule</title>
<script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script>
<script src="js/tests.js"></script>
<meta charset="utf-8" />
</head>
<body class="yui3-skin-sam">
<div id="logger"></div>

<script>
YUI({
coverage: ['mymodule'],
filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'raw'
}).use('test-console', 'test', 'module-tests', function(Y) {

(new Y.Test.Console()).render('#logger');

Y.Test.Runner.setName('mymodule');
Y.Test.Runner.run();
});
</script>
</body>
</html>
22 changes: 22 additions & 0 deletions tests/tap/mymodule/tests/unit/js/tests.js
@@ -0,0 +1,22 @@
YUI.add('module-tests', function(Y) {

var suite = new Y.Test.Suite('mymodule');
suite.myArray = ["one", "two", "three"]

suite.add(new Y.Test.Case({
name: 'Automated Tests',
'test first': function() {
Y.Assert.areSame('one', suite.myArray[0]);
},
'test second': function() {
Y.Assert.areSame('two', suite.myArray[1]);
},
'test third': function() {
Y.Assert.areSame('three', suite.myArray[2]);
}
}));

Y.Test.Runner.add(suite);


},'', { requires: [ 'test' ] });
2 changes: 2 additions & 0 deletions tests/tap/myothermodule/HISTORY.md
@@ -0,0 +1,2 @@
myothermodule
========
2 changes: 2 additions & 0 deletions tests/tap/myothermodule/README.md
@@ -0,0 +1,2 @@
myothermodule
========
10 changes: 10 additions & 0 deletions tests/tap/myothermodule/build.json
@@ -0,0 +1,10 @@
{
"name": "myothermodule",
"builds": {
"myothermodule": {
"jsfiles": [
"js/myothermodule.js"
]
}
}
}
11 changes: 11 additions & 0 deletions tests/tap/myothermodule/docs/component.json
@@ -0,0 +1,11 @@
{
"name" : "myothermodule",
"displayName": "Gallery: myothermodule",
"description": "*Summary Goes Here*",
"author" : [ "" ],
"use" : [ "myothermodule" ],

"tags": [ "gallery" ],

"examples": []
}
16 changes: 16 additions & 0 deletions tests/tap/myothermodule/docs/index.mustache
@@ -0,0 +1,16 @@
<div class="intro">
<p>
*Summary Goes Here*
</p>
</div>

{{>getting-started}}

<h2>Description</h2>

<p>*Module Description Goes Here*</p>

```
//Module example code
```

4 changes: 4 additions & 0 deletions tests/tap/myothermodule/js/myothermodule.js
@@ -0,0 +1,4 @@

/**
Your Code Goes Here
*/
7 changes: 7 additions & 0 deletions tests/tap/myothermodule/meta/myothermodule.json
@@ -0,0 +1,7 @@
{
"myothermodule": {
"requires": [
"yui-base"
]
}
}
25 changes: 25 additions & 0 deletions tests/tap/myothermodule/tests/unit/index.html
@@ -0,0 +1,25 @@
<!doctype html>
<html>
<head>
<title>myothermodule</title>
<script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script>
<script src="js/tests.js"></script>
<meta charset="utf-8" />
</head>
<body class="yui3-skin-sam">
<div id="logger"></div>

<script>
YUI({
coverage: ['myothermodule'],
filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'raw'
}).use('test-console', 'test', 'module-tests', function(Y) {

(new Y.Test.Console()).render('#logger');

Y.Test.Runner.setName('myothermodule');
Y.Test.Runner.run();
});
</script>
</body>
</html>
22 changes: 22 additions & 0 deletions tests/tap/myothermodule/tests/unit/js/tests.js
@@ -0,0 +1,22 @@
YUI.add('module-tests', function(Y) {

var suite = new Y.Test.Suite('myothermodule');
suite.myArray = ["one", "two", "three"]

suite.add(new Y.Test.Case({
name: 'Automated Tests',
'test one': function() {
Y.Assert.areSame('one', suite.myArray[0]);
},
'test two': function() {
Y.Assert.areSame('two', suite.myArray[1]);
},
'test three': function() {
Y.Assert.areSame('three', suite.myArray[2]);
}
}));

Y.Test.Runner.add(suite);


},'', { requires: [ 'test' ] });

1 comment on commit f5b1f91

@paulRbr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But breaks JUnit support : #22

Please sign in to comment.