-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpromise-test.js
42 lines (33 loc) · 1.11 KB
/
promise-test.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
// Tests pinkyswear.js with the Promises / A+ Test Suite (https://github.com/promises-aplus/promises-tests)
// Requires node.js installation.
// Run "npm install promises-aplus-tests" in this dir to install, and then run with "node promise-test.js pinkyswear.js"
var promisesAplusTests = require("promises-aplus-tests");
if (!process.argv[2]) {
process.stdout.write('Error: Test requires file name as argument (e.g. pinkyswear.js).\n');
process.exit(1);
}
var pinkySwearSrc = require("./" + process.argv[2]);
function getAdapter(pinkySwear) {
return adapter = {
resolved: function(value) { var p = pinkySwear(); p(true, [value]); return p; },
rejected: function(reason) { var p = pinkySwear(); p(false, [reason]); return p;},
deferred: function() {
var p = pinkySwear();
return {
promise: p,
resolve: function(value) {
p(true, [value]);
},
reject: function(reason) {
p(false, [reason]);
}
};
}
};
}
console.log('Testing source...');
var success = true;
promisesAplusTests(getAdapter(pinkySwearSrc), function (err) {
if (err)
process.exit(2);
});