Issue 1:
Bug report

We have a multi-page website that uses Webpack v4. Some pages have entry files. All pages have UI that needs JS to run.

In the past, we have had an entry that acts as a global JS initializer. This contains code for the site navigation, modernizr, and other global utilities. This is site level, consider it page agnostic code.

Additionally, we have entries for some pages that have additional JS driven UI. The entry files are not mapped to all pages though, so some pages will not have an entry.

When we build our <script> tags, we used to do something like this:

<script src='global.bundle.js' />
<script src='mypage.bundle.js' />

Stack Overflow discussion here: https://stackoverflow.com/questions/54795391/webpack-v4-with-multiple-entries-on-a-single-page-chunks-are-duplicated-unneces?noredirect=1

What is the current behavior?

We are encountering a bug in Webpack v4 where chunks that are shared between global and mypage are redundantly included in each bundle. Webpack is not aware that these files exist on the same page together, so it treats them as if they do not have access to eachother. We have been unable to locate a configuration that creates this link.

We need this link because we cannot make an entry for each page that imports an init file from global.js, and even if we could, it would cause unnecessary overhead. A clear separation of concerns is ideal, where global actions and page-specific actions live in different files and do not reference each other.

If the current behavior is a bug, please provide the steps to reproduce.

Create a config with more than one entry, and include both in the same page. Add some imports to files that are used on both entries. Analyze the bundle and you'll find the same chunks in both files.

Example config file here: https://gist.github.com/lostPixels/fef3f0cc4a3e99bf526249c605c2096f

What is the expected behavior?

Webpack should optimize the entries to include only one chunk, and share it across multiple entries that live together in one HTML document. The config should offer a way to describe these connections, and not assume that a page can only contain one entry file.

Other relevant information:

webpack version: 4.28.4

Node.js version: 9.3.0

Operating System: OSX

Additional tools: Salesforce Commerce Cloud Ecommerce platform

Issue 2:
@niieani

afterAll and beforeAll are called even if the test cases are skipped

running test suites with all test cases skipped takes very long time

yarn test:integration -t runtime-chunk --watch on node.js v10.0.0 (windows) causes this:

[6904]: src\fs_event_wrap.cc:90: Assertion `wrap != nullptr' failed.
1: node::DecodeWrite
2: node::DecodeWrite
3: node::Start
4: v8::internal::interpreter::BytecodeDecoder::Decode
5: v8::internal::RegExpImpl::Exec
6: v8::internal::RegExpImpl::Exec
7: v8::internal::Object::ToInt32
8: v8::internal::Object::GetProperty
9: v8::internal::NativesCollection<0>::GetScriptsSource
10: v8::internal::NativesCollection<0>::GetScriptsSource
11: 0000022CAD704281
error Command failed with exit code 134.

The WatchDetection suite cause jest crashing in watch mode

Investigation: When running jest in watch mode and running the WatchDetection test, sane emits EPERM errors on windows. sane doesn't seem to check the ignore list when directories are added (https://github.com/amasad/sane/blob/master/src/node_watcher.js#L310) and reading the stats from a removed file seem to cause an EPERM error here (https://github.com/amasad/sane/blob/master/src/node_watcher.js#L306). I believe it's an sane issue. Although it would also be great if watcher errors would be catched (via watcher.on("error")) in jest-haste-map.

events.js:183
throw er; // Unhandled 'error' event
^

Error: EPERM: operation not permitted, lstat 'D:\Repos\webpack\test\fixtures\temp-1600\file2.js'
error Command failed with exit code 1.

random error in watch mode, occurred only once

D:\Repos\webpack\node_modules\jest-runtime\build\index.js:581
const wrapper = this._environment.runScript(transformedFile.script)[
^

TypeError: Cannot read property 'Object.<anonymous>' of null
at Runtime._execModule (D:\Repos\webpack\node_modules\jest-runtime\build\index.js:581:72)
at Runtime.requireModule (D:\Repos\webpack\node_modules\jest-runtime\build\index.js:365:14)
at Runtime.requireModuleOrMock (D:\Repos\webpack\node_modules\jest-runtime\build\index.js:449:19)
at readdir (D:\Repos\webpack\node_modules\readdirp\readdirp.js:55:25)
at FSWatcher.<anonymous> (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:356:5)
at FSWatcher.Object.<anonymous>.NodeFsHandler._handleDir (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:407:18)
at FSWatcher.<anonymous> (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:456:19)
at FSWatcher.<anonymous> (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:461:16)
at D:\Repos\webpack\node_modules\graceful-fs\polyfills.js:287:18
at FSReqWrap.oncomplete (fs.js:153:5)

CI is hanging

(node:2612) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'spies' of undefined
(node:2612) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2612) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Could be related to jest-jasmine2...

https://travis-ci.org/webpack/webpack/jobs/374782908

https://travis-ci.org/webpack/webpack/jobs/374782909

https://ci.appveyor.com/project/sokra/webpack/build/1.0.7531/job/7m1jbsafpkt4sh5o

forceExit: true didn't help

There is no shortcut for --testPathPattern i. e. -p similar to -t

watch mode with single test suite and a lot of skipped test cases is very spammy

Example:

yarn test:integration -t runtime-chunk --watch --testPathPattern ConfigTestCases

Prints:

PASS test\ConfigTestCases.test.js
ConfigTestCases
additional-pass
simple
○ skipped 1 test
async-commons-chunk
all-selected
○ skipped 1 test
duplicate
○ skipped 1 test
existing-name
○ skipped 1 test
nested
○ skipped 1 test
node
○ skipped 1 test
simple
○ skipped 1 test
code-generation
require-context-id
○ skipped 1 test
use-strict
○ skipped 1 test
... (many many lines)
runtime-chunk
√ runtime-chunk should compile (754ms)
exported tests
√ should be able to load the split chunk on demand (6ms)
runtime-chunk-no-async
√ runtime-chunk-no-async should compile (105ms)
exported tests
√ should compile and evaluate fine
target
buffer
○ skipped 1 test
buffer-default
○ skipped 1 test
... (some more lines)

This message appears:

"transformIgnorePatterns": [
"<rootDir>/"
]

[BABEL] Note: The code generator has deoptimised the styling of "/home/travis/build/webpack/webpack/node_modules/text-encoding/lib/encoding-indexes.js" as it exceeds the max of "500KB".