Skip to content

Commit 2c2d400

Browse files
committed
Other: Manually merged gentests improvements, fixes #733
1 parent 6f74d30 commit 2c2d400

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

scripts/gentests.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,54 @@ var fs = require("fs"),
55
pbts = require("../cli/pbts");
66

77
[
8-
"tests/data/package.proto",
9-
"tests/data/rpc.proto",
10-
"tests/data/mapbox/vector_tile.proto",
11-
"tests/data/test.proto",
12-
"tests/data/convert.proto",
13-
"tests/data/comments.proto"
8+
{ file: "tests/data/comments.proto", flags: [] },
9+
{ file: "tests/data/convert.proto", flags: [] },
10+
{ file: "tests/data/mapbox/vector_tile.proto", flags: [] },
11+
{ file: "tests/data/package.proto", flags: [] },
12+
{ file: "tests/data/rpc.proto", flags: [ "es6" ] },
13+
{ file: "tests/data/rpc.proto", flags: [] },
14+
{ file: "tests/data/test.proto", flags: [] },
1415
]
15-
.forEach(function(file) {
16-
var out = file.replace(/\.proto$/, ".js");
16+
.forEach(function({ file, flags }) {
17+
var basename = file.replace(/\.proto$/, "");
18+
var out = [ basename ].concat(flags).join("-") + ".js";
1719
pbjs.main([
1820
"--target", "static-module",
1921
"--wrap", "commonjs",
20-
"--root", "test_" + path.basename(out, ".js"),
21-
"--out", out,
22+
"--root", "test_" + path.basename(basename, ".js"),
2223
file
23-
], function(err) {
24+
].concat(flags.map(function(flag) {
25+
return "--" + flag;
26+
})), function(err, output) {
2427
if (err)
2528
throw err;
2629
var pathToProtobufjs = path.relative(path.dirname(out), "minimal").replace(/\\/g, "/");
27-
fs.writeFileSync(out, fs.readFileSync(out).toString("utf8").replace(/"protobufjs\/minimal"/g, JSON.stringify(pathToProtobufjs)), "utf8");
30+
fs.writeFileSync(out, output.replace(/"protobufjs\/minimal"/g, JSON.stringify(pathToProtobufjs)));
2831
process.stdout.write("pbjs: " + file + " -> " + out + "\n");
2932
try {
3033
require(path.join(__dirname, "..", out));
31-
} catch (err2) {
32-
process.stderr.write("ERROR: " + err2.message + "\n");
34+
} catch (err) {
35+
if (!flags.includes("es6")) {
36+
process.stderr.write("ERROR: " + err.message + "\n");
37+
}
3338
}
3439
});
3540
});
3641

3742
[
43+
"tests/data/rpc.js",
3844
"tests/data/test.js",
39-
"tests/data/rpc.js"
4045
]
4146
.forEach(function(file) {
4247
var out = file.replace(/\.js$/, ".d.ts");
4348
pbts.main([
44-
"--out", out,
4549
"--no-comments",
4650
file
47-
], function(err) {
51+
], function(err, output) {
4852
if (err)
4953
throw err;
5054
var pathToProtobufjs = path.relative(path.dirname(out), "").replace(/\\/g, "/");
51-
fs.writeFileSync(out, fs.readFileSync(out).toString("utf8").replace(/"protobufjs"/g, JSON.stringify(pathToProtobufjs)), "utf8");
55+
fs.writeFileSync(out, output.replace(/"protobufjs"/g, JSON.stringify(pathToProtobufjs)));
5256
process.stdout.write("pbts: " + file + " -> " + out + "\n");
5357
});
5458
});

0 commit comments

Comments
 (0)