Skip to content

Commit

Permalink
determenistic tests by sorting entries
Browse files Browse the repository at this point in the history
  • Loading branch information
thlorenz committed Dec 7, 2013
1 parent cbcda61 commit bb48d80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var test = require('tap').test
var path = require('path');
var mutiny = require('../')
var sort = require('./util/sort-entries');

function toUpper(file, content, cb) {
cb(null, content.toUpperCase());
Expand Down Expand Up @@ -38,7 +39,7 @@ test('\nrunning upperCase transform', function (t) {
.on('data', [].push.bind(data))
.on('end', function () {
t.deepEqual(
data
sort(data)
, [ { file: '/Users/thlorenz/dev/js/projects/mutiny/test/fixtures/root/index.html',
content: '<HTML>\n <BODY>\n <H1>INDEX</H1> \n </BODY>\n</HTML>\n' },
{ file: '/Users/thlorenz/dev/js/projects/mutiny/test/fixtures/root/sub1/one.html',
Expand All @@ -59,7 +60,7 @@ test('\nrunning upperCase and trimLeading transforms', function (t) {
.on('data', [].push.bind(data))
.on('end', function () {
t.deepEqual(
data
sort(data)
, [ { file: '/Users/thlorenz/dev/js/projects/mutiny/test/fixtures/root/index.html',
content: '<HTML>\n<BODY>\n<H1>INDEX</H1> \n</BODY>\n</HTML>\n' },
{ file: '/Users/thlorenz/dev/js/projects/mutiny/test/fixtures/root/sub1/one.html',
Expand All @@ -79,7 +80,7 @@ test('\nrunning error prone upperCase and trimLeading transforms', function (t)
mutiny({ root: root }, [ toUpperError, trimLeading ])
.on('error', function (err) {
t.deepEqual(
data
sort(data)
, [ { file: '/Users/thlorenz/dev/js/projects/mutiny/test/fixtures/root/index.html',
content: '<HTML>\n<BODY>\n<H1>INDEX</H1> \n</BODY>\n</HTML>\n' },
{ file: '/Users/thlorenz/dev/js/projects/mutiny/test/fixtures/root/sub1/one.html',
Expand Down
15 changes: 15 additions & 0 deletions test/util/sort-entries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

var path = require('path');

var go = module.exports = function (entries) {
return entries.reduce(function (sorted, e) {
var filename = path.basename(e.file);

if ((/index/).test(filename)) sorted[0] = e;
else if ((/one/).test(filename)) sorted[1] = e;
else sorted[2] = e;

return sorted;
}, []);
}

0 comments on commit bb48d80

Please sign in to comment.