This repository has been archived by the owner on May 8, 2024. It is now read-only.
/
helper.js
82 lines (67 loc) · 1.89 KB
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*jshint -W064*/
var chai = require('chai');
var assert = chai.assert;
var path = require('path');
var Q = require('q');
var FS = require('q-io/fs');
var differ = require('unfunk-diff');
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function testName(filename) {
return path.basename(path.dirname(filename)) + '/' + path.basename(filename);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function createBulkCompare(grunt) {
var queue = [];
function getQueue() {
return queue.slice(0);
}
function directory(one, two, label) {
queue.push({
one: one,
two: two,
label: label
});
}
function getReducer (dir) {
dir = dir.split(path.sep).join('/');
return function reducer (memo, value) {
value = value.split(path.sep).join('/');
if (value.indexOf(dir) === 0) {
value = value.substring(dir.length);
}
if (value.length > 0) {
memo.push(value);
}
return memo;
};
}
function runTest() {
return Q.all(queue.map(function (item) {
return Q.all([
FS.listTree(item.one),
FS.listTree(item.two)
]).spread(function (oneTree, twoTree) {
item.oneTree = oneTree.reduce(getReducer(item.one), []);
item.twoTree = twoTree.reduce(getReducer(item.two), []);
item.oneTree.sort();
item.twoTree.sort();
return Q.resolve().then(function () {
assert.deepEqual(item.oneTree, item.twoTree);
}).fail(function (err) {
grunt.log.writeln(differ.ansi(err.actual, err.expected));
throw err;
});
});
}));
}
return {
runTest: runTest,
getQueue: getQueue,
directory: directory
};
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
module.exports = {
testName: testName,
createBulkCompare: createBulkCompare
};