Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration of tests to Jest #6565

Merged
merged 102 commits into from
Apr 30, 2018
Merged

Migration of tests to Jest #6565

merged 102 commits into from
Apr 30, 2018

Conversation

niieani
Copy link
Contributor

@niieani niieani commented Feb 25, 2018

@ooflorent Alright, I've done it.

This is with jest:

Test Suites: 1 failed, 65 passed, 66 total
Tests:       1 failed, 126 skipped, 10692 passed, 10819 total
Snapshots:   2 passed, 2 total
Time:        141.898s, estimated 158s
Ran all test suites.

This was before on the same computer with mocha:

  10713 passing (13m)
  127 pending

That's an improvement of almost 6x in terms of speed.

(fewer total number of tests under Mocha, cause I run that test around 4.0-alpha, before merging current master)


```
 FAIL  test/TestCasesDevelopment.test.js (13.204s)
  ● TestCases › development › chunks › runtime › exported tests › should not load a chunk which is included in a already loaded one

    expect(received).toBe(expected) // Object.is equality

    Expected: true
    Received: false

      175 |             __webpack_require__.e(/*! require.ensure */3).then((function(require) {
      176 |                     try {
    > 177 |                             expect(sync).toBe(true);
      178 |                             done();
      179 |                     } catch(e) {
      180 |                             done(e);

      at test/js/development/chunks/runtime/bundle.js:177:18
```

~~~We still need facebook/jest#5673 to ship before we can merge, but this is ready for review.~~~

ooflorent and others added 26 commits January 24, 2018 17:29
used regexps:

([\(\)a-zA-Z0-9\."'/ +{}\[\]=\-,:?_!]+)\.should\.be\.eql
➡️
expect($1).toBe

expect\(([\(\)a-zA-Z0-9\."'/ +{}\[\]=\-,:?_!]+)\)\.toBe\(\[
➡️
expect($1).toEqual([

expect\(([\(\)a-zA-Z0-9\."'/ +{}\[\]=\-,:?_!]+)\)\.toBe\(\{
➡️
expect($1).toEqual({
\.to\.have\.property\((.+)\)\.toEqual\((.+)\);
➡️
.toHaveProperty($1, $2);
# Conflicts:
#	test/BenchmarkTestCases.benchmark.js
#	test/CachePlugin.unittest.js
#	test/HotTestCases.test.js
#	test/NormalModule.unittest.js
#	test/ProfilingPlugin.unittest.js
#	test/TestCases.test.js
#	test/configCases/parsing/harmony-this/index.js
#	test/configCases/plugins/profiling-plugin/index.js
#	test/configCases/plugins/profiling-plugin/webpack.config.js
#	test/watchCases/runtime/static-import/0/index.js
#	yarn.lock
@sokra
Copy link
Member

sokra commented Apr 30, 2018

Looks good, I noticed one small issue. 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. Anyway, it's not super critical.

# Conflicts:
#	test/WatchTestCases.test.js
@webpack-bot
Copy link
Contributor

@sokra Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@shellscape Please review the new changes.

@sokra sokra merged commit fe0eb45 into webpack:master Apr 30, 2018
@sokra
Copy link
Member

sokra commented Apr 30, 2018

Awesome thanks

@devenbansod
Copy link

Awesome stuff @niieani !

Thanks @skovhus for /~https://github.com/skovhus/jest-codemods 🙌

Just throwing it out there:
I had faced some similar issues while transforming test assertions for babel's tests, which had a mix of mocha, chai, assert in babel/babel#7476. I feel I should have noted these down, and regret not reporting them to /~https://github.com/skovhus/jest-codemods then.

But then I wrote a (seriously) toned down version focusing on assertions that babel's tests required at: /~https://github.com/devenbansod/jest-expect-codemod

@sokra
Copy link
Member

sokra commented May 1, 2018

I got this random error in watch mode after changing a file. Can't reproduce...

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)

@sokra
Copy link
Member

sokra commented May 1, 2018

@niieani What's the reason for using Math.random().toPrecision(21).slice(2) in the folder name for watch-src tests?

@sokra
Copy link
Member

sokra commented May 1, 2018

I also ran into this issue jestjs/jest#4820 but no blocker

@sokra
Copy link
Member

sokra commented May 1, 2018

image

The slashes are also a bit weird here, but not important (windows)

@sokra
Copy link
Member

sokra commented May 1, 2018

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. Anyway, it's not super critical.

image

It's worse than I original estimated. The whole jest watch process crashes.

Please handle the error event in jest-haste-map.

@niieani
Copy link
Contributor Author

niieani commented May 1, 2018

@sokra Math.random().toPrecision(21).slice(2) is needed to always create a new folder. Jest creates their haste map, I think based on package.json files. When there are duplicates of the same path and the same package name, it can cause issues.

Not sure what to do with the Windows issues, I'm on macOS. :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants