Skip to content

Commit

Permalink
Merge pull request #146 from broccolijs/subclassing-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Jun 10, 2021
2 parents 7845bf3 + a7ed4fa commit 5cde9c2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ function existsSync(path) {
}

class Funnel extends Plugin {
constructor(inputNode, options = {}) {
super([inputNode], {
constructor(inputs, options = {}) {
let inputNodes = Array.isArray(inputs) ? inputs : [inputs];
super(inputNodes, {
annotation: options.annotation,
persistentOutput: true,
needsCache: false,
Expand Down
62 changes: 62 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,4 +1106,66 @@ describe('broccoli-funnel', function() {
expect(getDestPathCalled).to.be.equal(1);
});
});

describe('subclassing', function() {
it('can be subclassed, simple destDir modification', async function() {
class FunnelSubclass extends Funnel.Funnel {
constructor(input, options) {
super(input, options);

this._hasBuilt = false;
}

build() {
if (this._hasBuilt === false) {
this.destDir = 'lol';
this._hasBuilt = true;
}

return super.build();
}
}

let inputPath = input.path('lib/utils');
let node = new FunnelSubclass(inputPath, {});
output = createBuilder(node);

await output.build();
let outputPath = output.path();

expect(walkSync(outputPath)).to.eql(['lol/', 'lol/foo.js']);
});

it('subclasses can provide additional trees', async function() {
class FunnelSubclass extends Funnel.Funnel {
constructor(inputNode, options) {
super([inputNode, input.path('dir1/subdir2')], options);

this._hasBuilt = false;
}

build() {
if (this._hasBuilt === false) {
if (!fs.existsSync(`${this.inputPaths[1]}/bar.css`)) {
throw new Error('Could not find file!!!');
}
// set custom destDir to ensure our custom build code ran
this.destDir = 'lol';
this._hasBuilt = true;
}

return super.build();
}
}

let inputPath = input.path('lib/utils');
let node = new FunnelSubclass(inputPath, {});
output = createBuilder(node);

await output.build();
let outputPath = output.path();

expect(walkSync(outputPath)).to.eql(['lol/', 'lol/foo.js']);
});
});
});

0 comments on commit 5cde9c2

Please sign in to comment.