-
Notifications
You must be signed in to change notification settings - Fork 35
/
test.js
95 lines (87 loc) · 2.27 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
'use strict';
const MergeTrees = require('./');
const { createBuilder, createTempDir } = require('broccoli-test-helper');
const chai = require('chai'), expect = chai.expect;
describe('MergeTrees', function() {
let input, input2, output, subject;
beforeEach(async function () {
input = await createTempDir();
input2 = await createTempDir();
subject = new MergeTrees([input.path(), input2.path()]);
output = createBuilder(subject);
});
afterEach(async function() {
input.dispose();
input2.dispose();
output.dispose();
});
it('smoke test', async function() {
input.write({
'a.log': 'A'
});
input2.write({
'b.log': 'B',
'c.log': 'C'
});
await output.build();
expect(output.read()).to.deep.equal({
'a.log': 'A',
'b.log': 'B',
'c.log': 'C'
});
});
it('gives a useful error when merged trees have collisions', async function() {
input.write({
'a.log': 'A'
});
input2.write({
'a.log': 'A'
});
try {
await output.build();
} catch (err) {
// append input nodes' names
expect(err.message).to.contain('[BroccoliMergeTrees] error while merging the following');
expect(err.message).to.contain(` 1. ${input.path()}`);
expect(err.message).to.contain(` 2. ${input2.path()}`);
// wrap existing message
expect(err.message).to.contain('Merge error: file a.log exists in');
}
});
it(`doesn't error when merged trees have collisions and overwrite is set`, async function() {
input.write({
'a.log': 'A'
});
input2.write({
'a.log': 'B'
});
subject = new MergeTrees([input.path(), input2.path()], {
overwrite: true,
});
output = createBuilder(subject);
await output.build();
expect(output.read()).to.deep.equal({
'a.log': 'B',
});
});
it('smoke test with destDir', async function() {
input.write({
foo: '1'
});
input2.write({
baz: {}
});
subject = new MergeTrees([input.path(), input2.path()], {
destDir: 'test'
});
output = createBuilder(subject);
await output.build();
expect(output.read()).to.deep.equal({
test : {
foo: '1',
baz: {}
}
});
});
});
require('mocha-eslint')('*.js');