/
main.js
76 lines (66 loc) · 1.71 KB
/
main.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
var LOADER = require("sourcemint-platform-nodejs/loader"),
ERROR = require("sourcemint-platform-nodejs/lib/util/error"),
BUNDLER = require("sourcemint-platform-nodejs/lib/bundler"),
EXAMPLES = require("sourcemint-loader-js/tests/examples"),
PATH = require("path"),
FS = require("fs");
exports.main = function()
{
var done = Q.ref();
var basePath = __dirname + "/../02-LoaderFeatures";
FS.readdirSync(basePath).forEach(function(filename)
{
var exampleBasePath = basePath + "/" + filename;
if (PATH.existsSync(exampleBasePath + "/package.json"))
{
done = Q.when(done, function()
{
return Q.when(BUNDLER.bundle(exampleBasePath, __dirname + "/dist", {
packageIdHashSeed: "__TEST__"
}), function()
{
// TODO: Only do this if running in strict mode.
/*
if (filename === "Avoid-VariableRequire")
{
// This example should have thrown and marked as successful below.
throw new Error("The 'Avoid-VariableRequire' example should have thrown!");
}
*/
},
function(err)
{
// TODO: Only do this if running in strict mode.
/*
if (filename === "Avoid-VariableRequire")
{
// We ignore the error as we expect it to throw if successful.
}
else
{
throw err;
}
*/
throw err;
});
});
}
});
return done.then(function()
{
return EXAMPLES.main({
LOADER: LOADER
}, {
uris: FS.readdirSync(__dirname + "/dist").filter(function(filename)
{
return FS.statSync(__dirname + "/dist/" + filename).isFile();
}).map(function(filename)
{
return __dirname + "/dist/" + filename;
})
});
});
}
if (require.main === module) {
exports.main().fail(ERROR.logError);
}