Skip to content

Commit

Permalink
Merge pull request #78 from broccolijs/tests
Browse files Browse the repository at this point in the history
add failing tests for #76 (also backfill other linkroot tests)
  • Loading branch information
stefanpenner authored Sep 20, 2016
2 parents c89842e + 176e6a2 commit c37000d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 6 deletions.
23 changes: 20 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function Funnel(inputNode, options) {
this._includeFileCache = makeDictionary();
this._destinationPathCache = makeDictionary();
this._currentTree = new FSTree();
this._lastInputPath = null;

var keys = Object.keys(options || {});
for (var i = 0, l = keys.length; i < l; i++) {
Expand Down Expand Up @@ -175,12 +176,28 @@ Funnel.prototype.build = function() {
var linkedRoots = false;
if (this.shouldLinkRoots()) {
linkedRoots = true;
if (fs.existsSync(inputPath)) {

var inputPathExist = fs.existsSync(inputPath);

if (this._lastInputPath ? !inputPathExist : inputPathExist) {
rimraf.sync(this.outputPath);
this._copy(inputPath, this.destPath);
} else if (this.allowEmpty) {

if (inputPathExist) {
this._copy(inputPath, this.destPath);
}
}

if (!inputPathExist && this.allowEmpty) {
mkdirp.sync(this.destPath);
}

// TODO: verify if this scenario exists
// Refer to test "can properly handle the output path being a broken symlink"
if (inputPathExist && !fs.existsSync(this.outputPath)) {
this._copy(inputPath, this.destPath);
}

this._lastInputPath = inputPath;
} else {
this.processFilters(inputPath);
}
Expand Down
71 changes: 68 additions & 3 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var Funnel = require('..');

describe('broccoli-funnel', function(){
var builder;
var FIXTURE_INPUT = __dirname + '/../tmp/INPUT';
var FIXTURE_INPUT = path.resolve(__dirname, '../tmp/INPUT');

beforeEach(function() {
fs.mkdirpSync(FIXTURE_INPUT);
Expand Down Expand Up @@ -57,7 +57,6 @@ describe('broccoli-funnel', function(){
});

describe('rebuilding', function() {

it('correctly rebuilds', function() {
var inputPath = FIXTURE_INPUT + '/dir1';
var node = new Funnel(FIXTURE_INPUT + '/dir1', {
Expand All @@ -83,6 +82,73 @@ describe('broccoli-funnel', function(){
});
});

describe('linkRoots', function() {
it('links input to output if possible', function() {
var node = new Funnel(FIXTURE_INPUT);

builder = new broccoli.Builder(node);
return builder.build()
.then(function(results) {
expect(fs.lstatSync(results.directory).isSymbolicLink()).to.eql(true);
});
});

it('links input to destDir if possible', function() {
var node = new Funnel(FIXTURE_INPUT, {
destDir: 'output'
});

builder = new broccoli.Builder(node);
return builder.build()
.then(function(results) {
expect(fs.lstatSync(results.directory + '/output').isSymbolicLink()).to.eql(true);
expect(fs.realpathSync(results.directory + '/output')).to.eql(FIXTURE_INPUT);
});
});

it('links srcDir to output if possible', function() {
var node = new Funnel(FIXTURE_INPUT, {
srcDir: 'dir1'
});

builder = new broccoli.Builder(node);
return builder.build()
.then(function(results) {
expect(fs.lstatSync(results.directory).isSymbolicLink()).to.eql(true);
expect(fs.realpathSync(results.directory)).to.eql(path.resolve(FIXTURE_INPUT, 'dir1'));
});
});

it('links srcDir to destDir if possible', function() {
var node = new Funnel(FIXTURE_INPUT, {
srcDir: 'lib',
destDir: 'output'
});

builder = new broccoli.Builder(node);
return builder.build()
.then(function(results) {
expect(fs.lstatSync(results.directory + '/output').isSymbolicLink()).to.eql(true);
expect(fs.realpathSync(results.directory + '/output')).to.eql(path.resolve(FIXTURE_INPUT, 'lib'));
});
});

it('stable on idempotent rebuild', function() {
var node = new Funnel(FIXTURE_INPUT + '/dir1');
var stat;

builder = new broccoli.Builder(node);
return builder.build()
.then(function(results) {
stat = fs.lstatSync(results.directory);
return builder.build();
})
.then(function(results) {
expect(fs.lstatSync(results.directory)).to.eql(stat);
});
});
});

describe('processFile', function() {
it('is not called when simply linking roots (aka no include/exclude)', function() {
var inputPath = FIXTURE_INPUT + '/dir1';
Expand Down Expand Up @@ -193,7 +259,6 @@ describe('broccoli-funnel', function(){
});
});


it('correctly chooses _matchedWalk scenario', function() {
var inputPath = FIXTURE_INPUT + '/dir1';
var node;
Expand Down

0 comments on commit c37000d

Please sign in to comment.