Skip to content

Commit

Permalink
Reenabled rebuild test for webpack 5
Browse files Browse the repository at this point in the history
  • Loading branch information
larixer committed Sep 14, 2020
1 parent f302d6d commit ace8630
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"memory-fs": "^0.4.1",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
"webpack": "^5.0.0-beta.29"
"webpack": "^5.0.0-beta.30"
},
"dependencies": {
"debug": "^3.0.0"
Expand Down
55 changes: 55 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,59 @@ describe("webpack-virtual-modules", function() {
done();
});
});

it("shouldn't rebuild all virtual modules on any change", function(done) {
var plugin = new Plugin({
'entry.js': 'require("./dep_one.js"); require("./dep_two.js");',
'dep_one.js': '',
'dep_two.js': ''
});
var compiler = webpack({
plugins: [plugin],
entry: { bundle: './entry.js' },
mode: 'development'
});
compiler.outputFileSystem = new MemoryFileSystem();
var count = 0;
var modulesBuilt;

var waiter = function(callback) {
const fileWatchers = compiler.watchFileSystem.watcher.fileWatchers;
if (fileWatchers instanceof Map) {
// Webpack v5 is a map
if (fileWatchers.keys === 0) {
setTimeout(function() { waiter(callback); }, 50);
} else {
callback();
}
} else if (!Object.keys(fileWatchers).length) {
setTimeout(function() { waiter(callback); }, 50);
} else {
callback();
}
};

compiler.hooks.done.tap('Plugin', function(stats) {
if(count !== 1) return;
// assert doesn't throw here for some reason, writing to modulesBuilt
modulesBuilt = stats.toJson().modules.filter(function(m) {
return m.codeGenerated != null ? m.codeGenerated : m.built;
}).length;
});

var watcher = compiler.watch(null, function(err, stats) {
if (count === 0) {
waiter(function() {
plugin.writeModule('dep_one.js', 'var baz;');
var fs = stats.compilation.inputFileSystem;
fs.purge();
assert.equal(fs.readFileSync(path.resolve('dep_one.js')).toString(), 'var baz;');
count++;
});
} else {
watcher.close(done);
assert.equal(modulesBuilt, 1, 'only one module should be built');
}
});
});
});
14 changes: 4 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,6 @@ convert-source-map@^1.6.0:
dependencies:
safe-buffer "~5.1.1"

core-js@^3.6.5:
version "3.6.5"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.5.tgz#7395dc273af37fb2e50e9bd3d9fe841285231d1a"
integrity sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==

core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
Expand Down Expand Up @@ -2525,10 +2520,10 @@ webpack-sources@^1.4.3:
source-list-map "^2.0.0"
source-map "~0.6.1"

webpack@^5.0.0-beta.29:
version "5.0.0-beta.29"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.0.0-beta.29.tgz#73ee7eb4a8603ade49f37c7417a1560871a79c90"
integrity sha512-uBVX3gDHTN3FnIqlrGmav5FRW7CujSN4aybLbAd8Uc1hTk+zXDmZAFJFa0pCzzWv7FkKyhdv0+q8BRL2OK7+xg==
webpack@^5.0.0-beta.30:
version "5.0.0-beta.30"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.0.0-beta.30.tgz#11cf2d4ed1ec78eb836da2a7be7809e5e074e3eb"
integrity sha512-pOAAo71m6icygRrOPn/lQM4Ky8MN+9dDBwEU9Get285VBbmuZE6AFqizEEV692mYgUit/0+7vnjsnUr8xX2puA==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.45"
Expand All @@ -2538,7 +2533,6 @@ webpack@^5.0.0-beta.29:
"@webassemblyjs/wasm-parser" "1.9.0"
acorn "^7.4.0"
chrome-trace-event "^1.0.2"
core-js "^3.6.5"
enhanced-resolve "5.0.0-beta.10"
eslint-scope "^5.1.0"
events "^3.2.0"
Expand Down

0 comments on commit ace8630

Please sign in to comment.