forked from nomaed/dts-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
112 lines (104 loc) · 2.87 KB
/
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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const path = require("path");
const dtsBuilder = require(".");
console.log("Testing dts-builder...");
Promise.all([
checkModule(),
checkGenerateBundles(),
checkGenerateBundlesFn(),
checkOptions(),
checkOptionsVerbose(),
generateBundle(),
])
.then(() => {
console.log("All tests passed!");
})
.catch((reason) => {
console.error(reason);
process.exitCode = 1;
});
function checkModule() {
return new Promise((resolve, reject) => {
if (!dtsBuilder) {
reject("Unable to load dts-builder module");
}
else {
console.log(" + Loaded dtsBuilder module");
resolve();
}
});
}
function checkGenerateBundles() {
return new Promise((resolve, reject) => {
if (!dtsBuilder.generateBundles) {
reject("No generate-bundles functionality detected");
}
else {
console.log(" + generateBundles detected");
resolve();
}
});
}
function checkGenerateBundlesFn() {
return new Promise((resolve, reject) => {
if (typeof dtsBuilder.generateBundles !== "function") {
reject("Invalid generate-bundles detected");
}
else {
console.log(" + generateBundles: function");
resolve();
}
});
}
function checkOptions() {
return new Promise((resolve, reject) => {
if (!dtsBuilder.DTSBuilderOptions) {
reject("No DTSBuilderOptions object detected");
}
else {
console.log(" + DTSBuilderOptions detected");
resolve();
}
});
}
function checkOptionsVerbose() {
return new Promise((resolve, reject) => {
if (typeof dtsBuilder.DTSBuilderOptions.verbose !== "boolean") {
reject("Invalid DTSBuilderOptions.verbose detected");
}
else {
console.log(" + DTSBuilderOptions.verbose: boolean");
resolve();
}
});
}
function generateBundle() {
const bundles = [{
name: "dts-builder",
alias: "dts",
sourceDir: path.resolve(__dirname, "dist"),
destDir: path.resolve(__dirname, "./test-out")
},
{
name: "dts-builder-2",
alias: "dts2",
sourceDir: path.resolve(__dirname, "dist"),
destDir: path.resolve(__dirname, "./test-out")
},
// {
// name: "failed",
// sourceDir: '.'
// }
];
return new Promise((resolve, reject) => {
dtsBuilder.DTSBuilderOptions.verbose = false;
dtsBuilder.generateBundles(bundles)
.then((result) => {
console.log(" + Generated test bundles: " + result.join(", "));
resolve();
})
.catch((err) => {
if (err instanceof Error) reject(`Exception: ${err.stack}`);
else reject(err);
});
})
}