From 5435f8d0214982cb4289f59019564602980d6185 Mon Sep 17 00:00:00 2001 From: Brenden Palmer Date: Tue, 13 Apr 2021 21:46:55 -0400 Subject: [PATCH] invalidate `_content` on rebuild if necessary --- lib/strategies/simple.js | 5 +++++ test/simple-concat-test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/strategies/simple.js b/lib/strategies/simple.js index ff394a8..0afbc5c 100644 --- a/lib/strategies/simple.js +++ b/lib/strategies/simple.js @@ -30,8 +30,13 @@ class Entry { } set content(value) { + // if value is less than content limit, set it; otherwise invalidate + // previous content so we don't unexpectedly read from it later and + // get the old content if (value.length < this._contentLimit) { this._content = value; + } else { + this._content = undefined; } } } diff --git a/test/simple-concat-test.js b/test/simple-concat-test.js index 9ecaf38..174dc9c 100644 --- a/test/simple-concat-test.js +++ b/test/simple-concat-test.js @@ -504,6 +504,32 @@ describe('simple-concat', function() { await builder.build(); }); + + it('properly invalidates if contentLimit is exceeded on rebuild', async function() { + let node = concat(inputDir, { + outputFile: '/rebuild.js', + inputFiles: ['**/*.js'], + allowNone: true, + contentLimit: 5, + sourceMapConfig: { enabled: false } + }); + + builder = new broccoli.Builder(node); + + await builder.build(); + expect(read(builder.outputPath + '/rebuild.js')).to.eql(''); + + write('z.js', 'z'); + write('a.js', 'a'); + await builder.build(); + expect(read(builder.outputPath + '/rebuild.js')).to.eql('a\nz'); + + write('a.js', 'abcdefg'); + await builder.build(); + expect(read(builder.outputPath + '/rebuild.js')).to.eql('abcdefg\nz'); + + await builder.build(); + }); }); describe('CONCAT_STATS', function() {