Skip to content

Commit

Permalink
Update test suite
Browse files Browse the repository at this point in the history
- update the packages
- move to broccoli-test-helpers
  • Loading branch information
sparshithNR committed Nov 18, 2019
1 parent 660fb71 commit 0a036cf
Show file tree
Hide file tree
Showing 4 changed files with 1,603 additions and 431 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"node": true,
"mocha": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2017
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
},
"devDependencies": {
"broccoli-fixture": "^1.0.0",
"broccoli-test-helper": "^2.0.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"mocha": "^5.0.1",
"mocha-eslint": "^4.1.0"
"mocha": "^6.2.2",
"mocha-eslint": "^5.0.0"
},
"scripts": {
"test": "mocha",
Expand Down
93 changes: 58 additions & 35 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,72 @@
'use strict';

var MergeTrees = require('./');
var chai = require('chai'), expect = chai.expect;
var chaiAsPromised = require('chai-as-promised'); chai.use(chaiAsPromised);
var Fixture = require('broccoli-fixture');

function mergeFixtures(inputFixtures, options) {
return Fixture.build(new MergeTrees(inputFixtures.map(inputFixture), options));
}

function inputFixture(obj) {
return new Fixture.Node(obj);
}
const MergeTrees = require('./');
const { createBuilder, createTempDir } = require('broccoli-test-helper');
const chai = require('chai'), expect = chai.expect;

describe('MergeTrees', function() {
it('smoke test', function() {
return expect(mergeFixtures([
{
foo: '1'
}, {
baz: {}
}
])).to.eventually.deep.equal({
foo: '1',
baz: {}
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', function () {
return mergeFixtures([
{
foo: 'hello',
}, {
foo: 'morehello',
}
]).then(v => {
throw Error(`Should not fulfill ${v}`);
}, err => {
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. [Fixturify]');
expect(err.message).to.contain(' 2. [Fixturify]');
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 foo exists in');
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',
});
});
});
Expand Down
Loading

0 comments on commit 0a036cf

Please sign in to comment.