-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathflat-strict.test.js
34 lines (29 loc) · 1.54 KB
/
flat-strict.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
const path = require("path");
const util = require("util");
const exec = util.promisify(require("node:child_process").exec);
const protocJsPlugin = path.resolve(__dirname, "..", "..", "bazel-bin", "generator", "protoc-gen-js");
const command = `protoc --plugin=protoc-gen-js=${protocJsPlugin} --js_out=import_style=commonjs_flat_strict,binary:.`;
describe("When import_style is 'commonjs_flat_strict'", () => {
it("'proto' is exported directly without package nesting", async () => {
await exec(command + " ./protos/proto.proto ./protos/proto2.proto", { cwd: __dirname });
const r = require(path.resolve(__dirname, "./protos/proto_pb"));
expect(r.CommandRequest).toBeDefined();
});
it("global 'proto' is not polluted", async () => {
await exec(command + " ./protos/proto.proto ./protos/proto2.proto", { cwd: __dirname });
const r = require(path.resolve(__dirname, "./protos/proto_pb"));
expect(global.proto).toBe(undefined);
});
it("addCommands resolves correctly without an error", async () => {
await exec(command + " ./protos/proto.proto ./protos/proto2.proto", { cwd: __dirname });
const r = require(path.resolve(__dirname, "./protos/proto_pb"));
const c = new r.CommandRequest();
c.addCommands();
});
it("getCommandsList resolves correctly without an error", async () => {
await exec(command + " ./protos/proto.proto ./protos/proto2.proto", { cwd: __dirname });
const r = require(path.resolve(__dirname, "./protos/proto_pb"));
const c = new r.CommandRequest();
c.getCommandsList();
});
});