-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
77 lines (68 loc) · 2.12 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
'use strict';
const expect = require('chai').expect;
const path = require('path');
const progeny = require('progeny');
const ProtoBufJSCompiler = require('./');
const fs = require('fs');
function getFixturePath(subPath) {
return path.join(__dirname, 'fixtures', subPath);
}
describe('protobufjs-brunch', () => {
let plugin;
beforeEach(() => {
plugin = new ProtoBufJSCompiler({
conventions: {},
plugins: {
proto: {
includePath: getFixturePath("/included"),
}
},
});
});
it('should be an object', () => {
expect(plugin).to.be.an.instanceof(ProtoBufJSCompiler);
});
it('should have #compile method', () => {
expect(plugin).to.respondTo('compile');
});
it('should compile and produce valid result', () => {
const file = {
path: getFixturePath("test.proto"),
};
file.data = fs.readFileSync(file.path, "utf8");
return plugin.compile(file).then(file => {
expect(file.data).to.contain("require(\"protobufjs/light\");");
expect(file.data).to.contain("Test:");
});
});
it('should compile with relative dependancies', () => {
const file = {
path: getFixturePath("outer.proto"),
};
file.data = fs.readFileSync(file.path, "utf8");
return plugin.compile(file).then(file => {
expect(file.data).to.contain("require(\"protobufjs/light\");");
expect(file.data).to.contain("Outer:");
});
});
it('should compile with a package', () => {
const file = {
path: getFixturePath("package.proto"),
};
file.data = fs.readFileSync(file.path, "utf8");
return plugin.compile(file).then(file => {
expect(file.data).to.contain("require(\"protobufjs/light\");");
expect(file.data).to.contain("Test:");
});
});
it('should compile with dependancies from an include path', () => {
const file = {
path: getFixturePath("/source/depender.proto"),
};
file.data = fs.readFileSync(file.path, "utf8");
return plugin.compile(file).then(file => {
expect(file.data).to.contain("require(\"protobufjs/light\");");
expect(file.data).to.contain("Depender:");
});
});
});