Перейти до основного змісту

2016 в Jest

· 9 хвилин читання

2016 рік був дуже важливим для JavaScript тестування з Jest. Перші пів року ми переписували Jest і створювали надійну основу для значного підвищення продуктивності та допомоги в тестуванні JavaScript коду. We flow-typed the entire codebase, built a ton of integration tests for Jest itself and adopted lerna to turn Jest from a framework into a Painless JavaScript Testing platform.

The newly created react-test-renderer finally enabled testing of react-native components. Through the jest-react-native preset (now merged directly into react-native) Jest now works out of the box for any React project and comes pre-configured in create-react-app and react-native projects. We integrated core pieces of Jest into react-native's packager and the completely new snapshot testing feature has since been used outside of Jest: It was integrated with React Storybook as “storyshots” and is being adopted by other test runners like ava.

The pretty-format project was rewritten with performance in mind to drive Jest's snapshot feature, was recently merged into Jest's monorepo and is also helpful in other test runners. На цей момент Jest презентує збірник різних ідей та рішень для тестування, а не єдину конкретну реалізацію тестового фреймворку.

I'd like to deeply thank all the people that have contributed to Jest this year, both from the open source community and at Facebook: Dmitrii Abramov, Cristian Carlesso, Dan Abramov, Daniel Lo Nigro, Maxim Derbin, Evan Scott, Forbes Lindesay, Keyan Zhang and 60 more people. We'd also like to welcome Michał Pierzchała (@thymikee) as first official external contributor to Jest. Він провів чудову роботу з управління проблемами та PR-ами репозиторію. If you'd like to start contributing to Jest, we have a bunch of good first tasks and we are always happy to help on our discord channel.

repl.it with Jest integration

Amjad Massad built a Jest container so you can now try out Jest directly in the browser. З цього моменту, ви можете використовувати його при створенні проблем на GitHub, що має допомогти швидше розв'язувати проблеми. Amjad and Haya are building repl.it to democratize programming by building powerful yet simple tools and platforms for educators, learners, and developers. They are also hiring talented engineers!

Оновлення спільноти

We feel incredibly humbled that 100+ companies have adopted Jest in the last six months. Такі компанії, як Twitter, Pinterest, Paypal, nytime, IBM (Watson), Spotify, eBay, SoundCloud, Intuit, FormidableLabs, Automattic, Trivago та Microsoft повністю або частково перейшли на Jest через потреби в тестуванні JavaScript. Ми вдячні за шанс, який ви дали цьому проєкту. Ми також хотіли б подякувати всім, хто відвідував конференції та зустрічі для презентації Jest і усім, хто створює дописи в блогах про власний досвід з Jest!

Ось що сталося у спільноті за останні два місяці:

New features, changes and fixes in Jest 17 & 18

Jest був створений понад п'ять років тому, тож, як старий фреймворк, він накопичив технічний борг. Ось чому ми рішуче робимо великі зміни частіше, ніж може здатися необхідним: ми вважаємо за потрібне поступово зменшувати технічний борг, аби забезпечити Jest повноцінною довгостроковою підтримкою. We didn't announce Jest 17 in a blog post and if you haven't upgraded to it in the last month you may find the changelog useful.

  • Breaking: Removed pit in favor of it or test and mockImpl in favor of jest.fn() or mockImplementation .
  • Breaking: Renamed --jsonOutputFile to --outputFile.
  • Breaking: Updated testRegex to include test.js and spec.js files.
  • Breaking: Replaced scriptPreprocessor with the new transform option.
  • Breaking: The testResultsProcessor function is now required to return the modified results.
  • Potentially Breaking: Properly resolve snapshotSerializers, setupFiles, transform, testRunner and testResultsProcessor with a resolution algorithm instead of using path.resolve. This mainly means that <rootDir> is no longer needed for these options.
  • Added: pretty-format and jest-editor-support were merged into Jest.
  • Added: expect.any, expect.anything, expect.objectContaining, expect.arrayContaining, expect.stringMatching.
  • Added: --testResultsProcessor is now exposed through the cli.
  • Added: Implemented file watching in jest-haste-map.
  • Added: Usage of Jest in watch mode can be hidden through JEST_HIDE_USAGE.
  • Added: expect.assertions(number) which will ensure that a specified amount of assertions is made in one test.
  • Added: .toMatchSnapshot(?string) feature to give snapshots a name.
  • Added: toMatchObject, toHaveProperty , toHaveLength matchers.
  • Added: expect.extend.
  • Added: Added support for custom snapshots serializers.
  • Added: Big diffs are now collapsed by default in snapshots and assertions. Added --expand (or -e) to show the full diff.
  • Added: jest.resetAllMocks which replaces jest.clearAllMocks.
  • Added: --json now includes information about individual tests inside a file.
  • Fixed: test.concurrent unhandled promise rejections.
  • Fixed: babel-plugin-jest-hoist when using jest.mock with three arguments.
  • Fixed: The JSON global in jest-environment-node now comes from the vm context instead of the parent context.
  • Fixed: Jest does not print stack traces from babel any longer.
  • Fixed: Fake timers are reset when FakeTimers.useTimers() is called.
  • Fixed: Regular expressions are properly escaped in snapshots.
  • Fixed: Improved pretty printing of large objects.
  • Fixed: NaN% Failed in the OS notification when using --notify.
  • Fixed: The first test run without cached timings will now use separate processes instead of running in band.
  • Fixed: Map/Set comparisons.
  • Fixed: test.concurrent now works with --testNamePattern.
  • Fixed: Improved .toContain matcher.
  • Fixed: Properly resolve modules with platform extensions on react-native.
  • Fixed: global built in objects in jest-environment-node now work properly.
  • Fixed: Create mock objects in the vm context instead of the parent context.
  • Fixed: .babelrc is now part of the transform cache key in babel-jest.
  • Fixed: docblock parsing with haste modules.
  • Fixed: Exit with the proper code when the coverage threshold is not reached.
  • Fixed: Jest now clears the entire scrollback in watch mode.
  • Deprecated: jest-react-native was deprecated and now forwards react-native.

Плани Jest на першу половину 2017

Six months ago we shared our plans for Jest and we are happy that we were able to execute well on almost all of them. Наші плани на наступні шість місяців:

  • Instant feedback: Nuclide integration and an improved and faster watch mode.
  • Improved developer experience: new mocking APIs and improved assertions.
  • Better performance and memory usage: analyze Jest and be more conscious about efficiency.
  • Snapshot Improvements: snapshot approval mode, syntax highlighting and improved react-test-renderer APIs.
  • Website: We'll overhaul the website and documentation and add a Jest cheat sheet.

Ми не надаватимемо графіків та розрахунків для цих нововведень, може так статись, що не все вдасться реалізувати. Якщо ви хочете допомогти з реалізацією, надішліть нам задачі та запроси на злиття з вашими ідеями; працюватимемо над покращенням Jest у 2017 році разом.