diff --git a/packages/diff-sequences/src/index.ts b/packages/diff-sequences/src/index.ts index fe3c81f88c5a..6144781c3acb 100644 --- a/packages/diff-sequences/src/index.ts +++ b/packages/diff-sequences/src/index.ts @@ -34,7 +34,7 @@ // Forward diagonals kF: // zero diagonal intersects top left corner // positive diagonals intersect top edge -// negative diagonals insersect left edge +// negative diagonals intersect left edge // // Reverse diagonals kR: // zero diagonal intersects bottom right corner diff --git a/packages/jest-config/src/readConfigFileAndSetRootDir.ts b/packages/jest-config/src/readConfigFileAndSetRootDir.ts index 01a705f10620..b12f8bf6373e 100644 --- a/packages/jest-config/src/readConfigFileAndSetRootDir.ts +++ b/packages/jest-config/src/readConfigFileAndSetRootDir.ts @@ -59,7 +59,7 @@ export default async function readConfigFileAndSetRootDir( } if (configPath.endsWith(PACKAGE_JSON)) { - // Event if there's no "jest" property in package.json we will still use + // Even if there's no "jest" property in package.json we will still use // an empty object. configObject = configObject.jest || {}; } diff --git a/packages/jest-config/src/resolveConfigPath.ts b/packages/jest-config/src/resolveConfigPath.ts index d6cd21da82d2..88fe99a350e5 100644 --- a/packages/jest-config/src/resolveConfigPath.ts +++ b/packages/jest-config/src/resolveConfigPath.ts @@ -108,8 +108,8 @@ const resolveConfigPathByTraversing = ( throw new ValidationError(...makeMultipleConfigsErrorMessage(configFiles)); } - if (configFiles.length > 0 || packageJson) { - return configFiles[0] ?? packageJson; + if (configFiles.length > 0) { + return configFiles[0]; } // This is the system root. diff --git a/packages/jest-core/src/watch.ts b/packages/jest-core/src/watch.ts index a8cc3e1ff769..f6f4814eb645 100644 --- a/packages/jest-core/src/watch.ts +++ b/packages/jest-core/src/watch.ts @@ -173,10 +173,11 @@ export default async function watch( 'forbiddenOverwriteMessage' | 'key' > = RESERVED_KEY_PLUGINS.get(plugin.constructor as WatchPluginClass) || {}; - const key = reservedInfo.key || getPluginKey(plugin, globalConfig); - if (!key) { - continue; - } + const { key } = reservedInfo; + const pluginKey = key || getPluginKey(plugin, globalConfig); + if (!pluginKey) { + continue; + } const {forbiddenOverwriteMessage} = reservedInfo; watchPluginKeys.set(key, { forbiddenOverwriteMessage, diff --git a/packages/jest-diff/src/cleanupSemantic.ts b/packages/jest-diff/src/cleanupSemantic.ts index 0df74e0bc895..9a03238b1fa1 100644 --- a/packages/jest-diff/src/cleanupSemantic.ts +++ b/packages/jest-diff/src/cleanupSemantic.ts @@ -26,7 +26,7 @@ * CHANGES by pedrottimark to diff_match_patch_uncompressed.ts file: * * 1. Delete anything not needed to use diff_cleanupSemantic method - * 2. Convert from prototype properties to var declarations + * 2. Convert from prototype properties to variable declarations * 3. Convert Diff to class from constructor and prototype * 4. Add type annotations for arguments and return values * 5. Add exports @@ -37,9 +37,9 @@ * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']] * which means: delete 'Hello', add 'Goodbye' and keep ' world.' */ -var DIFF_DELETE = -1; -var DIFF_INSERT = 1; -var DIFF_EQUAL = 0; +const DIFF_DELETE = -1; +const DIFF_INSERT = 1; +const DIFF_EQUAL = 0; /** * Class representing one diff tuple. @@ -66,17 +66,17 @@ class Diff { * @return {number} The number of characters common to the start of each * string. */ -var diff_commonPrefix = function(text1: string, text2: string): number { +let diff_commonPrefix = function(text1: string, text2: string): number { // Quick check for common null cases. if (!text1 || !text2 || text1.charAt(0) != text2.charAt(0)) { return 0; } // Binary search. // Performance analysis: https://neil.fraser.name/news/2007/10/09/ - var pointermin = 0; - var pointermax = Math.min(text1.length, text2.length); - var pointermid = pointermax; - var pointerstart = 0; + let pointermin = 0; + let pointermax = Math.min(text1.length, text2.length); + let pointermid = pointermax; + let pointerstart = 0; while (pointermin < pointermid) { if (text1.substring(pointerstart, pointermid) == text2.substring(pointerstart, pointermid)) { @@ -97,7 +97,7 @@ var diff_commonPrefix = function(text1: string, text2: string): number { * @param {string} text2 Second string. * @return {number} The number of characters common to the end of each string. */ -var diff_commonSuffix = function(text1: string, text2: string): number { +let diff_commonSuffix = function(text1: string, text2: string): number { // Quick check for common null cases. if (!text1 || !text2 || text1.charAt(text1.length - 1) != text2.charAt(text2.length - 1)) { @@ -105,10 +105,10 @@ var diff_commonSuffix = function(text1: string, text2: string): number { } // Binary search. // Performance analysis: https://neil.fraser.name/news/2007/10/09/ - var pointermin = 0; - var pointermax = Math.min(text1.length, text2.length); - var pointermid = pointermax; - var pointerend = 0; + let pointermin = 0; + let pointermax = Math.min(text1.length, text2.length); + let pointermid = pointermax; + let pointerend = 0; while (pointermin < pointermid) { if (text1.substring(text1.length - pointermid, text1.length - pointerend) == text2.substring(text2.length - pointermid, text2.length - pointerend)) { @@ -131,10 +131,10 @@ var diff_commonSuffix = function(text1: string, text2: string): number { * string and the start of the second string. * @private */ -var diff_commonOverlap_ = function(text1: string, text2: string): number { +let diff_commonOverlap_ = function(text1: string, text2: string): number { // Cache the text lengths to prevent multiple calls. - var text1_length = text1.length; - var text2_length = text2.length; + let text1_length = text1.length; + let text2_length = text2.length; // Eliminate the null case. if (text1_length == 0 || text2_length == 0) { return 0; @@ -145,7 +145,7 @@ var diff_commonOverlap_ = function(text1: string, text2: string): number { } else if (text1_length < text2_length) { text2 = text2.substring(0, text1_length); } - var text_length = Math.min(text1_length, text2_length); + let text_length = Math.min(text1_length, text2_length); // Quick check for the worst case. if (text1 == text2) { return text_length; @@ -154,11 +154,11 @@ var diff_commonOverlap_ = function(text1: string, text2: string): number { // Start by looking for a single character match // and increase length until no match is found. // Performance analysis: https://neil.fraser.name/news/2010/11/04/ - var best = 0; - var length = 1; + let best = 0; + let length = 1; while (true) { - var pattern = text1.substring(text_length - length); - var found = text2.indexOf(pattern); + let pattern = text1.substring(text_length - length); + let found = text2.indexOf(pattern); if (found == -1) { return best; } @@ -174,22 +174,22 @@ var diff_commonOverlap_ = function(text1: string, text2: string): number { /** * Reduce the number of edits by eliminating semantically trivial equalities. - * @param {!Array.} diffs Array of diff tuples. + * @param {Array} diffs Array of diff tuples. */ - var diff_cleanupSemantic = function(diffs: Array) { - var changes = false; - var equalities = []; // Stack of indices where equalities are found. - var equalitiesLength = 0; // Keeping our own length var is faster in JS. +let diff_cleanupSemantic = function(diffs: Array) { + let changes = false; + let equalities = []; // Stack of indices where equalities are found. + let equalitiesLength = 0; // Keeping our own length let is faster in JS. /** @type {?string} */ - var lastEquality = null; + let lastEquality = null; // Always equal to diffs[equalities[equalitiesLength - 1]][1] - var pointer = 0; // Index of current position. + let pointer = 0; // Index of current position. // Number of characters that changed prior to the equality. - var length_insertions1 = 0; - var length_deletions1 = 0; + let length_insertions1 = 0; + let length_deletions1 = 0; // Number of characters that changed after the equality. - var length_insertions2 = 0; - var length_deletions2 = 0; + let length_insertions2 = 0; + let length_deletions2 = 0; while (pointer < diffs.length) { if (diffs[pointer][0] == DIFF_EQUAL) { // Equality found. equalities[equalitiesLength++] = pointer; @@ -247,10 +247,10 @@ var diff_commonOverlap_ = function(text1: string, text2: string): number { while (pointer < diffs.length) { if (diffs[pointer - 1][0] == DIFF_DELETE && diffs[pointer][0] == DIFF_INSERT) { - var deletion = diffs[pointer - 1][1]; - var insertion = diffs[pointer][1]; - var overlap_length1 = diff_commonOverlap_(deletion, insertion); - var overlap_length2 = diff_commonOverlap_(insertion, deletion); + let deletion = diffs[pointer - 1][1]; + let insertion = diffs[pointer][1]; + let overlap_length1 = diff_commonOverlap_(deletion, insertion); + let overlap_length2 = diff_commonOverlap_(insertion, deletion); if (overlap_length1 >= overlap_length2) { if (overlap_length1 >= deletion.length / 2 || overlap_length1 >= insertion.length / 2) { @@ -291,7 +291,7 @@ var diff_commonOverlap_ = function(text1: string, text2: string): number { * e.g: The cat came. -> The cat came. * @param {!Array.} diffs Array of diff tuples. */ -var diff_cleanupSemanticLossless = function(diffs: Array) { +let diff_cleanupSemanticLossless = function(diffs: Array) { /** * Given two strings, compute a score representing whether the internal * boundary falls on logical boundaries. @@ -313,21 +313,21 @@ var diff_cleanupSemanticLossless = function(diffs: Array) { // 'whitespace'. Since this function's purpose is largely cosmetic, // the choice has been made to use each language's native features // rather than force total conformity. - var char1 = one.charAt(one.length - 1); - var char2 = two.charAt(0); - var nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex_); - var nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex_); - var whitespace1 = nonAlphaNumeric1 && + let char1 = one.charAt(one.length - 1); + let char2 = two.charAt(0); + let nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex_); + let nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex_); + let whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex_); - var whitespace2 = nonAlphaNumeric2 && + let whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex_); - var lineBreak1 = whitespace1 && + let lineBreak1 = whitespace1 && char1.match(linebreakRegex_); - var lineBreak2 = whitespace2 && + let lineBreak2 = whitespace2 && char2.match(linebreakRegex_); - var blankLine1 = lineBreak1 && + let blankLine1 = lineBreak1 && one.match(blanklineEndRegex_); - var blankLine2 = lineBreak2 && + let blankLine2 = lineBreak2 && two.match(blanklineStartRegex_); if (blankLine1 || blankLine2) { @@ -349,36 +349,36 @@ var diff_cleanupSemanticLossless = function(diffs: Array) { return 0; } - var pointer = 1; + let pointer = 1; // Intentionally ignore the first and last element (don't need checking). while (pointer < diffs.length - 1) { if (diffs[pointer - 1][0] == DIFF_EQUAL && diffs[pointer + 1][0] == DIFF_EQUAL) { // This is a single edit surrounded by equalities. - var equality1 = diffs[pointer - 1][1]; - var edit = diffs[pointer][1]; - var equality2 = diffs[pointer + 1][1]; + let equality1 = diffs[pointer - 1][1]; + let edit = diffs[pointer][1]; + let equality2 = diffs[pointer + 1][1]; // First, shift the edit as far left as possible. - var commonOffset = diff_commonSuffix(equality1, edit); + let commonOffset = diff_commonSuffix(equality1, edit); if (commonOffset) { - var commonString = edit.substring(edit.length - commonOffset); + let commonString = edit.substring(edit.length - commonOffset); equality1 = equality1.substring(0, equality1.length - commonOffset); edit = commonString + edit.substring(0, edit.length - commonOffset); equality2 = commonString + equality2; } // Second, step character by character right, looking for the best fit. - var bestEquality1 = equality1; - var bestEdit = edit; - var bestEquality2 = equality2; - var bestScore = diff_cleanupSemanticScore_(equality1, edit) + + let bestEquality1 = equality1; + let bestEdit = edit; + let bestEquality2 = equality2; + let bestScore = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2); while (edit.charAt(0) === equality2.charAt(0)) { equality1 += edit.charAt(0); edit = edit.substring(1) + equality2.charAt(0); equality2 = equality2.substring(1); - var score = diff_cleanupSemanticScore_(equality1, edit) + + let score = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2); // The >= encourages trailing rather than leading whitespace on edits. if (score >= bestScore) { @@ -424,15 +424,15 @@ var blanklineStartRegex_ = /^\r?\n\r?\n/; * Any edit section can move as long as it doesn't cross an equality. * @param {!Array.} diffs Array of diff tuples. */ -var diff_cleanupMerge = function(diffs: Array) { +let diff_cleanupMerge = function(diffs: Array) { // Add a dummy entry at the end. diffs.push(new Diff(DIFF_EQUAL, '')); - var pointer = 0; - var count_delete = 0; - var count_insert = 0; - var text_delete = ''; - var text_insert = ''; - var commonlength; + let pointer = 0; + let count_delete = 0; + let count_insert = 0; + let text_delete = ''; + let text_insert = ''; + let commonlength; while (pointer < diffs.length) { switch (diffs[pointer][0]) { case DIFF_INSERT: @@ -511,7 +511,7 @@ var diff_cleanupMerge = function(diffs: Array) { // Second pass: look for single edits surrounded on both sides by equalities // which can be shifted sideways to eliminate an equality. // e.g: ABAC -> ABAC - var changes = false; + let changes = false; pointer = 1; // Intentionally ignore the first and last element (don't need checking). while (pointer < diffs.length - 1) { diff --git a/website/blog/2016-03-11-javascript-unit-testing-performance.md b/website/blog/2016-03-11-javascript-unit-testing-performance.md index 1baa53b30c39..e1ff01c6eed2 100644 --- a/website/blog/2016-03-11-javascript-unit-testing-performance.md +++ b/website/blog/2016-03-11-javascript-unit-testing-performance.md @@ -116,4 +116,4 @@ More importantly, adding new tests causes total runtime to grow very slowly. Eng With Jest's recent 0.9 release and performance improvements from the [node-haste2 integration](https://github.com/jestjs/jest/pull/599), the runtime of the [Relay](https://github.com/facebook/relay) framework's test suite went down from 60 seconds to about 25 and the [react-native](https://github.com/facebook/react-native) test suite now finishes in less than ten seconds on a 13” MacBook Pro. -We're very happy with the wins we've seen so far, and we're going to keep working on Jest and making it better. If you are curious about contributing to Jest, feel free get in touch on GitHub, [Discord](https://discord.gg/j6FKKQQrW9) or Facebook :) +We're very happy with the wins we've seen so far, and we're going to keep working on Jest and making it better. If you are curious about contributing to Jest, feel free to get in touch on GitHub, [Discord](https://discord.gg/j6FKKQQrW9) or Facebook :) diff --git a/website/blog/2016-04-12-jest-11.md b/website/blog/2016-04-12-jest-11.md index 8a2be7f94663..2a8c2d809d44 100644 --- a/website/blog/2016-04-12-jest-11.md +++ b/website/blog/2016-04-12-jest-11.md @@ -49,7 +49,7 @@ import LikeButton from 'LikeButton'; // LikeButton is properly unmocked! #### (Auto)Mocking Improvements -We have made numerous improvements and bug fixes to Jest's automocking feature, improved npm3 support and added new manual mocking APIs. Many people have expressed a desire use Jest with the automocking feature disabled. A global configuration option [`automock`](/docs/api#automock-boolean), which can be set to `false`, was added. +We have made numerous improvements and bug fixes to Jest's automocking feature, improved npm3 support and added new manual mocking APIs. Many people have expressed a desire to use Jest with the automocking feature disabled. A global configuration option [`automock`](/docs/api#automock-boolean), which can be set to `false`, was added. We have also added two new APIs to simplify manual mocks. `jest.mock` specifies a manual mock factory for a specific test: diff --git a/website/blog/2016-06-22-jest-13.md b/website/blog/2016-06-22-jest-13.md index 7d2310a7fae6..1696731bfe88 100644 --- a/website/blog/2016-06-22-jest-13.md +++ b/website/blog/2016-06-22-jest-13.md @@ -11,7 +11,7 @@ The Flow project has evolved a lot within Facebook and has been successfully ado -With the help of [lerna](https://github.com/lerna/lerna), we continued to modularize the Jest project. With just a small [update to the configuration](https://github.com/lerna/lerna#lernajson), Flow and lerna now get along well with each other. Splitting up Jest into packages helped us rethink module boundaries and enabled us to ship useful [packages](https://github.com/jestjs/jest/tree/main/packages) standalone: The `jest-runtime` and `jest-repl` cli tools now allow you to run scripts in a sandboxed Jest environment, enabling you to run and debug your app from the command line. This is especially helpful for projects that use Facebook's `@providesModule` module convention. To get started, just install `jest-repl` and run it in the same folder you normally run your tests in! We also published a `jest-changed-files` package that finds changed files in version control for either git or hg, a common thing in developer tools. +With the help of [lerna](https://github.com/lerna/lerna), we continued to modularize the Jest project. With just a small [update to the configuration](https://github.com/lerna/lerna#lernajson), Flow and lerna now get along well with each other. Splitting up Jest into packages helped us rethink module boundaries and enabled us to ship useful [packages](https://github.com/jestjs/jest/tree/main/packages) standalone: The `jest-runtime` and `jest-repl` CLI tools now allow you to run scripts in a sandboxed Jest environment, enabling you to run and debug your app from the command line. This is especially helpful for projects that use Facebook's `@providesModule` module convention. To get started, just install `jest-repl` and run it in the same folder you normally run your tests in! We also published a `jest-changed-files` package that finds changed files in version control for either git or hg, a common thing in developer tools. ## New and improved features diff --git a/website/blog/2016-12-15-2016-in-jest.md b/website/blog/2016-12-15-2016-in-jest.md index 70cfd0940589..6d678e47d9d6 100644 --- a/website/blog/2016-12-15-2016-in-jest.md +++ b/website/blog/2016-12-15-2016-in-jest.md @@ -32,7 +32,7 @@ Here is what happened in the community in the last two months: - Jason Bonta and Dmitrii Abramov [redefined the “testing pyramid”](https://twitter.com/abramov_dmitrii/status/805913874704674816) we were talking a lot about at Facebook. - [jest-codemods](https://github.com/skovhus/jest-codemods#jest-codemods) now allows you to painlessly migrate from Mocha, Tape and Ava to Jest. - The React team announced [improvements to the react-test-renderer](https://facebook.github.io/react/blog/2016/11/16/react-v15.4.0.html) in 15.4.0. -- Orta Therox build an amazing [vscode-jest integration](https://github.com/orta/vscode-jest#the-aim) and donated the code for editor support to Jest. +- Orta Therox built an amazing [vscode-jest integration](https://github.com/orta/vscode-jest#the-aim) and donated the code for editor support to Jest. - Pavithra Kodmad is documenting [Flipkarts adoption of Jest](http://pksjce.github.io/2016/12/08/notes-on-jest) and shares some getting started tips. - Kent C. Dodds wrote about [migrating to Jest at Paypal](https://medium.com/@kentcdodds/migrating-to-jest-881f75366e7e#.ticf0wchu) and Jason Brown [wrote about migrating to Jest as well](http://browniefed.com/blog/migrating-ava-to-jest/). - Ben McCormick wrote about [saving time with Jest](http://benmccormick.org/2016/12/10/saving-time-with-jest/). diff --git a/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md b/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md index 0764f16dbf0a..b0fb66d13162 100644 --- a/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md +++ b/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md @@ -17,7 +17,7 @@ Until now, Jest could only operate in one project at a time. This is often cumbe Jest is now collapsing the usage guide after the first test run to save vertical space in the terminal. -Further, we completely overhauled how the configuration system works inside of Jest. You can now pass any configuration option through the CLI to overwrite the ones specified in your configuration file. Along with that, we changed Jest to look for a `jest.config.js` file by default which means you are now able to define a Jest configuration using JavaScript as well as being able to configure it through `package.json` like before. Through the addition of all these new features, you are now able to combine Jest in more powerful ways than ever before. For example, if you would like to find out which tests Jest would run given a set of changed files from a commit across multiple projects in a monorepo, you can combine cli arguments like this now: +Further, we completely overhauled how the configuration system works inside of Jest. You can now pass any configuration option through the CLI to overwrite the ones specified in your configuration file. Along with that, we changed Jest to look for a `jest.config.js` file by default which means you are now able to define a Jest configuration using JavaScript as well as being able to configure it through `package.json` like before. Through the addition of all these new features, you are now able to combine Jest in more powerful ways than ever before. For example, if you would like to find out which tests Jest would run given a set of changed files from a commit across multiple projects in a monorepo, you can combine CLI arguments like this now: ```bash $ jest --projects projectA projectB --listTests --findRelatedTests projectA/banana.js projectB/kiwi.js @@ -42,7 +42,7 @@ We made a number of additions and improvements to the testing APIs which will he - **Pretty-Format Plugins:** A number of new pretty-format plugins were added to Jest. We now pretty-print [Immutable.js](https://github.com/facebook/immutable-js/) data structures and HtmlElements in assertion failures and snapshots. - **Custom Environment:** It is now possible to add a `@jest-environment node|jsdom` annotation to the doc-block comment of a test file to use a test environment different from the default for individual tests. -Here is an example of all how all the new APIs together will make testing more delightful: +Here is an example of how the new APIs will work together to make testing more delightful: ```js /** diff --git a/website/blog/2018-05-29-jest-23-blazing-fast-delightful-testing.md b/website/blog/2018-05-29-jest-23-blazing-fast-delightful-testing.md index 132594a4e49d..240de0c69d3b 100644 --- a/website/blog/2018-05-29-jest-23-blazing-fast-delightful-testing.md +++ b/website/blog/2018-05-29-jest-23-blazing-fast-delightful-testing.md @@ -9,7 +9,7 @@ Today we are excited to announce Jest 23, our largest major release to date! Tog We would also like to welcome both [Babel](https://babeljs.io/) and [webpack](https://webpack.js.org/) to the Jest community! After converting from Mocha to Jest 23 Beta, webpack saw their total test suite time reduced 6x from over 13 minutes to 2 minutes 20 seconds. [#blazingmeansgood](https://twitter.com/search?q=%23blazingmeansgood) -Here's are some of the Jest 23 highlights and breaking changes. +Here are some of the Jest 23 highlights and breaking changes. diff --git a/website/blog/2022-04-25-jest-28.md b/website/blog/2022-04-25-jest-28.md index 1cbcbc329aa8..6e35c9e4e836 100644 --- a/website/blog/2022-04-25-jest-28.md +++ b/website/blog/2022-04-25-jest-28.md @@ -27,7 +27,7 @@ Now let's talk about the new features in Jest 28, which is way more exciting! An ### Sharding of test run -Jest now includes a new [`--shard`](/docs/cli#--shard) CLI option, contributed by [Mario Nebl](https://github.com/marionebl). It allows you to run parts of your test across different machine, and has been one of Jest's oldest feature requests. +Jest now includes a new [`--shard`](/docs/cli#--shard) CLI option, contributed by [Mario Nebl](https://github.com/marionebl). It allows you to run parts of your test across different machines, and has been one of Jest's oldest feature requests. Jest's own test suite on CI went from about 10 minutes to 3 on Ubuntu, and on Windows from 20 minutes to 7.