From 244f7dc7310de24b4892fac55113f8a06f24d947 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 23 Mar 2020 20:56:37 +0100 Subject: [PATCH] chore: update to prettier@2 (#9692) --- .circleci/config.yml | 2 + .github/workflows/nodejs.yml | 3 + docs/Configuration.md | 2 +- docs/Es6ClassMocks.md | 2 +- docs/MockFunctionAPI.md | 2 +- docs/MockFunctions.md | 9 +- docs/Puppeteer.md | 4 +- e2e/MockStdinWatchPlugin.js | 2 +- .../environmentAfterTeardown.test.ts | 5 +- e2e/__tests__/listTests.test.ts | 15 +--- e2e/__tests__/requireAfterTeardown.test.ts | 5 +- e2e/coverage-report/notRequiredInTestSuite.js | 2 +- e2e/filter/my-broken-filter.js | 2 +- e2e/filter/my-broken-setup-filter.js | 4 +- e2e/filter/my-clowny-filter.js | 2 +- e2e/filter/my-filter.js | 2 +- e2e/filter/my-secondary-filter.js | 2 +- e2e/filter/my-setup-filter.js | 4 +- e2e/global-setup-custom-transform/setup.js | 2 +- e2e/global-setup-node-modules/setup.js | 2 +- e2e/global-setup/project-1/setup.js | 2 +- e2e/global-setup/project-2/setup.js | 2 +- e2e/global-setup/setup.js | 2 +- e2e/global-setup/setupWithConfig.js | 2 +- e2e/global-setup/setupWithDefaultExport.js | 2 +- e2e/global-teardown/project-1/teardown.js | 2 +- e2e/global-teardown/project-2/teardown.js | 2 +- e2e/global-teardown/teardown.js | 2 +- e2e/global-teardown/teardownWithConfig.js | 2 +- .../teardownWithDefaultExport.js | 2 +- e2e/jasmine-async/__tests__/generator.test.js | 4 +- e2e/json-reporter/sum.js | 2 +- e2e/override-globals/index.js | 2 +- e2e/runJest.ts | 4 +- .../__mocks__/fs.js | 2 +- e2e/test-results-processor/processor.js | 2 +- examples/mongodb/teardown.js | 2 +- package.json | 4 +- packages/diff-sequences/perf/index.js | 2 +- .../src/__tests__/asymmetricMatchers.test.ts | 8 +- .../expect/src/__tests__/matchers.test.js | 36 +++----- .../expect/src/__tests__/spyMatchers.test.js | 6 +- packages/expect/src/index.ts | 4 +- packages/expect/src/spyMatchers.ts | 27 +++--- packages/expect/src/toThrowMatchers.ts | 2 +- .../jest-circus/src/__mocks__/testUtils.ts | 4 +- .../src/ReporterValidationErrors.ts | 4 +- .../jest-core/src/__tests__/watch.test.js | 2 +- .../watch_filename_pattern_mode.test.js | 2 +- .../watch_test_name_pattern_mode.test.js | 2 +- .../jest-each/src/__tests__/array.test.ts | 2 +- .../jest-each/src/__tests__/template.test.ts | 2 +- .../src/__mocks__/index.ts | 4 +- packages/jest-environment-jsdom/src/index.ts | 4 +- .../src/__tests__/index.test.js | 5 +- packages/jest-haste-map/src/index.ts | 4 +- .../jest-haste-map/src/lib/WatchmanWatcher.js | 10 +-- packages/jest-haste-map/src/worker.ts | 4 +- packages/jest-jasmine2/src/PCancelable.js | 2 +- .../jest-jasmine2/src/jasmine/CallTracker.ts | 18 ++-- packages/jest-jasmine2/src/jasmine/Env.ts | 82 +++++++++---------- .../src/jasmine/JsApiReporter.ts | 22 ++--- .../src/jasmine/ReportDispatcher.ts | 10 +-- packages/jest-jasmine2/src/jasmine/Spec.ts | 14 ++-- .../jest-jasmine2/src/jasmine/SpyStrategy.ts | 30 +++---- packages/jest-jasmine2/src/jasmine/Timer.ts | 8 +- .../jest-jasmine2/src/jasmine/createSpy.ts | 2 +- .../jest-jasmine2/src/jasmine/jasmineLight.ts | 6 +- .../jest-jasmine2/src/jasmine/spyRegistry.ts | 14 ++-- .../jest-jasmine2/src/jasmineAsyncInstall.ts | 10 +-- packages/jest-jasmine2/src/jestExpect.ts | 2 +- packages/jest-jasmine2/src/queueRunner.ts | 4 +- .../jest-jasmine2/src/setup_jest_globals.ts | 2 +- packages/jest-leak-detector/README.md | 2 +- .../src/__tests__/index.test.ts | 2 +- .../jest-mock/src/__tests__/index.test.ts | 16 ++-- packages/jest-mock/src/index.ts | 30 +++---- packages/jest-phabricator/src/index.ts | 2 +- packages/jest-repl/src/cli/index.ts | 2 +- .../src/generateEmptyCoverage.ts | 2 +- .../jest-reporters/src/summary_reporter.ts | 8 +- packages/jest-runtime/src/cli/index.ts | 9 +- packages/jest-snapshot/src/index.ts | 8 +- .../jest-transform/src/ScriptTransformer.ts | 8 +- .../src/__tests__/script_transformer.test.js | 4 +- .../src/__tests__/deepCyclicCopy.test.ts | 24 +++--- packages/jest-util/src/createProcessObject.ts | 2 +- .../jest-util/src/installCommonGlobals.ts | 4 +- .../src/__tests__/validate.test.ts | 8 +- packages/jest-validate/src/utils.ts | 4 +- .../workers/jest_worker.js | 4 +- .../src/__performance_tests__/workers/pi.js | 2 +- .../workers/worker_farm.js | 4 +- scripts/buildUtils.js | 5 +- scripts/remove-prettier-dep.js | 18 ++++ .../version-22.x/MockFunctionAPI.md | 2 +- .../version-22.x/MockFunctions.md | 9 +- .../versioned_docs/version-22.x/Puppeteer.md | 4 +- .../version-23.x/Es6ClassMocks.md | 2 +- .../version-23.x/MockFunctionAPI.md | 2 +- .../version-23.x/MockFunctions.md | 9 +- .../versioned_docs/version-23.x/Puppeteer.md | 4 +- .../version-24.x/Configuration.md | 2 +- .../version-24.x/Es6ClassMocks.md | 2 +- .../version-24.x/MockFunctionAPI.md | 2 +- .../version-24.x/MockFunctions.md | 9 +- .../versioned_docs/version-24.x/Puppeteer.md | 4 +- .../version-25.1/Configuration.md | 2 +- .../version-25.1/MockFunctions.md | 9 +- yarn.lock | 7 +- 110 files changed, 332 insertions(+), 380 deletions(-) create mode 100644 scripts/remove-prettier-dep.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 7ca80ca29228..33113f6c43b2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,6 +24,8 @@ jobs: - image: circleci/node:8 steps: - checkout + - run: + command: yarn remove-prettier-dep - restore-cache: *restore-cache - run: *install - save-cache: *save-cache diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 556a26a33542..cb8ddbc912cf 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -80,6 +80,9 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} + - name: remove prettier dep + run: yarn remove-prettier-dep + if: matrix.node-version == '8.17.0' - name: install run: yarn install-no-ts-build - name: run tests diff --git a/docs/Configuration.md b/docs/Configuration.md index 7796705e5085..9e88f1b33c5b 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -429,7 +429,7 @@ module.exports = async () => { ```js // teardown.js -module.exports = async function() { +module.exports = async function () { await global.__MONGOD__.stop(); }; ``` diff --git a/docs/Es6ClassMocks.md b/docs/Es6ClassMocks.md index f6c91499ada8..06209155e304 100644 --- a/docs/Es6ClassMocks.md +++ b/docs/Es6ClassMocks.md @@ -221,7 +221,7 @@ In order to mock a constructor function, the module factory must return a constr ```javascript jest.mock('./sound-player', () => { - return function() { + return function () { return {playSoundFile: () => {}}; }; }); diff --git a/docs/MockFunctionAPI.md b/docs/MockFunctionAPI.md index c46c8c2895b3..7fca5d9bd548 100644 --- a/docs/MockFunctionAPI.md +++ b/docs/MockFunctionAPI.md @@ -202,7 +202,7 @@ Expected mock function "mockedFunction" to have been called, but it was not call Syntactic sugar function for: ```js -jest.fn(function() { +jest.fn(function () { return this; }); ``` diff --git a/docs/MockFunctions.md b/docs/MockFunctions.md index 64a950ab5b39..746add09fe87 100644 --- a/docs/MockFunctions.md +++ b/docs/MockFunctions.md @@ -86,10 +86,7 @@ const myMock = jest.fn(); console.log(myMock()); // > undefined -myMock - .mockReturnValueOnce(10) - .mockReturnValueOnce('x') - .mockReturnValue(true); +myMock.mockReturnValueOnce(10).mockReturnValueOnce('x').mockReturnValue(true); console.log(myMock(), myMock(), myMock(), myMock()); // > 10, 'x', true, true @@ -169,7 +166,7 @@ The `mockImplementation` method is useful when you need to define the default im ```js // foo.js -module.exports = function() { +module.exports = function () { // some implementation; }; @@ -220,7 +217,7 @@ const myObj = { // is the same as const otherObj = { - myMethod: jest.fn(function() { + myMethod: jest.fn(function () { return this; }), }; diff --git a/docs/Puppeteer.md b/docs/Puppeteer.md index c0df40d8d54a..b64350a286ef 100644 --- a/docs/Puppeteer.md +++ b/docs/Puppeteer.md @@ -63,7 +63,7 @@ const os = require('os'); const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); -module.exports = async function() { +module.exports = async function () { const browser = await puppeteer.launch(); // store the browser instance so we can teardown it later // this global is only available in the teardown but not in TestEnvironments @@ -127,7 +127,7 @@ const rimraf = require('rimraf'); const path = require('path'); const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); -module.exports = async function() { +module.exports = async function () { // close the browser instance await global.__BROWSER_GLOBAL__.close(); diff --git a/e2e/MockStdinWatchPlugin.js b/e2e/MockStdinWatchPlugin.js index e22c6400d218..f1d92456dc5b 100644 --- a/e2e/MockStdinWatchPlugin.js +++ b/e2e/MockStdinWatchPlugin.js @@ -12,7 +12,7 @@ class MockStdinWatchPlugin { constructor({stdin, config}) { this._stdin = stdin; if (typeof this._stdin.setRawMode !== 'function') { - this._stdin.setRawMode = function() {}; + this._stdin.setRawMode = function () {}; } this._config = config; } diff --git a/e2e/__tests__/environmentAfterTeardown.test.ts b/e2e/__tests__/environmentAfterTeardown.test.ts index f9f247964a4e..5b1c0a63ee2e 100644 --- a/e2e/__tests__/environmentAfterTeardown.test.ts +++ b/e2e/__tests__/environmentAfterTeardown.test.ts @@ -10,10 +10,7 @@ import runJest from '../runJest'; test('prints useful error for environment methods after test is done', () => { const {stderr} = runJest('environment-after-teardown'); - const interestingLines = stderr - .split('\n') - .slice(9, 18) - .join('\n'); + const interestingLines = stderr.split('\n').slice(9, 18).join('\n'); expect(wrap(interestingLines)).toMatchSnapshot(); expect(stderr.split('\n')[9]).toBe( diff --git a/e2e/__tests__/listTests.test.ts b/e2e/__tests__/listTests.test.ts index 6de9620c52a1..73923613d29c 100644 --- a/e2e/__tests__/listTests.test.ts +++ b/e2e/__tests__/listTests.test.ts @@ -24,12 +24,7 @@ describe('--listTests flag', () => { expect(exitCode).toBe(0); expect( - wrap( - normalizePaths(stdout) - .split('\n') - .sort() - .join('\n'), - ), + wrap(normalizePaths(stdout).split('\n').sort().join('\n')), ).toMatchSnapshot(); }); @@ -39,13 +34,7 @@ describe('--listTests flag', () => { expect(exitCode).toBe(0); expect(() => JSON.parse(stdout)).not.toThrow(); expect( - wrap( - JSON.stringify( - JSON.parse(stdout) - .map(normalizePaths) - .sort(), - ), - ), + wrap(JSON.stringify(JSON.parse(stdout).map(normalizePaths).sort())), ).toMatchSnapshot(); }); }); diff --git a/e2e/__tests__/requireAfterTeardown.test.ts b/e2e/__tests__/requireAfterTeardown.test.ts index 4ce1201e337c..c8353dc7ed2b 100644 --- a/e2e/__tests__/requireAfterTeardown.test.ts +++ b/e2e/__tests__/requireAfterTeardown.test.ts @@ -11,10 +11,7 @@ import runJest from '../runJest'; test('prints useful error for requires after test is done', () => { const {stderr} = runJest('require-after-teardown'); - const interestingLines = stderr - .split('\n') - .slice(9, 18) - .join('\n'); + const interestingLines = stderr.split('\n').slice(9, 18).join('\n'); expect(wrap(interestingLines)).toMatchSnapshot(); expect(stderr.split('\n')[19]).toMatch( diff --git a/e2e/coverage-report/notRequiredInTestSuite.js b/e2e/coverage-report/notRequiredInTestSuite.js index 7814240ed547..8bbc209edb50 100644 --- a/e2e/coverage-report/notRequiredInTestSuite.js +++ b/e2e/coverage-report/notRequiredInTestSuite.js @@ -12,7 +12,7 @@ throw new Error( // Flow annotations to make sure istanbul can instrument non ES6 source // eslint-disable-next-line no-unreachable -module.exports = function(j: string, d: string): string { +module.exports = function (j: string, d: string): string { if (j) { return d; } else { diff --git a/e2e/filter/my-broken-filter.js b/e2e/filter/my-broken-filter.js index 42d16cfc4fbe..1dbe6f140429 100644 --- a/e2e/filter/my-broken-filter.js +++ b/e2e/filter/my-broken-filter.js @@ -7,7 +7,7 @@ 'use strict'; -module.exports = function(tests) { +module.exports = function (tests) { return new Promise((resolve, reject) => { reject(new Error('My broken filter error.')); }); diff --git a/e2e/filter/my-broken-setup-filter.js b/e2e/filter/my-broken-setup-filter.js index 887cc8b63e5a..e5dce8248fbb 100644 --- a/e2e/filter/my-broken-setup-filter.js +++ b/e2e/filter/my-broken-setup-filter.js @@ -7,13 +7,13 @@ 'use strict'; -module.exports = function(tests) { +module.exports = function (tests) { return { filtered: tests.filter(t => t.indexOf('foo') !== -1).map(test => ({test})), }; }; -module.exports.setup = function() { +module.exports.setup = function () { return new Promise((resolve, reject) => { setTimeout(() => { reject(new Error('My broken setup filter error.')); diff --git a/e2e/filter/my-clowny-filter.js b/e2e/filter/my-clowny-filter.js index f716b38d690d..e1a18606a515 100644 --- a/e2e/filter/my-clowny-filter.js +++ b/e2e/filter/my-clowny-filter.js @@ -7,7 +7,7 @@ 'use strict'; -module.exports = function(tests) { +module.exports = function (tests) { return { filtered: 'potato', }; diff --git a/e2e/filter/my-filter.js b/e2e/filter/my-filter.js index 33db34218a63..801f5e3bd462 100644 --- a/e2e/filter/my-filter.js +++ b/e2e/filter/my-filter.js @@ -7,7 +7,7 @@ 'use strict'; -module.exports = function(tests) { +module.exports = function (tests) { return new Promise(resolve => { setTimeout(() => { resolve({ diff --git a/e2e/filter/my-secondary-filter.js b/e2e/filter/my-secondary-filter.js index 70b3fb8c352f..f0b23d0579df 100644 --- a/e2e/filter/my-secondary-filter.js +++ b/e2e/filter/my-secondary-filter.js @@ -7,7 +7,7 @@ 'use strict'; -module.exports = function(tests) { +module.exports = function (tests) { return { filtered: tests.filter(t => t.indexOf('foo') !== -1).map(test => ({test})), }; diff --git a/e2e/filter/my-setup-filter.js b/e2e/filter/my-setup-filter.js index d9ce620f0405..9fc6f3b12d8c 100644 --- a/e2e/filter/my-setup-filter.js +++ b/e2e/filter/my-setup-filter.js @@ -11,7 +11,7 @@ const setupData = { filterText: 'this will return no tests', }; -module.exports = function(tests) { +module.exports = function (tests) { return { filtered: tests .filter(t => t.indexOf(setupData.filterText) !== -1) @@ -19,7 +19,7 @@ module.exports = function(tests) { }; }; -module.exports.setup = function() { +module.exports.setup = function () { return new Promise(resolve => { setTimeout(() => { setupData.filterText = 'foo'; diff --git a/e2e/global-setup-custom-transform/setup.js b/e2e/global-setup-custom-transform/setup.js index 975d615e401b..b17b8d38fd51 100644 --- a/e2e/global-setup-custom-transform/setup.js +++ b/e2e/global-setup-custom-transform/setup.js @@ -12,7 +12,7 @@ const path = require('path'); const DIR = path.join(os.tmpdir(), 'jest-global-setup-custom-transform'); -module.exports = function() { +module.exports = function () { return new Promise(resolve => { createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); diff --git a/e2e/global-setup-node-modules/setup.js b/e2e/global-setup-node-modules/setup.js index edea4d43a008..c77d928eb161 100644 --- a/e2e/global-setup-node-modules/setup.js +++ b/e2e/global-setup-node-modules/setup.js @@ -13,7 +13,7 @@ const path = require('path'); const DIR = path.join(os.tmpdir(), 'jest-global-setup-node-modules'); -module.exports = function() { +module.exports = function () { return new Promise(resolve => { createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); diff --git a/e2e/global-setup/project-1/setup.js b/e2e/global-setup/project-1/setup.js index f5374c480b30..3c32a63ccd14 100644 --- a/e2e/global-setup/project-1/setup.js +++ b/e2e/global-setup/project-1/setup.js @@ -12,7 +12,7 @@ const path = require('path'); const DIR = path.join(os.tmpdir(), 'jest-global-setup-project-1'); -module.exports = function() { +module.exports = function () { return new Promise((resolve, reject) => { createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); diff --git a/e2e/global-setup/project-2/setup.js b/e2e/global-setup/project-2/setup.js index 383f473c424e..1477774a2643 100644 --- a/e2e/global-setup/project-2/setup.js +++ b/e2e/global-setup/project-2/setup.js @@ -12,7 +12,7 @@ const path = require('path'); const DIR = path.join(os.tmpdir(), 'jest-global-setup-project-2'); -module.exports = function() { +module.exports = function () { return new Promise((resolve, reject) => { createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); diff --git a/e2e/global-setup/setup.js b/e2e/global-setup/setup.js index 39e924c39daf..43f07b5d26a8 100644 --- a/e2e/global-setup/setup.js +++ b/e2e/global-setup/setup.js @@ -12,7 +12,7 @@ const path = require('path'); const DIR = path.join(os.tmpdir(), 'jest-global-setup'); -module.exports = function() { +module.exports = function () { // This uses a flow annotation to show it can be transpiled return new Promise((resolve, reject: any) => { createDirectory(DIR); diff --git a/e2e/global-setup/setupWithConfig.js b/e2e/global-setup/setupWithConfig.js index 139a863fea39..78e2b910c082 100644 --- a/e2e/global-setup/setupWithConfig.js +++ b/e2e/global-setup/setupWithConfig.js @@ -5,6 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -module.exports = function(jestConfig) { +module.exports = function (jestConfig) { console.log(jestConfig.testPathPattern); }; diff --git a/e2e/global-setup/setupWithDefaultExport.js b/e2e/global-setup/setupWithDefaultExport.js index f60cfc524bf4..ea8cd34e38c1 100644 --- a/e2e/global-setup/setupWithDefaultExport.js +++ b/e2e/global-setup/setupWithDefaultExport.js @@ -5,6 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -export default function(jestConfig): void { +export default function (jestConfig): void { console.log(jestConfig.testPathPattern); } diff --git a/e2e/global-teardown/project-1/teardown.js b/e2e/global-teardown/project-1/teardown.js index d153236c1e7c..19482fdf686c 100644 --- a/e2e/global-teardown/project-1/teardown.js +++ b/e2e/global-teardown/project-1/teardown.js @@ -12,7 +12,7 @@ const path = require('path'); const DIR = path.join(os.tmpdir(), 'jest-global-teardown-project-1'); -module.exports = function() { +module.exports = function () { return new Promise((resolve, reject) => { createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); diff --git a/e2e/global-teardown/project-2/teardown.js b/e2e/global-teardown/project-2/teardown.js index 95eb1b32a6b0..f428e8b417a9 100644 --- a/e2e/global-teardown/project-2/teardown.js +++ b/e2e/global-teardown/project-2/teardown.js @@ -12,7 +12,7 @@ const path = require('path'); const DIR = path.join(os.tmpdir(), 'jest-global-teardown-project-2'); -module.exports = function() { +module.exports = function () { return new Promise((resolve, reject) => { createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); diff --git a/e2e/global-teardown/teardown.js b/e2e/global-teardown/teardown.js index e5c4d27a9b62..db5d6c7d3ffb 100644 --- a/e2e/global-teardown/teardown.js +++ b/e2e/global-teardown/teardown.js @@ -12,7 +12,7 @@ const path = require('path'); const DIR = path.join(os.tmpdir(), 'jest-global-teardown'); -module.exports = function() { +module.exports = function () { return new Promise((resolve, reject) => { createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); diff --git a/e2e/global-teardown/teardownWithConfig.js b/e2e/global-teardown/teardownWithConfig.js index 139a863fea39..78e2b910c082 100644 --- a/e2e/global-teardown/teardownWithConfig.js +++ b/e2e/global-teardown/teardownWithConfig.js @@ -5,6 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -module.exports = function(jestConfig) { +module.exports = function (jestConfig) { console.log(jestConfig.testPathPattern); }; diff --git a/e2e/global-teardown/teardownWithDefaultExport.js b/e2e/global-teardown/teardownWithDefaultExport.js index f60cfc524bf4..ea8cd34e38c1 100644 --- a/e2e/global-teardown/teardownWithDefaultExport.js +++ b/e2e/global-teardown/teardownWithDefaultExport.js @@ -5,6 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -export default function(jestConfig): void { +export default function (jestConfig): void { console.log(jestConfig.testPathPattern); } diff --git a/e2e/jasmine-async/__tests__/generator.test.js b/e2e/jasmine-async/__tests__/generator.test.js index e4e4589c1a6e..56e2cafbc7cd 100644 --- a/e2e/jasmine-async/__tests__/generator.test.js +++ b/e2e/jasmine-async/__tests__/generator.test.js @@ -12,12 +12,12 @@ function* someFunc() { } describe('generators', () => { - beforeEach(function*() { + beforeEach(function* () { // This shouldn't throw yield someFunc(); }); - it('in spec', function*() { + it('in spec', function* () { const data = yield someFunc(); expect(data).toBe(3); diff --git a/e2e/json-reporter/sum.js b/e2e/json-reporter/sum.js index 9daa67524231..6e9d947501ec 100644 --- a/e2e/json-reporter/sum.js +++ b/e2e/json-reporter/sum.js @@ -5,6 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -module.exports = function(a, b) { +module.exports = function (a, b) { return a + b; }; diff --git a/e2e/override-globals/index.js b/e2e/override-globals/index.js index f7a1c8f975d9..561d42923a8c 100644 --- a/e2e/override-globals/index.js +++ b/e2e/override-globals/index.js @@ -5,6 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -global.Promise = function() { +global.Promise = function () { throw new Error('Booo'); }; diff --git a/e2e/runJest.ts b/e2e/runJest.ts index 7eb6c19216e5..4abdf3e0e6bc 100644 --- a/e2e/runJest.ts +++ b/e2e/runJest.ts @@ -112,7 +112,7 @@ function normalizeStdoutAndStderr( // 'success', 'startTime', 'numTotalTests', 'numTotalTestSuites', // 'numRuntimeErrorTestSuites', 'numPassedTests', 'numFailedTests', // 'numPendingTests', 'testResults' -export const json = function( +export const json = function ( dir: string, args: Array | undefined, options: RunJestOptions = {}, @@ -141,7 +141,7 @@ type ConditionFunction = (arg: StdErrAndOutString) => boolean; // Runs `jest` continously (watch mode) and allows the caller to wait for // conditions on stdout and stderr and to end the process. -export const runContinuous = function( +export const runContinuous = function ( dir: string, args?: Array, options: RunJestOptions = {}, diff --git a/e2e/runtime-internal-module-registry/__mocks__/fs.js b/e2e/runtime-internal-module-registry/__mocks__/fs.js index 72489fb7bddb..86e21919deab 100644 --- a/e2e/runtime-internal-module-registry/__mocks__/fs.js +++ b/e2e/runtime-internal-module-registry/__mocks__/fs.js @@ -17,7 +17,7 @@ function mkdirSync() { } fs.mkdirSync = mkdirSync; -fs.__wasMkdirCalled = function() { +fs.__wasMkdirCalled = function () { return mkdirWasCalled; }; diff --git a/e2e/test-results-processor/processor.js b/e2e/test-results-processor/processor.js index 4b796c66b9da..535cc405eeab 100644 --- a/e2e/test-results-processor/processor.js +++ b/e2e/test-results-processor/processor.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -module.exports = function(results) { +module.exports = function (results) { results.processed = true; return results; }; diff --git a/examples/mongodb/teardown.js b/examples/mongodb/teardown.js index 8f1b7c0a7cf1..ab260a66005a 100644 --- a/examples/mongodb/teardown.js +++ b/examples/mongodb/teardown.js @@ -5,7 +5,7 @@ const fs = require('fs'); const globalConfigPath = path.join(__dirname, 'globalConfig.json'); -module.exports = async function() { +module.exports = async function () { await global.__MONGOD__.stop(); fs.unlinkSync(globalConfigPath); diff --git a/package.json b/package.json index 2b22ff4a80fa..aa2a352ef215 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "mocha": "^7.0.0", "mock-fs": "^4.4.1", "opencollective": "^1.0.3", - "prettier": "^1.19.0", + "prettier": "^2.0.1", "progress": "^2.0.0", "promise": "^8.0.2", "realpath-native": "^2.0.0", @@ -96,6 +96,7 @@ "lint:prettier:ci": "prettier '**/*.{md,yml,yaml}' --check --ignore-path .gitignore", "postinstall": "opencollective postinstall && yarn build", "install-no-ts-build": "node ./scripts/remove-postinstall && yarn --no-progress --frozen-lockfile && node ./scripts/build", + "remove-prettier-dep": "node ./scripts/remove-prettier-dep", "publish": "yarn build-clean && yarn build && lerna publish --silent", "test-ci-es5-build-in-browser": "karma start --single-run", "test-ci": "yarn jest-coverage --color -i --config jest.config.ci.js && yarn test-leak && node ./scripts/mapCoverage.js && codecov", @@ -118,6 +119,7 @@ "proseWrap": "never", "singleQuote": true, "trailingComma": "all", + "arrowParens": "avoid", "overrides": [ { "excludeFiles": [ diff --git a/packages/diff-sequences/perf/index.js b/packages/diff-sequences/perf/index.js index 981706765259..e49bb3459a85 100644 --- a/packages/diff-sequences/perf/index.js +++ b/packages/diff-sequences/perf/index.js @@ -39,7 +39,7 @@ const testBaseline = (a, b) => { return benchmark.stats; }; -const testImproved = function(a, b) { +const testImproved = function (a, b) { const benchmark = new Benchmark({ fn() { // Split string arguments to make fair comparison with baseline. diff --git a/packages/expect/src/__tests__/asymmetricMatchers.test.ts b/packages/expect/src/__tests__/asymmetricMatchers.test.ts index 71fdbe66ded1..b45e4c23d0b4 100644 --- a/packages/expect/src/__tests__/asymmetricMatchers.test.ts +++ b/packages/expect/src/__tests__/asymmetricMatchers.test.ts @@ -47,7 +47,7 @@ test('Any.toAsymmetricMatcher() with function name', () => { ['$someFunc', function $someFunc() {}], [ '$someFunc2', - (function() { + (function () { function $someFunc2() {} Object.defineProperty($someFunc2, 'name', {value: ''}); return $someFunc2; @@ -55,7 +55,7 @@ test('Any.toAsymmetricMatcher() with function name', () => { ], [ '$someAsyncFunc', - (function() { + (function () { async function $someAsyncFunc() {} Object.defineProperty($someAsyncFunc, 'name', {value: ''}); return $someAsyncFunc; @@ -63,7 +63,7 @@ test('Any.toAsymmetricMatcher() with function name', () => { ], [ '$someGeneratorFunc', - (function() { + (function () { function* $someGeneratorFunc() {} Object.defineProperty($someGeneratorFunc, 'name', {value: ''}); return $someGeneratorFunc; @@ -71,7 +71,7 @@ test('Any.toAsymmetricMatcher() with function name', () => { ], [ '$someFuncWithFakeToString', - (function() { + (function () { function $someFuncWithFakeToString() {} $someFuncWithFakeToString.toString = () => 'Fake to string'; return $someFuncWithFakeToString; diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 0b9695e00d9d..7bb6676b2b24 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -478,12 +478,8 @@ describe('.toEqual()', () => { [Immutable.Map({a: 0}), Immutable.Map({b: 0})], [Immutable.Map({v: 1}), Immutable.Map({v: 2})], [ - Immutable.OrderedMap() - .set(1, 'one') - .set(2, 'two'), - Immutable.OrderedMap() - .set(2, 'two') - .set(1, 'one'), + Immutable.OrderedMap().set(1, 'one').set(2, 'two'), + Immutable.OrderedMap().set(2, 'two').set(1, 'one'), ], [ Immutable.Map({1: Immutable.Map({2: {a: 99}})}), @@ -674,28 +670,16 @@ describe('.toEqual()', () => { ], [Immutable.Map(), Immutable.Map()], [ - Immutable.Map() - .set(1, 'one') - .set(2, 'two'), - Immutable.Map() - .set(1, 'one') - .set(2, 'two'), + Immutable.Map().set(1, 'one').set(2, 'two'), + Immutable.Map().set(1, 'one').set(2, 'two'), ], [ - Immutable.Map() - .set(1, 'one') - .set(2, 'two'), - Immutable.Map() - .set(2, 'two') - .set(1, 'one'), + Immutable.Map().set(1, 'one').set(2, 'two'), + Immutable.Map().set(2, 'two').set(1, 'one'), ], [ - Immutable.OrderedMap() - .set(1, 'one') - .set(2, 'two'), - Immutable.OrderedMap() - .set(1, 'one') - .set(2, 'two'), + Immutable.OrderedMap().set(1, 'one').set(2, 'two'), + Immutable.OrderedMap().set(1, 'one').set(2, 'two'), ], [ Immutable.Map({1: Immutable.Map({2: {a: 99}})}), @@ -941,7 +925,7 @@ describe('.toBeInstanceOf()', () => { [Object.create(null), A], [undefined, String], [null, String], - [/\w+/, function() {}], + [/\w+/, function () {}], [new DefinesNameProp(), RegExp], ].forEach(([a, b]) => { test(`failing ${stringify(a)} and ${stringify(b)}`, () => { @@ -1761,7 +1745,7 @@ describe('.toHaveProperty()', () => { } E.prototype.nodeType = 1; - const memoized = function() {}; + const memoized = function () {}; memoized.memo = []; const pathDiff = ['children', 0]; diff --git a/packages/expect/src/__tests__/spyMatchers.test.js b/packages/expect/src/__tests__/spyMatchers.test.js index 000273a46cec..1c3a5c956e65 100644 --- a/packages/expect/src/__tests__/spyMatchers.test.js +++ b/packages/expect/src/__tests__/spyMatchers.test.js @@ -13,7 +13,7 @@ expect.addSnapshotSerializer(alignedAnsiStyleSerializer); // Given a Jest mock function, return a minimal mock of a Jasmine spy. const createSpy = fn => { - const spy = function() {}; + const spy = function () {}; spy.calls = { all() { @@ -177,7 +177,7 @@ const createSpy = fn => { 'toBeCalledWith', 'toHaveBeenCalledWith', ].forEach(calledWith => { - const caller = function(callee, ...args) { + const caller = function (callee, ...args) { if ( calledWith === 'nthCalledWith' || calledWith === 'toHaveBeenNthCalledWith' @@ -734,7 +734,7 @@ const createSpy = fn => { 'toReturnWith', 'toHaveReturnedWith', ].forEach(returnedWith => { - const caller = function(callee, ...args) { + const caller = function (callee, ...args) { if ( returnedWith === 'nthReturnedWith' || returnedWith === 'toHaveNthReturnedWith' diff --git a/packages/expect/src/index.ts b/packages/expect/src/index.ts index a99fa819d0e3..8daf40d81926 100644 --- a/packages/expect/src/index.ts +++ b/packages/expect/src/index.ts @@ -57,10 +57,10 @@ const isPromise = (obj: any): obj is PromiseLike => (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; -const createToThrowErrorMatchingSnapshotMatcher = function( +const createToThrowErrorMatchingSnapshotMatcher = function ( matcher: RawMatcherFn, ) { - return function( + return function ( this: JestMatcherState, received: any, testNameOrInlineSnapshot?: string, diff --git a/packages/expect/src/spyMatchers.ts b/packages/expect/src/spyMatchers.ts index 6a2b116ea4f7..f2ebfbc33e1f 100644 --- a/packages/expect/src/spyMatchers.ts +++ b/packages/expect/src/spyMatchers.ts @@ -170,12 +170,7 @@ const printExpectedReceivedCallsPositive = ( difference.includes('+ Received') ) { // Omit annotation in case multiple args have diff. - lines.push( - difference - .split('\n') - .slice(3) - .join('\n') + ',', - ); + lines.push(difference.split('\n').slice(3).join('\n') + ','); continue; } } @@ -357,7 +352,7 @@ const printReceivedResults = ( }; const createToBeCalledMatcher = (matcherName: string) => - function( + function ( this: MatcherState, received: any, expected: unknown, @@ -404,7 +399,7 @@ const createToBeCalledMatcher = (matcherName: string) => }; const createToReturnMatcher = (matcherName: string) => - function( + function ( this: MatcherState, received: any, expected: unknown, @@ -462,7 +457,7 @@ const createToReturnMatcher = (matcherName: string) => }; const createToBeCalledTimesMatcher = (matcherName: string) => - function( + function ( this: MatcherState, received: any, expected: number, @@ -498,7 +493,7 @@ const createToBeCalledTimesMatcher = (matcherName: string) => }; const createToReturnTimesMatcher = (matcherName: string) => - function( + function ( this: MatcherState, received: any, expected: number, @@ -546,7 +541,7 @@ const createToReturnTimesMatcher = (matcherName: string) => }; const createToBeCalledWithMatcher = (matcherName: string) => - function( + function ( this: MatcherState, received: any, ...expected: Array @@ -619,7 +614,7 @@ const createToBeCalledWithMatcher = (matcherName: string) => }; const createToReturnWithMatcher = (matcherName: string) => - function( + function ( this: MatcherState, received: any, expected: unknown, @@ -692,7 +687,7 @@ const createToReturnWithMatcher = (matcherName: string) => }; const createLastCalledWithMatcher = (matcherName: string) => - function( + function ( this: MatcherState, received: any, ...expected: Array @@ -775,7 +770,7 @@ const createLastCalledWithMatcher = (matcherName: string) => }; const createLastReturnedMatcher = (matcherName: string) => - function( + function ( this: MatcherState, received: any, expected: unknown, @@ -859,7 +854,7 @@ const createLastReturnedMatcher = (matcherName: string) => }; const createNthCalledWithMatcher = (matcherName: string) => - function( + function ( this: MatcherState, received: any, nth: number, @@ -989,7 +984,7 @@ const createNthCalledWithMatcher = (matcherName: string) => }; const createNthReturnedWithMatcher = (matcherName: string) => - function( + function ( this: MatcherState, received: any, nth: number, diff --git a/packages/expect/src/toThrowMatchers.ts b/packages/expect/src/toThrowMatchers.ts index 2c586f1dc922..8a018f3298b9 100644 --- a/packages/expect/src/toThrowMatchers.ts +++ b/packages/expect/src/toThrowMatchers.ts @@ -77,7 +77,7 @@ export const createMatcher = ( fromPromise?: boolean, ): RawMatcherFn => // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types - function( + function ( this: MatcherState, received: Function, expected: any, diff --git a/packages/jest-circus/src/__mocks__/testUtils.ts b/packages/jest-circus/src/__mocks__/testUtils.ts index 8886eb27017f..4a26fc4a2907 100644 --- a/packages/jest-circus/src/__mocks__/testUtils.ts +++ b/packages/jest-circus/src/__mocks__/testUtils.ts @@ -27,9 +27,7 @@ interface Result extends ExecaSyncReturnValue { } export const runTest = (source: string) => { - const filename = createHash('md5') - .update(source) - .digest('hex'); + const filename = createHash('md5').update(source).digest('hex'); const tmpFilename = path.join(tmpdir(), filename); const content = ` diff --git a/packages/jest-config/src/ReporterValidationErrors.ts b/packages/jest-config/src/ReporterValidationErrors.ts index 3726cc524c92..65d3b57b41ff 100644 --- a/packages/jest-config/src/ReporterValidationErrors.ts +++ b/packages/jest-config/src/ReporterValidationErrors.ts @@ -52,9 +52,7 @@ export function createArrayReporterError( ` ${chalk.bold.green(getType(value))}\n` + ` Reporter configuration:\n` + ` ${chalk.bold.green( - JSON.stringify(arrayReporter, null, 2) - .split('\n') - .join('\n '), + JSON.stringify(arrayReporter, null, 2).split('\n').join('\n '), )}`; return new ValidationError(ERROR, errorMessage, DOCUMENTATION_NOTE); diff --git a/packages/jest-core/src/__tests__/watch.test.js b/packages/jest-core/src/__tests__/watch.test.js index 84e55a43dee0..af2dea274d7a 100644 --- a/packages/jest-core/src/__tests__/watch.test.js +++ b/packages/jest-core/src/__tests__/watch.test.js @@ -46,7 +46,7 @@ jest.doMock('chalk', () => new chalk.Instance({level: 0})); jest.doMock( '../runJest', () => - function() { + function () { const args = Array.from(arguments); const [{onComplete}] = args; runJestMock.apply(null, args); diff --git a/packages/jest-core/src/__tests__/watch_filename_pattern_mode.test.js b/packages/jest-core/src/__tests__/watch_filename_pattern_mode.test.js index 30374f5e2623..e06be7b17b9e 100644 --- a/packages/jest-core/src/__tests__/watch_filename_pattern_mode.test.js +++ b/packages/jest-core/src/__tests__/watch_filename_pattern_mode.test.js @@ -72,7 +72,7 @@ require('strip-ansi').mockImplementation(str => str); jest.doMock( '../runJest', () => - function() { + function () { const args = Array.from(arguments); const [{onComplete}] = args; runJestMock.apply(null, args); diff --git a/packages/jest-core/src/__tests__/watch_test_name_pattern_mode.test.js b/packages/jest-core/src/__tests__/watch_test_name_pattern_mode.test.js index bfaa38f6b13f..7926af101eef 100644 --- a/packages/jest-core/src/__tests__/watch_test_name_pattern_mode.test.js +++ b/packages/jest-core/src/__tests__/watch_test_name_pattern_mode.test.js @@ -48,7 +48,7 @@ require('strip-ansi').mockImplementation(str => str); jest.doMock( '../runJest', () => - function() { + function () { const args = Array.from(arguments); const [{onComplete}] = args; runJestMock.apply(null, args); diff --git a/packages/jest-each/src/__tests__/array.test.ts b/packages/jest-each/src/__tests__/array.test.ts index 5bdac1756f91..666e7aece2ec 100644 --- a/packages/jest-each/src/__tests__/array.test.ts +++ b/packages/jest-each/src/__tests__/array.test.ts @@ -314,7 +314,7 @@ describe('jest-each', () => { const eachObject = each.withGlobal(globalTestMocks)([['hello']]); const testFunction = get(eachObject, keyPath); - testFunction('expected string', function(hello, done) { + testFunction('expected string', function (hello, done) { expect(hello).toBe('hello'); expect(arguments.length).toBe(1); expect(done).toBe(undefined); diff --git a/packages/jest-each/src/__tests__/template.test.ts b/packages/jest-each/src/__tests__/template.test.ts index 7518ee153a79..7952d90fcc5f 100644 --- a/packages/jest-each/src/__tests__/template.test.ts +++ b/packages/jest-each/src/__tests__/template.test.ts @@ -346,7 +346,7 @@ describe('jest-each', () => { ${0} | ${1} | ${1} `; const testFunction = get(eachObject, keyPath); - testFunction('expected string', function({a, b, expected}, done) { + testFunction('expected string', function ({a, b, expected}, done) { expect(a).toBe(0); expect(b).toBe(1); expect(expected).toBe(1); diff --git a/packages/jest-environment-jsdom/src/__mocks__/index.ts b/packages/jest-environment-jsdom/src/__mocks__/index.ts index b528bc840c64..b6f34c08f441 100644 --- a/packages/jest-environment-jsdom/src/__mocks__/index.ts +++ b/packages/jest-environment-jsdom/src/__mocks__/index.ts @@ -10,7 +10,7 @@ const vm = jest.requireActual('vm'); const JSDOMEnvironment = jest.genMockFromModule('../index') as jest.Mock; -JSDOMEnvironment.mockImplementation(function(config) { +JSDOMEnvironment.mockImplementation(function (config) { // @ts-ignore this.global = { JSON, @@ -24,7 +24,7 @@ JSDOMEnvironment.mockImplementation(function(config) { } }); -JSDOMEnvironment.prototype.runSourceText.mockImplementation(function( +JSDOMEnvironment.prototype.runSourceText.mockImplementation(function ( sourceText: string, filename: string, ) { diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index 8a66d54f05b6..36378df6b9f7 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -65,7 +65,7 @@ class JSDOMEnvironment implements JestEnvironment { const originalAddListener = global.addEventListener; const originalRemoveListener = global.removeEventListener; let userErrorListenerCount = 0; - global.addEventListener = function( + global.addEventListener = function ( ...args: Parameters ) { if (args[0] === 'error') { @@ -73,7 +73,7 @@ class JSDOMEnvironment implements JestEnvironment { } return originalAddListener.apply(this, args); }; - global.removeEventListener = function( + global.removeEventListener = function ( ...args: Parameters ) { if (args[0] === 'error') { diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index a24f9c3bddbf..7a80f97bb934 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -10,10 +10,7 @@ import crypto from 'crypto'; import {skipSuiteOnWindows} from '@jest/test-utils'; function mockHashContents(contents) { - return crypto - .createHash('sha1') - .update(contents) - .digest('hex'); + return crypto.createHash('sha1').update(contents).digest('hex'); } jest.mock('child_process', () => ({ diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 1faf0b5ae591..0db77ea12dbb 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -281,9 +281,7 @@ class HasteMap extends EventEmitter { ); } - const rootDirHash = createHash('md5') - .update(options.rootDir) - .digest('hex'); + const rootDirHash = createHash('md5').update(options.rootDir).digest('hex'); let hasteImplHash = ''; let dependencyExtractorHash = ''; diff --git a/packages/jest-haste-map/src/lib/WatchmanWatcher.js b/packages/jest-haste-map/src/lib/WatchmanWatcher.js index af0f49c45abd..adce679cdf08 100644 --- a/packages/jest-haste-map/src/lib/WatchmanWatcher.js +++ b/packages/jest-haste-map/src/lib/WatchmanWatcher.js @@ -43,7 +43,7 @@ WatchmanWatcher.prototype.__proto__ = EventEmitter.prototype; * @private */ -WatchmanWatcher.prototype.init = function() { +WatchmanWatcher.prototype.init = function () { if (this.client) { this.client.removeAllListeners(); } @@ -187,7 +187,7 @@ WatchmanWatcher.prototype.init = function() { * @private */ -WatchmanWatcher.prototype.handleChangeEvent = function(resp) { +WatchmanWatcher.prototype.handleChangeEvent = function (resp) { assert.equal(resp.subscription, SUB_NAME, 'Invalid subscription event.'); if (resp.is_fresh_instance) { this.emit('fresh_instance'); @@ -207,7 +207,7 @@ WatchmanWatcher.prototype.handleChangeEvent = function(resp) { * @private */ -WatchmanWatcher.prototype.handleFileChange = function(changeDescriptor) { +WatchmanWatcher.prototype.handleFileChange = function (changeDescriptor) { const self = this; let absPath; let relativePath; @@ -265,7 +265,7 @@ WatchmanWatcher.prototype.handleFileChange = function(changeDescriptor) { * @private */ -WatchmanWatcher.prototype.emitEvent = function( +WatchmanWatcher.prototype.emitEvent = function ( eventType, filepath, root, @@ -282,7 +282,7 @@ WatchmanWatcher.prototype.emitEvent = function( * @private */ -WatchmanWatcher.prototype.close = function(callback) { +WatchmanWatcher.prototype.close = function (callback) { this.client.removeAllListeners(); this.client.end(); callback && callback(null, true); diff --git a/packages/jest-haste-map/src/worker.ts b/packages/jest-haste-map/src/worker.ts index abc235841e35..236160fac927 100644 --- a/packages/jest-haste-map/src/worker.ts +++ b/packages/jest-haste-map/src/worker.ts @@ -19,9 +19,7 @@ let hasteImpl: HasteImpl | null = null; let hasteImplModulePath: string | null = null; function sha1hex(content: string | Buffer): string { - return createHash('sha1') - .update(content) - .digest('hex'); + return createHash('sha1').update(content).digest('hex'); } export async function worker(data: WorkerMessage): Promise { diff --git a/packages/jest-jasmine2/src/PCancelable.js b/packages/jest-jasmine2/src/PCancelable.js index f5a488ec0efb..8b3bc3c71629 100644 --- a/packages/jest-jasmine2/src/PCancelable.js +++ b/packages/jest-jasmine2/src/PCancelable.js @@ -16,7 +16,7 @@ class CancelError extends Error { class PCancelable { static fn(fn) { - return function() { + return function () { const args = [].slice.apply(arguments); return new PCancelable((onCancel, resolve, reject) => { args.unshift(onCancel); diff --git a/packages/jest-jasmine2/src/jasmine/CallTracker.ts b/packages/jest-jasmine2/src/jasmine/CallTracker.ts index 02a0b767ffdf..1fc2dc25d8ef 100644 --- a/packages/jest-jasmine2/src/jasmine/CallTracker.ts +++ b/packages/jest-jasmine2/src/jasmine/CallTracker.ts @@ -49,28 +49,28 @@ class CallTracker { constructor() { let calls: Array = []; - this.track = function(context: Context) { + this.track = function (context: Context) { calls.push(context); }; - this.any = function() { + this.any = function () { return !!calls.length; }; - this.count = function() { + this.count = function () { return calls.length; }; - this.argsFor = function(index) { + this.argsFor = function (index) { const call = calls[index]; return call ? call.args : []; }; - this.all = function() { + this.all = function () { return calls; }; - this.allArgs = function() { + this.allArgs = function () { const callArgs = []; for (let i = 0; i < calls.length; i++) { callArgs.push(calls[i].args); @@ -79,15 +79,15 @@ class CallTracker { return callArgs; }; - this.first = function() { + this.first = function () { return calls[0]; }; - this.mostRecent = function() { + this.mostRecent = function () { return calls[calls.length - 1]; }; - this.reset = function() { + this.reset = function () { calls = []; }; } diff --git a/packages/jest-jasmine2/src/jasmine/Env.ts b/packages/jest-jasmine2/src/jasmine/Env.ts index 9c47b20f9c2e..0056423e08ed 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.ts +++ b/packages/jest-jasmine2/src/jasmine/Env.ts @@ -45,7 +45,7 @@ import {AssertionErrorWithStack, Jasmine, Reporter, Spy} from '../types'; import Spec, {SpecResult} from './Spec'; import Suite from './Suite'; -export default function(j$: Jasmine) { +export default function (j$: Jasmine) { return class Env { specFilter: (spec: Spec) => boolean; catchExceptions: (value: unknown) => boolean; @@ -103,11 +103,11 @@ export default function(j$: Jasmine) { let nextSpecId = 0; let nextSuiteId = 0; - const getNextSpecId = function() { + const getNextSpecId = function () { return 'spec' + nextSpecId++; }; - const getNextSuiteId = function() { + const getNextSuiteId = function () { return 'suite' + nextSuiteId++; }; @@ -120,11 +120,11 @@ export default function(j$: Jasmine) { }); let currentDeclarationSuite = topSuite; - const currentSuite = function() { + const currentSuite = function () { return currentlyExecutingSuites[currentlyExecutingSuites.length - 1]; }; - const currentRunnable = function() { + const currentRunnable = function () { return currentSpec || currentSuite(); }; @@ -137,11 +137,11 @@ export default function(j$: Jasmine) { 'specDone', ]); - this.specFilter = function() { + this.specFilter = function () { return true; }; - const defaultResourcesForRunnable = function( + const defaultResourcesForRunnable = function ( id: string, _parentRunnableId?: string, ) { @@ -150,13 +150,13 @@ export default function(j$: Jasmine) { runnableResources[id] = resources; }; - const clearResourcesForRunnable = function(id: string) { + const clearResourcesForRunnable = function (id: string) { spyRegistry.clearSpies(); delete runnableResources[id]; }; - const beforeAndAfterFns = function(suite: Suite) { - return function() { + const beforeAndAfterFns = function (suite: Suite) { + return function () { let afters: Array = []; let befores: Array = []; @@ -174,7 +174,7 @@ export default function(j$: Jasmine) { }; }; - const getSpecName = function(spec: Spec, suite: Suite) { + const getSpecName = function (spec: Spec, suite: Suite) { const fullName = [spec.description]; const suiteFullName = suite.getFullName(); @@ -185,32 +185,32 @@ export default function(j$: Jasmine) { return fullName.join(' '); }; - this.catchExceptions = function(value) { + this.catchExceptions = function (value) { catchExceptions = !!value; return catchExceptions; }; - this.catchingExceptions = function() { + this.catchingExceptions = function () { return catchExceptions; }; - this.throwOnExpectationFailure = function(value) { + this.throwOnExpectationFailure = function (value) { throwOnExpectationFailure = !!value; }; - this.throwingExpectationFailures = function() { + this.throwingExpectationFailures = function () { return throwOnExpectationFailure; }; - this.randomizeTests = function(value) { + this.randomizeTests = function (value) { random = !!value; }; - this.randomTests = function() { + this.randomTests = function () { return random; }; - this.seed = function(value) { + this.seed = function (value) { if (value) { seed = value; } @@ -224,7 +224,7 @@ export default function(j$: Jasmine) { return queueRunner(options); }; - this.topSuite = function() { + this.topSuite = function () { return topSuite; }; @@ -241,7 +241,7 @@ export default function(j$: Jasmine) { let oldListenersException: Array; let oldListenersRejection: Array; - const executionSetup = function() { + const executionSetup = function () { // Need to ensure we are the only ones handling these exceptions. oldListenersException = process.listeners('uncaughtException').slice(); oldListenersRejection = process.listeners('unhandledRejection').slice(); @@ -253,7 +253,7 @@ export default function(j$: Jasmine) { j$.process.on('unhandledRejection', uncaught); }; - const executionTeardown = function() { + const executionTeardown = function () { j$.process.removeListener('uncaughtException', uncaught); j$.process.removeListener('unhandledRejection', uncaught); @@ -267,7 +267,7 @@ export default function(j$: Jasmine) { }); }; - this.execute = async function(runnablesToRun, suiteTree = topSuite) { + this.execute = async function (runnablesToRun, suiteTree = topSuite) { if (!runnablesToRun) { if (focusedRunnables.length) { runnablesToRun = focusedRunnables; @@ -320,15 +320,15 @@ export default function(j$: Jasmine) { } }; - this.addReporter = function(reporterToAdd) { + this.addReporter = function (reporterToAdd) { reporter.addReporter(reporterToAdd); }; - this.provideFallbackReporter = function(reporterToAdd) { + this.provideFallbackReporter = function (reporterToAdd) { reporter.provideFallbackReporter(reporterToAdd); }; - this.clearReporters = function() { + this.clearReporters = function () { reporter.clearReporters(); }; @@ -343,15 +343,15 @@ export default function(j$: Jasmine) { }, }); - this.allowRespy = function(allow) { + this.allowRespy = function (allow) { spyRegistry.allowRespy(allow); }; - this.spyOn = function(...args) { + this.spyOn = function (...args) { return spyRegistry.spyOn.apply(spyRegistry, args); }; - const suiteFactory = function(description: string) { + const suiteFactory = function (description: string) { const suite = new j$.Suite({ id: getNextSuiteId(), description, @@ -365,7 +365,7 @@ export default function(j$: Jasmine) { return suite; }; - this.describe = function(description: string, specDefinitions) { + this.describe = function (description: string, specDefinitions) { const suite = suiteFactory(description); if (specDefinitions === undefined) { throw new Error( @@ -391,7 +391,7 @@ export default function(j$: Jasmine) { return suite; }; - this.xdescribe = function(description, specDefinitions) { + this.xdescribe = function (description, specDefinitions) { const suite = suiteFactory(description); suite.pend(); addSpecsToSuite(suite, specDefinitions); @@ -400,7 +400,7 @@ export default function(j$: Jasmine) { const focusedRunnables: Array = []; - this.fdescribe = function(description, specDefinitions) { + this.fdescribe = function (description, specDefinitions) { const suite = suiteFactory(description); suite.isFocused = true; @@ -536,7 +536,7 @@ export default function(j$: Jasmine) { } }; - this.it = function(description, fn, timeout) { + this.it = function (description, fn, timeout) { if (typeof description !== 'string') { throw new Error( `Invalid first argument, ${description}. It must be a string.`, @@ -577,13 +577,13 @@ export default function(j$: Jasmine) { return spec; }; - this.xit = function(...args) { + this.xit = function (...args) { const spec = this.it.apply(this, args); spec.pend('Temporarily disabled with xit'); return spec; }; - this.todo = function() { + this.todo = function () { const description = arguments[0]; if (arguments.length !== 1 || typeof description !== 'string') { throw new ErrorWithStack( @@ -602,7 +602,7 @@ export default function(j$: Jasmine) { return spec; }; - this.fit = function(description, fn, timeout) { + this.fit = function (description, fn, timeout) { const spec = specFactory( description, fn, @@ -615,7 +615,7 @@ export default function(j$: Jasmine) { return spec; }; - this.beforeEach = function(beforeEachFunction, timeout) { + this.beforeEach = function (beforeEachFunction, timeout) { currentDeclarationSuite.beforeEach({ fn: beforeEachFunction, timeout() { @@ -624,7 +624,7 @@ export default function(j$: Jasmine) { }); }; - this.beforeAll = function(beforeAllFunction, timeout) { + this.beforeAll = function (beforeAllFunction, timeout) { currentDeclarationSuite.beforeAll({ fn: beforeAllFunction, timeout() { @@ -633,7 +633,7 @@ export default function(j$: Jasmine) { }); }; - this.afterEach = function(afterEachFunction, timeout) { + this.afterEach = function (afterEachFunction, timeout) { currentDeclarationSuite.afterEach({ fn: afterEachFunction, timeout() { @@ -642,7 +642,7 @@ export default function(j$: Jasmine) { }); }; - this.afterAll = function(afterAllFunction, timeout) { + this.afterAll = function (afterAllFunction, timeout) { currentDeclarationSuite.afterAll({ fn: afterAllFunction, timeout() { @@ -651,7 +651,7 @@ export default function(j$: Jasmine) { }); }; - this.pending = function(message) { + this.pending = function (message) { let fullMessage = j$.Spec.pendingSpecExceptionMessage; if (message) { fullMessage += message; @@ -659,7 +659,7 @@ export default function(j$: Jasmine) { throw fullMessage; }; - this.fail = function(error) { + this.fail = function (error) { let checkIsError; let message; diff --git a/packages/jest-jasmine2/src/jasmine/JsApiReporter.ts b/packages/jest-jasmine2/src/jasmine/JsApiReporter.ts index 0d233744f6de..4152837052dd 100644 --- a/packages/jest-jasmine2/src/jasmine/JsApiReporter.ts +++ b/packages/jest-jasmine2/src/jasmine/JsApiReporter.ts @@ -82,7 +82,7 @@ export default class JsApiReporter implements Reporter { } } - this.jasmineDone = function(runDetails) { + this.jasmineDone = function (runDetails) { validateAfterAllExceptions(runDetails); this.finished = true; this.runDetails = runDetails; @@ -90,24 +90,24 @@ export default class JsApiReporter implements Reporter { status = 'done'; }; - this.status = function() { + this.status = function () { return status; }; const suites: Array = []; const suites_hash: Record = {}; - this.specStarted = function() {}; + this.specStarted = function () {}; - this.suiteStarted = function(result: SuiteResult) { + this.suiteStarted = function (result: SuiteResult) { suites_hash[result.id] = result; }; - this.suiteDone = function(result: SuiteResult) { + this.suiteDone = function (result: SuiteResult) { storeSuite(result); }; - this.suiteResults = function(index, length) { + this.suiteResults = function (index, length) { return suites.slice(index, index + length); }; @@ -116,25 +116,25 @@ export default class JsApiReporter implements Reporter { suites_hash[result.id] = result; } - this.suites = function() { + this.suites = function () { return suites_hash; }; const specs: Array = []; - this.specDone = function(result) { + this.specDone = function (result) { specs.push(result); }; - this.specResults = function(index, length) { + this.specResults = function (index, length) { return specs.slice(index, index + length); }; - this.specs = function() { + this.specs = function () { return specs; }; - this.executionTime = function() { + this.executionTime = function () { return executionTime; }; } diff --git a/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts b/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts index dab52c999020..6575affc2e1f 100644 --- a/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts +++ b/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts @@ -55,8 +55,8 @@ export default class ReportDispatcher implements Reporter { for (let i = 0; i < dispatchedMethods.length; i++) { const method = dispatchedMethods[i]; - this[method] = (function(m) { - return function() { + this[method] = (function (m) { + return function () { dispatch(m, arguments); }; })(method); @@ -65,15 +65,15 @@ export default class ReportDispatcher implements Reporter { let reporters: Array = []; let fallbackReporter: Reporter | null = null; - this.addReporter = function(reporter) { + this.addReporter = function (reporter) { reporters.push(reporter); }; - this.provideFallbackReporter = function(reporter) { + this.provideFallbackReporter = function (reporter) { fallbackReporter = reporter; }; - this.clearReporters = function() { + this.clearReporters = function () { reporters = []; }; diff --git a/packages/jest-jasmine2/src/jasmine/Spec.ts b/packages/jest-jasmine2/src/jasmine/Spec.ts index e22c9f885748..0ac2782acb79 100644 --- a/packages/jest-jasmine2/src/jasmine/Spec.ts +++ b/packages/jest-jasmine2/src/jasmine/Spec.ts @@ -108,27 +108,27 @@ export default class Spec { } constructor(attrs: Attributes) { - this.resultCallback = attrs.resultCallback || function() {}; + this.resultCallback = attrs.resultCallback || function () {}; this.id = attrs.id; this.description = attrs.description || ''; this.queueableFn = attrs.queueableFn; this.beforeAndAfterFns = attrs.beforeAndAfterFns || - function() { + function () { return {befores: [], afters: []}; }; this.userContext = attrs.userContext || - function() { + function () { return {}; }; - this.onStart = attrs.onStart || function() {}; + this.onStart = attrs.onStart || function () {}; this.getSpecName = attrs.getSpecName || - function() { + function () { return ''; }; - this.queueRunnerFactory = attrs.queueRunnerFactory || function() {}; + this.queueRunnerFactory = attrs.queueRunnerFactory || function () {}; this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure; this.initError = new Error(); @@ -302,7 +302,7 @@ export default class Spec { Spec.pendingSpecExceptionMessage = '=> marked Pending'; -const extractCustomPendingMessage = function(e: Error) { +const extractCustomPendingMessage = function (e: Error) { const fullMessage = e.toString(); const boilerplateStart = fullMessage.indexOf( Spec.pendingSpecExceptionMessage, diff --git a/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts b/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts index 59c2faf24c05..9d56d282d9ab 100644 --- a/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts +++ b/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts @@ -41,51 +41,51 @@ export default class SpyStrategy { constructor({ name = 'unknown', - fn = function() {}, - getSpy = function() {}, + fn = function () {}, + getSpy = function () {}, }: {name?: string; fn?: Function; getSpy?: () => unknown} = {}) { const identity = name; const originalFn = fn; - let plan: Function = function() {}; + let plan: Function = function () {}; - this.identity = function() { + this.identity = function () { return identity; }; - this.exec = function() { + this.exec = function () { return plan.apply(this, arguments); }; - this.callThrough = function() { + this.callThrough = function () { plan = originalFn; return getSpy(); }; - this.returnValue = function(value) { - plan = function() { + this.returnValue = function (value) { + plan = function () { return value; }; return getSpy(); }; - this.returnValues = function() { + this.returnValues = function () { const values = Array.prototype.slice.call(arguments); - plan = function() { + plan = function () { return values.shift(); }; return getSpy(); }; - this.throwError = function(something) { + this.throwError = function (something) { const error = something instanceof Error ? something : new Error(something); - plan = function() { + plan = function () { throw error; }; return getSpy(); }; - this.callFake = function(fn) { + this.callFake = function (fn) { if (typeof fn !== 'function') { throw new Error( 'Argument passed to callFake should be a function, got ' + fn, @@ -95,8 +95,8 @@ export default class SpyStrategy { return getSpy(); }; - this.stub = function(_fn) { - plan = function() {}; + this.stub = function (_fn) { + plan = function () {}; return getSpy(); }; } diff --git a/packages/jest-jasmine2/src/jasmine/Timer.ts b/packages/jest-jasmine2/src/jasmine/Timer.ts index fe6a8f9ec9fa..ce5a24f32762 100644 --- a/packages/jest-jasmine2/src/jasmine/Timer.ts +++ b/packages/jest-jasmine2/src/jasmine/Timer.ts @@ -29,8 +29,8 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -const defaultNow = (function(Date) { - return function() { +const defaultNow = (function (Date) { + return function () { return new Date().getTime(); }; })(Date); @@ -45,11 +45,11 @@ export default class Timer { const now = options.now || defaultNow; let startTime: number; - this.start = function() { + this.start = function () { startTime = now(); }; - this.elapsed = function() { + this.elapsed = function () { return now() - startTime; }; } diff --git a/packages/jest-jasmine2/src/jasmine/createSpy.ts b/packages/jest-jasmine2/src/jasmine/createSpy.ts index 99e531c073fa..983ccfbca45c 100644 --- a/packages/jest-jasmine2/src/jasmine/createSpy.ts +++ b/packages/jest-jasmine2/src/jasmine/createSpy.ts @@ -47,7 +47,7 @@ function createSpy(name: string, originalFn: Fn): Spy { }, }); const callTracker = new CallTracker(); - const spy: Spy = function(...args) { + const spy: Spy = function (...args) { const callData: Context = { object: this, args: Array.prototype.slice.apply(arguments), diff --git a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts index 576af1aae1f2..d28426686c02 100644 --- a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts +++ b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts @@ -40,12 +40,12 @@ import SpyRegistry from './spyRegistry'; import Suite from './Suite'; import Timer from './Timer'; -export const create = function(createOptions: Record): Jasmine { +export const create = function (createOptions: Record): Jasmine { const j$ = {...createOptions} as Jasmine; j$._DEFAULT_TIMEOUT_INTERVAL = createOptions.testTimeout || 5000; - j$.getEnv = function(options?: object) { + j$.getEnv = function (options?: object) { const env = (j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options)); //jasmine. singletons in here (setTimeout blah blah). return env; @@ -64,7 +64,7 @@ export const create = function(createOptions: Record): Jasmine { }; // Interface is a reserved word in strict mode, so can't export it as ESM -export const _interface = function(jasmine: Jasmine, env: any) { +export const _interface = function (jasmine: Jasmine, env: any) { const jasmineInterface = { describe(description: string, specDefinitions: Function) { return env.describe(description, specDefinitions); diff --git a/packages/jest-jasmine2/src/jasmine/spyRegistry.ts b/packages/jest-jasmine2/src/jasmine/spyRegistry.ts index 8934b3ce7e89..e60886b2bf7d 100644 --- a/packages/jest-jasmine2/src/jasmine/spyRegistry.ts +++ b/packages/jest-jasmine2/src/jasmine/spyRegistry.ts @@ -72,7 +72,7 @@ export default class SpyRegistry { }: { currentSpies?: () => Array; } = {}) { - this.allowRespy = function(allow) { + this.allowRespy = function (allow) { this.respy = allow; }; @@ -127,11 +127,11 @@ export default class SpyRegistry { let restoreStrategy; if (Object.prototype.hasOwnProperty.call(obj, methodName)) { - restoreStrategy = function() { + restoreStrategy = function () { obj[methodName] = originalMethod; }; } else { - restoreStrategy = function() { + restoreStrategy = function () { if (!delete obj[methodName]) { obj[methodName] = originalMethod; } @@ -147,7 +147,7 @@ export default class SpyRegistry { return spiedMethod; }; - this._spyOnProperty = function(obj, propertyName, accessType = 'get') { + this._spyOnProperty = function (obj, propertyName, accessType = 'get') { if (!obj) { throw new Error( getErrorMsg( @@ -203,11 +203,11 @@ export default class SpyRegistry { let restoreStrategy; if (Object.prototype.hasOwnProperty.call(obj, propertyName)) { - restoreStrategy = function() { + restoreStrategy = function () { Object.defineProperty(obj, propertyName, originalDescriptor); }; } else { - restoreStrategy = function() { + restoreStrategy = function () { delete obj[propertyName]; }; } @@ -223,7 +223,7 @@ export default class SpyRegistry { return spiedProperty; }; - this.clearSpies = function() { + this.clearSpies = function () { const spies = currentSpies(); for (let i = spies.length - 1; i >= 0; i--) { const spyEntry = spies[i]; diff --git a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts index a4409251e906..ee46213b41b9 100644 --- a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts +++ b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts @@ -32,7 +32,7 @@ function promisifyLifeCycleFunction( originalFn: Function, env: Jasmine['currentEnv_'], ) { - return function( + return function ( fn: Function | (() => Promise) | GeneratorFunction | undefined, timeout?: number, ) { @@ -57,7 +57,7 @@ function promisifyLifeCycleFunction( // We make *all* functions async and run `done` right away if they // didn't return a promise. - const asyncJestLifecycle = function(done: DoneFn) { + const asyncJestLifecycle = function (done: DoneFn) { const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn; const returnValue = wrappedFn.call({}); @@ -86,7 +86,7 @@ function promisifyIt( env: Jasmine['currentEnv_'], jasmine: Jasmine, ) { - return function(specName: string, fn: Function, timeout?: number) { + return function (specName: string, fn: Function, timeout?: number) { if (!fn) { const spec = originalFn.call(env, specName); spec.pend('not implemented'); @@ -107,7 +107,7 @@ function promisifyIt( // https://crbug.com/v8/7142 extraError.stack = extraError.stack; - const asyncJestTest = function(done: DoneFn) { + const asyncJestTest = function (done: DoneFn) { const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn; const returnValue = wrappedFn.call({}); @@ -150,7 +150,7 @@ function makeConcurrent( env: Jasmine['currentEnv_'], mutex: ReturnType, ): Global.ItConcurrentBase { - return function(specName, fn, timeout) { + return function (specName, fn, timeout) { let promise: Promise = Promise.resolve(); const spec = originalFn.call(env, specName, () => promise, timeout); diff --git a/packages/jest-jasmine2/src/jestExpect.ts b/packages/jest-jasmine2/src/jestExpect.ts index 39dd471f859c..d80e45adbd94 100644 --- a/packages/jest-jasmine2/src/jestExpect.ts +++ b/packages/jest-jasmine2/src/jestExpect.ts @@ -47,7 +47,7 @@ export default (config: {expand: boolean}): void => { jasmine.addMatchers = (jasmineMatchersObject: JasmineMatchersObject) => { const jestMatchersObject = Object.create(null); Object.keys(jasmineMatchersObject).forEach(name => { - jestMatchersObject[name] = function( + jestMatchersObject[name] = function ( this: expect.MatcherState, ...args: Array ): RawMatcherFn { diff --git a/packages/jest-jasmine2/src/queueRunner.ts b/packages/jest-jasmine2/src/queueRunner.ts index dae635009722..c20c6d601cbb 100644 --- a/packages/jest-jasmine2/src/queueRunner.ts +++ b/packages/jest-jasmine2/src/queueRunner.ts @@ -35,7 +35,7 @@ export default function queueRunner(options: Options) { const mapper = ({fn, timeout, initError = new Error()}: QueueableFn) => { let promise = new Promise(resolve => { - const next = function(...args: [Error]) { + const next = function (...args: [Error]) { const err = args[0]; if (err) { options.fail.apply(null, args); @@ -43,7 +43,7 @@ export default function queueRunner(options: Options) { resolve(); }; - next.fail = function(...args: [Error]) { + next.fail = function (...args: [Error]) { options.fail.apply(null, args); resolve(); }; diff --git a/packages/jest-jasmine2/src/setup_jest_globals.ts b/packages/jest-jasmine2/src/setup_jest_globals.ts index 30dd5559640a..de65e50f5949 100644 --- a/packages/jest-jasmine2/src/setup_jest_globals.ts +++ b/packages/jest-jasmine2/src/setup_jest_globals.ts @@ -67,7 +67,7 @@ const patchJasmine = () => { class Spec extends realSpec { constructor(attr: Attributes) { const resultCallback = attr.resultCallback; - attr.resultCallback = function(result: SpecResult) { + attr.resultCallback = function (result: SpecResult) { addSuppressedErrors(result); addAssertionErrors(result); resultCallback.call(attr, result); diff --git a/packages/jest-leak-detector/README.md b/packages/jest-leak-detector/README.md index c1e060c28eb9..5e650b732f49 100644 --- a/packages/jest-leak-detector/README.md +++ b/packages/jest-leak-detector/README.md @@ -7,7 +7,7 @@ Internally creates a weak reference to the object, and forces garbage collection ## Example ```javascript -(async function() { +(async function () { let reference = {}; let isLeaking; diff --git a/packages/jest-leak-detector/src/__tests__/index.test.ts b/packages/jest-leak-detector/src/__tests__/index.test.ts index 5c2cc780064f..1d8f0c6f0896 100644 --- a/packages/jest-leak-detector/src/__tests__/index.test.ts +++ b/packages/jest-leak-detector/src/__tests__/index.test.ts @@ -65,7 +65,7 @@ it('correctly checks simple leaks', async () => { it('tests different objects', async () => { const refs = [ - function() {}, + function () {}, () => {}, Object.create(null), [], diff --git a/packages/jest-mock/src/__tests__/index.test.ts b/packages/jest-mock/src/__tests__/index.test.ts index df330d6354e1..bd7b073351e4 100644 --- a/packages/jest-mock/src/__tests__/index.test.ts +++ b/packages/jest-mock/src/__tests__/index.test.ts @@ -140,7 +140,7 @@ describe('moduleMocker', () => { }); it('wont interfere with previous mocks on a shared prototype', () => { - const ClassFoo = function() {}; + const ClassFoo = function () {}; ClassFoo.prototype.x = () => {}; const ClassFooMock = moduleMocker.generateFromMetadata( moduleMocker.getMetadata(ClassFoo), @@ -986,7 +986,7 @@ describe('moduleMocker', () => { const mock1 = jest.fn(); const mock2 = jest.fn(); const Module = jest.fn(() => ({someFn: mock1})); - const testFn = function() { + const testFn = function () { const m = new Module(); m.someFn(); }; @@ -1183,7 +1183,7 @@ describe('moduleMocker', () => { let originalCallArguments; const obj = { get method() { - return function() { + return function () { isOriginalCalled = true; originalCallThis = this; originalCallArguments = arguments; @@ -1256,12 +1256,12 @@ describe('moduleMocker', () => { let methodTwoCalls = 0; const obj = { get methodOne() { - return function() { + return function () { methodOneCalls++; }; }, get methodTwo() { - return function() { + return function () { methodTwoCalls++; }; }, @@ -1297,7 +1297,7 @@ describe('moduleMocker', () => { let originalCallArguments; const prototype = { get method() { - return function() { + return function () { isOriginalCalled = true; originalCallThis = this; originalCallArguments = arguments; @@ -1360,12 +1360,12 @@ describe('moduleMocker', () => { let methodTwoCalls = 0; const prototype = { get methodOne() { - return function() { + return function () { methodOneCalls++; }; }, get methodTwo() { - return function() { + return function () { methodTwoCalls++; }; }, diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index 8afcd60b6a56..a72847029b0d 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -183,17 +183,17 @@ function matchArity(fn: Function, length: number): Function { switch (length) { case 1: - mockConstructor = function(this: unknown, _a: unknown) { + mockConstructor = function (this: unknown, _a: unknown) { return fn.apply(this, arguments); }; break; case 2: - mockConstructor = function(this: unknown, _a: unknown, _b: unknown) { + mockConstructor = function (this: unknown, _a: unknown, _b: unknown) { return fn.apply(this, arguments); }; break; case 3: - mockConstructor = function( + mockConstructor = function ( this: unknown, _a: unknown, _b: unknown, @@ -203,7 +203,7 @@ function matchArity(fn: Function, length: number): Function { }; break; case 4: - mockConstructor = function( + mockConstructor = function ( this: unknown, _a: unknown, _b: unknown, @@ -214,7 +214,7 @@ function matchArity(fn: Function, length: number): Function { }; break; case 5: - mockConstructor = function( + mockConstructor = function ( this: unknown, _a: unknown, _b: unknown, @@ -226,7 +226,7 @@ function matchArity(fn: Function, length: number): Function { }; break; case 6: - mockConstructor = function( + mockConstructor = function ( this: unknown, _a: unknown, _b: unknown, @@ -239,7 +239,7 @@ function matchArity(fn: Function, length: number): Function { }; break; case 7: - mockConstructor = function( + mockConstructor = function ( this: unknown, _a: unknown, _b: unknown, @@ -253,7 +253,7 @@ function matchArity(fn: Function, length: number): Function { }; break; case 8: - mockConstructor = function( + mockConstructor = function ( this: unknown, _a: unknown, _b: unknown, @@ -268,7 +268,7 @@ function matchArity(fn: Function, length: number): Function { }; break; case 9: - mockConstructor = function( + mockConstructor = function ( this: unknown, _a: unknown, _b: unknown, @@ -284,7 +284,7 @@ function matchArity(fn: Function, length: number): Function { }; break; default: - mockConstructor = function(this: unknown) { + mockConstructor = function (this: unknown) { return fn.apply(this, arguments); }; break; @@ -528,7 +528,7 @@ class ModuleMockerClass { {}; const prototypeSlots = this._getSlots(prototype); const mocker = this; - const mockConstructor = matchArity(function(this: T, ...args: Y) { + const mockConstructor = matchArity(function (this: T, ...args: Y) { const mockState = mocker._ensureMockState(f); const mockConfig = mocker._ensureMockConfig(f); mockState.instances.push(this); @@ -692,7 +692,7 @@ class ModuleMockerClass { }; f.mockReturnThis = () => - f.mockImplementation(function(this: T) { + f.mockImplementation(function (this: T) { return this; }); @@ -805,7 +805,7 @@ class ModuleMockerClass { const slotMetadata = (metadata.members && metadata.members[slot]) || {}; if (slotMetadata.ref != null) { callbacks.push( - (function(ref) { + (function (ref) { return () => (mock[slot] = refs[ref]); })(slotMetadata.ref), ); @@ -988,7 +988,7 @@ class ModuleMockerClass { }); // @ts-ignore original method is now a Mock - object[methodName].mockImplementation(function(this: unknown) { + object[methodName].mockImplementation(function (this: unknown) { return original.apply(this, arguments); }); } @@ -1059,7 +1059,7 @@ class ModuleMockerClass { Object.defineProperty(obj, propertyName, descriptor!); }); - (descriptor[accessType] as Mock).mockImplementation(function( + (descriptor[accessType] as Mock).mockImplementation(function ( this: unknown, ) { // @ts-ignore diff --git a/packages/jest-phabricator/src/index.ts b/packages/jest-phabricator/src/index.ts index de36344afc5d..43d738b6c771 100644 --- a/packages/jest-phabricator/src/index.ts +++ b/packages/jest-phabricator/src/index.ts @@ -38,6 +38,6 @@ function summarize(coverageMap: CoverageMap): CoverageMap { return summaries; } -export = function(results: AggregatedResult): AggregatedResult { +export = function (results: AggregatedResult): AggregatedResult { return {...results, coverageMap: summarize(results.coverageMap)}; }; diff --git a/packages/jest-repl/src/cli/index.ts b/packages/jest-repl/src/cli/index.ts index 1a0e982d03f3..7c76ca03b9ed 100644 --- a/packages/jest-repl/src/cli/index.ts +++ b/packages/jest-repl/src/cli/index.ts @@ -18,7 +18,7 @@ const {version: VERSION} = require('../../package.json'); const REPL_SCRIPT = require.resolve('./repl.js'); -export = function(): void { +export = function (): void { const argv = yargs.usage(args.usage).options(args.options).argv; // @ts-ignore: fix this at some point diff --git a/packages/jest-reporters/src/generateEmptyCoverage.ts b/packages/jest-reporters/src/generateEmptyCoverage.ts index b026e9861b3e..5fc8b6c315ae 100644 --- a/packages/jest-reporters/src/generateEmptyCoverage.ts +++ b/packages/jest-reporters/src/generateEmptyCoverage.ts @@ -25,7 +25,7 @@ export type CoverageWorkerResult = result: SingleV8Coverage; }; -export default function( +export default function ( source: string, filename: Config.Path, globalConfig: Config.GlobalConfig, diff --git a/packages/jest-reporters/src/summary_reporter.ts b/packages/jest-reporters/src/summary_reporter.ts index 026e29bbac55..f7729898f3b8 100644 --- a/packages/jest-reporters/src/summary_reporter.ts +++ b/packages/jest-reporters/src/summary_reporter.ts @@ -145,11 +145,9 @@ export default class SummaryReporter extends BaseReporter { if (globalConfig.watch || globalConfig.watchAll) { updateCommand = 'press `u`'; } else if (event && scriptUsesJest) { - updateCommand = `run \`${client + - ' ' + - prefix + - event + - (isYarn ? '' : ' --')} -u\``; + updateCommand = `run \`${ + client + ' ' + prefix + event + (isYarn ? '' : ' --') + } -u\``; } else { updateCommand = 're-run jest with `-u`'; } diff --git a/packages/jest-runtime/src/cli/index.ts b/packages/jest-runtime/src/cli/index.ts index 26cfb8136467..269a52dc2438 100644 --- a/packages/jest-runtime/src/cli/index.ts +++ b/packages/jest-runtime/src/cli/index.ts @@ -32,11 +32,10 @@ export async function run( if (cliArgv) { argv = cliArgv; } else { - argv = yargs - .usage(args.usage) - .help(false) - .version(false) - .options(args.options).argv; + argv = ( + yargs.usage(args.usage).help(false).version(false).options(args.options) + .argv + ); validateCLIOptions(argv, {...args.options, deprecationEntries}); } diff --git a/packages/jest-snapshot/src/index.ts b/packages/jest-snapshot/src/index.ts index 1fbabce0fc22..b9742f89edc4 100644 --- a/packages/jest-snapshot/src/index.ts +++ b/packages/jest-snapshot/src/index.ts @@ -154,7 +154,7 @@ const cleanup = ( }; }; -const toMatchSnapshot = function( +const toMatchSnapshot = function ( this: Context, received: any, propertiesOrHint?: object | Config.Path, @@ -212,7 +212,7 @@ const toMatchSnapshot = function( }); }; -const toMatchInlineSnapshot = function( +const toMatchInlineSnapshot = function ( this: Context, received: any, propertiesOrSnapshot?: object | string, @@ -412,7 +412,7 @@ const _toMatchSnapshot = (config: MatchSnapshotConfig) => { }; }; -const toThrowErrorMatchingSnapshot = function( +const toThrowErrorMatchingSnapshot = function ( this: Context, received: any, hint: string | undefined, // because error TS1016 for hint?: string @@ -435,7 +435,7 @@ const toThrowErrorMatchingSnapshot = function( ); }; -const toThrowErrorMatchingInlineSnapshot = function( +const toThrowErrorMatchingInlineSnapshot = function ( this: Context, received: any, inlineSnapshot?: string, diff --git a/packages/jest-transform/src/ScriptTransformer.ts b/packages/jest-transform/src/ScriptTransformer.ts index 18b3b46a07f0..e63d230dd34b 100644 --- a/packages/jest-transform/src/ScriptTransformer.ts +++ b/packages/jest-transform/src/ScriptTransformer.ts @@ -599,9 +599,7 @@ const stripShebang = (content: string) => { * could get corrupted, out-of-sync, etc. */ function writeCodeCacheFile(cachePath: Config.Path, code: string) { - const checksum = createHash('md5') - .update(code) - .digest('hex'); + const checksum = createHash('md5').update(code).digest('hex'); writeCacheFile(cachePath, checksum + '\n' + code); } @@ -617,9 +615,7 @@ function readCodeCacheFile(cachePath: Config.Path): string | null { return null; } const code = content.substr(33); - const checksum = createHash('md5') - .update(code) - .digest('hex'); + const checksum = createHash('md5').update(code).digest('hex'); if (checksum === content.substr(0, 32)) { return code; } diff --git a/packages/jest-transform/src/__tests__/script_transformer.test.js b/packages/jest-transform/src/__tests__/script_transformer.test.js index 39a14eea96ad..63dd80a9d08b 100644 --- a/packages/jest-transform/src/__tests__/script_transformer.test.js +++ b/packages/jest-transform/src/__tests__/script_transformer.test.js @@ -461,9 +461,7 @@ describe('ScriptTransformer', () => { const content = 'var x = 1;\n' + '//# sourceMappingURL=data:application/json;base64,' + - Buffer.from(sourceMap) - .toString('base64') - .slice(0, 16); + Buffer.from(sourceMap).toString('base64').slice(0, 16); require('preprocessor-with-sourcemaps').process.mockReturnValue(content); diff --git a/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts b/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts index 73ea0f451da0..926bbd540da3 100644 --- a/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts +++ b/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts @@ -85,11 +85,11 @@ it('uses the blacklist to avoid copying properties on the first level', () => { it('does not keep the prototype by default when top level is object', () => { // @ts-ignore - const sourceObject = new (function() {})(); + const sourceObject = new (function () {})(); // @ts-ignore - sourceObject.nestedObject = new (function() {})(); + sourceObject.nestedObject = new (function () {})(); // @ts-ignore - sourceObject.nestedArray = new (function() { + sourceObject.nestedArray = new (function () { // @ts-ignore this.length = 0; })(); @@ -125,7 +125,7 @@ it('does not keep the prototype by default when top level is array', () => { const spy = jest.spyOn(Array, 'isArray').mockImplementation(() => true); // @ts-ignore - const sourceArray = new (function() { + const sourceArray = new (function () { // @ts-ignore this.length = 0; })(); @@ -143,7 +143,7 @@ it('does not keep the prototype of arrays when keepPrototype = false', () => { const spy = jest.spyOn(Array, 'isArray').mockImplementation(() => true); // @ts-ignore - const sourceArray = new (function() { + const sourceArray = new (function () { // @ts-ignore this.length = 0; })(); @@ -161,7 +161,7 @@ it('keeps the prototype of arrays when keepPrototype = true', () => { const spy = jest.spyOn(Array, 'isArray').mockImplementation(() => true); // @ts-ignore - const sourceArray = new (function() { + const sourceArray = new (function () { // @ts-ignore this.length = 0; })(); @@ -174,11 +174,11 @@ it('keeps the prototype of arrays when keepPrototype = true', () => { it('does not keep the prototype for objects when keepPrototype = false', () => { // @ts-ignore - const sourceobject = new (function() {})(); + const sourceobject = new (function () {})(); // @ts-ignore - sourceobject.nestedObject = new (function() {})(); + sourceobject.nestedObject = new (function () {})(); // @ts-ignore - sourceobject.nestedArray = new (function() { + sourceobject.nestedArray = new (function () { // @ts-ignore this.length = 0; })(); @@ -211,11 +211,11 @@ it('does not keep the prototype for objects when keepPrototype = false', () => { it('keeps the prototype for objects when keepPrototype = true', () => { // @ts-ignore - const sourceObject = new (function() {})(); + const sourceObject = new (function () {})(); // @ts-ignore - sourceObject.nestedObject = new (function() {})(); + sourceObject.nestedObject = new (function () {})(); // @ts-ignore - sourceObject.nestedArray = new (function() { + sourceObject.nestedArray = new (function () { // @ts-ignore this.length = 0; })(); diff --git a/packages/jest-util/src/createProcessObject.ts b/packages/jest-util/src/createProcessObject.ts index 621754380072..1c391acb8136 100644 --- a/packages/jest-util/src/createProcessObject.ts +++ b/packages/jest-util/src/createProcessObject.ts @@ -79,7 +79,7 @@ function createProcessEnv(): NodeJS.ProcessEnv { return Object.assign(proxy, process.env); } -export default function(): NodeJS.Process { +export default function (): NodeJS.Process { const process = require('process'); const newProcess = deepCyclicCopy(process, { blacklist: BLACKLIST, diff --git a/packages/jest-util/src/installCommonGlobals.ts b/packages/jest-util/src/installCommonGlobals.ts index afd2c0dfd706..d6365683597f 100644 --- a/packages/jest-util/src/installCommonGlobals.ts +++ b/packages/jest-util/src/installCommonGlobals.ts @@ -12,7 +12,7 @@ import deepCyclicCopy from './deepCyclicCopy'; const DTRACE = Object.keys(global).filter(key => key.startsWith('DTRACE')); -export default function( +export default function ( globalObject: NodeJS.Global, globals: Config.ConfigGlobals, ): NodeJS.Global & Config.ConfigGlobals { @@ -56,7 +56,7 @@ export default function( // Forward some APIs. DTRACE.forEach(dtrace => { // @ts-ignore: no index - globalObject[dtrace] = function(...args: Array) { + globalObject[dtrace] = function (...args: Array) { // @ts-ignore: no index return global[dtrace].apply(this, args); }; diff --git a/packages/jest-validate/src/__tests__/validate.test.ts b/packages/jest-validate/src/__tests__/validate.test.ts index fa83731159c6..aaf5e2bf172c 100644 --- a/packages/jest-validate/src/__tests__/validate.test.ts +++ b/packages/jest-validate/src/__tests__/validate.test.ts @@ -88,10 +88,10 @@ test('recursively omits null and undefined config values', () => { }); test.each([ - [function() {}, function() {}], - [async function() {}, function() {}], - [function() {}, async function() {}], - [async function() {}, async function() {}], + [function () {}, function () {}], + [async function () {}, function () {}], + [function () {}, async function () {}], + [async function () {}, async function () {}], ])( 'treat async and non-async functions as equivalent', (value, exampleValue) => { diff --git a/packages/jest-validate/src/utils.ts b/packages/jest-validate/src/utils.ts index d2414dd50d1a..48d2beabe980 100644 --- a/packages/jest-validate/src/utils.ts +++ b/packages/jest-validate/src/utils.ts @@ -22,9 +22,7 @@ export const format = (value: unknown): string => export const formatPrettyObject = (value: unknown): string => typeof value === 'function' ? value.toString() - : JSON.stringify(value, null, 2) - .split('\n') - .join('\n '); + : JSON.stringify(value, null, 2).split('\n').join('\n '); export class ValidationError extends Error { name: string; diff --git a/packages/jest-worker/src/__performance_tests__/workers/jest_worker.js b/packages/jest-worker/src/__performance_tests__/workers/jest_worker.js index 49fd08b2cbc6..97b7fc251fbc 100644 --- a/packages/jest-worker/src/__performance_tests__/workers/jest_worker.js +++ b/packages/jest-worker/src/__performance_tests__/workers/jest_worker.js @@ -9,10 +9,10 @@ const pi = require('./pi'); -module.exports.loadTest = function() { +module.exports.loadTest = function () { return pi(); }; -module.exports.empty = function() { +module.exports.empty = function () { // Do nothing. }; diff --git a/packages/jest-worker/src/__performance_tests__/workers/pi.js b/packages/jest-worker/src/__performance_tests__/workers/pi.js index bf2c043f45ec..c4c7a7bf1f1a 100644 --- a/packages/jest-worker/src/__performance_tests__/workers/pi.js +++ b/packages/jest-worker/src/__performance_tests__/workers/pi.js @@ -7,7 +7,7 @@ 'use strict'; -module.exports = function() { +module.exports = function () { const points = 10000; let inside = 0; diff --git a/packages/jest-worker/src/__performance_tests__/workers/worker_farm.js b/packages/jest-worker/src/__performance_tests__/workers/worker_farm.js index 8310301e0f16..9ff29df123c4 100644 --- a/packages/jest-worker/src/__performance_tests__/workers/worker_farm.js +++ b/packages/jest-worker/src/__performance_tests__/workers/worker_farm.js @@ -9,11 +9,11 @@ const pi = require('./pi'); -module.exports.loadTest = function(callback) { +module.exports.loadTest = function (callback) { callback(null, pi()); }; -module.exports.empty = function(callback) { +module.exports.empty = function (callback) { // Do nothing. callback(); }; diff --git a/scripts/buildUtils.js b/scripts/buildUtils.js index 9e240e09a615..0e0775795cc4 100644 --- a/scripts/buildUtils.js +++ b/scripts/buildUtils.js @@ -30,10 +30,7 @@ module.exports.adjustToTerminalWidth = function adjustToTerminalWidth(str) { if (lastString.length < WIDTH) { lastString += Array(WIDTH - lastString.length).join(chalk.dim('.')); } - return strs - .slice(0, -1) - .concat(lastString) - .join('\n'); + return strs.slice(0, -1).concat(lastString).join('\n'); }; module.exports.OK = OK; diff --git a/scripts/remove-prettier-dep.js b/scripts/remove-prettier-dep.js new file mode 100644 index 000000000000..90db4ad2f53b --- /dev/null +++ b/scripts/remove-prettier-dep.js @@ -0,0 +1,18 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +'use strict'; + +const {writeFileSync} = require('fs'); + +const pkgPath = require.resolve('../package.json'); + +const pkg = require('../package.json'); + +delete pkg.devDependencies.prettier; + +writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`); diff --git a/website/versioned_docs/version-22.x/MockFunctionAPI.md b/website/versioned_docs/version-22.x/MockFunctionAPI.md index eb5382803862..63f0c6237450 100644 --- a/website/versioned_docs/version-22.x/MockFunctionAPI.md +++ b/website/versioned_docs/version-22.x/MockFunctionAPI.md @@ -170,7 +170,7 @@ Expected mock function "mockedFunction" to have been called, but it was not call Syntactic sugar function for: ```js -jest.fn(function() { +jest.fn(function () { return this; }); ``` diff --git a/website/versioned_docs/version-22.x/MockFunctions.md b/website/versioned_docs/version-22.x/MockFunctions.md index 874042fc4c3f..27f0b4076e62 100644 --- a/website/versioned_docs/version-22.x/MockFunctions.md +++ b/website/versioned_docs/version-22.x/MockFunctions.md @@ -81,10 +81,7 @@ const myMock = jest.fn(); console.log(myMock()); // > undefined -myMock - .mockReturnValueOnce(10) - .mockReturnValueOnce('x') - .mockReturnValue(true); +myMock.mockReturnValueOnce(10).mockReturnValueOnce('x').mockReturnValue(true); console.log(myMock(), myMock(), myMock(), myMock()); // > 10, 'x', true, true @@ -127,7 +124,7 @@ The `mockImplementation` method is useful when you need to define the default im ```js // foo.js -module.exports = function() { +module.exports = function () { // some implementation; }; @@ -178,7 +175,7 @@ const myObj = { // is the same as const otherObj = { - myMethod: jest.fn(function() { + myMethod: jest.fn(function () { return this; }), }; diff --git a/website/versioned_docs/version-22.x/Puppeteer.md b/website/versioned_docs/version-22.x/Puppeteer.md index 62f4693dcc74..8c54dca91784 100644 --- a/website/versioned_docs/version-22.x/Puppeteer.md +++ b/website/versioned_docs/version-22.x/Puppeteer.md @@ -20,7 +20,7 @@ Here's an example of the GlobalSetup script ```js // setup.js -module.exports = async function() { +module.exports = async function () { const browser = await puppeteer.launch(); // store the browser instance so we can teardown it later global.__BROWSER__ = browser; @@ -68,7 +68,7 @@ Finally we can close the puppeteer instance and clean-up the file ```js // teardown.js -module.exports = async function() { +module.exports = async function () { // close the browser instance await global.__BROWSER__.close(); diff --git a/website/versioned_docs/version-23.x/Es6ClassMocks.md b/website/versioned_docs/version-23.x/Es6ClassMocks.md index 74e38caea546..32ec1d1e13f6 100644 --- a/website/versioned_docs/version-23.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-23.x/Es6ClassMocks.md @@ -222,7 +222,7 @@ In order to mock a constructor function, the module factory must return a constr ```javascript jest.mock('./sound-player', () => { - return function() { + return function () { return {playSoundFile: () => {}}; }; }); diff --git a/website/versioned_docs/version-23.x/MockFunctionAPI.md b/website/versioned_docs/version-23.x/MockFunctionAPI.md index deac6e4809f1..dc78bd26007b 100644 --- a/website/versioned_docs/version-23.x/MockFunctionAPI.md +++ b/website/versioned_docs/version-23.x/MockFunctionAPI.md @@ -197,7 +197,7 @@ Expected mock function "mockedFunction" to have been called, but it was not call Syntactic sugar function for: ```js -jest.fn(function() { +jest.fn(function () { return this; }); ``` diff --git a/website/versioned_docs/version-23.x/MockFunctions.md b/website/versioned_docs/version-23.x/MockFunctions.md index b949b52665a5..caf664f9d5be 100644 --- a/website/versioned_docs/version-23.x/MockFunctions.md +++ b/website/versioned_docs/version-23.x/MockFunctions.md @@ -87,10 +87,7 @@ const myMock = jest.fn(); console.log(myMock()); // > undefined -myMock - .mockReturnValueOnce(10) - .mockReturnValueOnce('x') - .mockReturnValue(true); +myMock.mockReturnValueOnce(10).mockReturnValueOnce('x').mockReturnValue(true); console.log(myMock(), myMock(), myMock(), myMock()); // > 10, 'x', true, true @@ -173,7 +170,7 @@ The `mockImplementation` method is useful when you need to define the default im ```js // foo.js -module.exports = function() { +module.exports = function () { // some implementation; }; @@ -224,7 +221,7 @@ const myObj = { // is the same as const otherObj = { - myMethod: jest.fn(function() { + myMethod: jest.fn(function () { return this; }), }; diff --git a/website/versioned_docs/version-23.x/Puppeteer.md b/website/versioned_docs/version-23.x/Puppeteer.md index e07002b0f52f..feb39463c6a0 100644 --- a/website/versioned_docs/version-23.x/Puppeteer.md +++ b/website/versioned_docs/version-23.x/Puppeteer.md @@ -64,7 +64,7 @@ const os = require('os'); const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); -module.exports = async function() { +module.exports = async function () { const browser = await puppeteer.launch(); // store the browser instance so we can teardown it later // this global is only available in the teardown but not in TestEnvironments @@ -126,7 +126,7 @@ const rimraf = require('rimraf'); const path = require('path'); const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); -module.exports = async function() { +module.exports = async function () { // close the browser instance await global.__BROWSER_GLOBAL__.close(); diff --git a/website/versioned_docs/version-24.x/Configuration.md b/website/versioned_docs/version-24.x/Configuration.md index 5a32f8a5dd16..2e169d285daa 100644 --- a/website/versioned_docs/version-24.x/Configuration.md +++ b/website/versioned_docs/version-24.x/Configuration.md @@ -414,7 +414,7 @@ module.exports = async () => { ```js // teardown.js -module.exports = async function() { +module.exports = async function () { await global.__MONGOD__.stop(); }; ``` diff --git a/website/versioned_docs/version-24.x/Es6ClassMocks.md b/website/versioned_docs/version-24.x/Es6ClassMocks.md index 8d4661d6aa99..26122083a404 100644 --- a/website/versioned_docs/version-24.x/Es6ClassMocks.md +++ b/website/versioned_docs/version-24.x/Es6ClassMocks.md @@ -222,7 +222,7 @@ In order to mock a constructor function, the module factory must return a constr ```javascript jest.mock('./sound-player', () => { - return function() { + return function () { return {playSoundFile: () => {}}; }; }); diff --git a/website/versioned_docs/version-24.x/MockFunctionAPI.md b/website/versioned_docs/version-24.x/MockFunctionAPI.md index e1592572f6b2..3e83e06715bf 100644 --- a/website/versioned_docs/version-24.x/MockFunctionAPI.md +++ b/website/versioned_docs/version-24.x/MockFunctionAPI.md @@ -203,7 +203,7 @@ Expected mock function "mockedFunction" to have been called, but it was not call Syntactic sugar function for: ```js -jest.fn(function() { +jest.fn(function () { return this; }); ``` diff --git a/website/versioned_docs/version-24.x/MockFunctions.md b/website/versioned_docs/version-24.x/MockFunctions.md index fabd2bac40b7..742ef4522dea 100644 --- a/website/versioned_docs/version-24.x/MockFunctions.md +++ b/website/versioned_docs/version-24.x/MockFunctions.md @@ -87,10 +87,7 @@ const myMock = jest.fn(); console.log(myMock()); // > undefined -myMock - .mockReturnValueOnce(10) - .mockReturnValueOnce('x') - .mockReturnValue(true); +myMock.mockReturnValueOnce(10).mockReturnValueOnce('x').mockReturnValue(true); console.log(myMock(), myMock(), myMock(), myMock()); // > 10, 'x', true, true @@ -170,7 +167,7 @@ The `mockImplementation` method is useful when you need to define the default im ```js // foo.js -module.exports = function() { +module.exports = function () { // some implementation; }; @@ -221,7 +218,7 @@ const myObj = { // is the same as const otherObj = { - myMethod: jest.fn(function() { + myMethod: jest.fn(function () { return this; }), }; diff --git a/website/versioned_docs/version-24.x/Puppeteer.md b/website/versioned_docs/version-24.x/Puppeteer.md index 12eee2b8779f..87a7260592e9 100644 --- a/website/versioned_docs/version-24.x/Puppeteer.md +++ b/website/versioned_docs/version-24.x/Puppeteer.md @@ -64,7 +64,7 @@ const os = require('os'); const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); -module.exports = async function() { +module.exports = async function () { const browser = await puppeteer.launch(); // store the browser instance so we can teardown it later // this global is only available in the teardown but not in TestEnvironments @@ -128,7 +128,7 @@ const rimraf = require('rimraf'); const path = require('path'); const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); -module.exports = async function() { +module.exports = async function () { // close the browser instance await global.__BROWSER_GLOBAL__.close(); diff --git a/website/versioned_docs/version-25.1/Configuration.md b/website/versioned_docs/version-25.1/Configuration.md index 4ffbbd9a9090..a2c1ed6c3f8d 100644 --- a/website/versioned_docs/version-25.1/Configuration.md +++ b/website/versioned_docs/version-25.1/Configuration.md @@ -424,7 +424,7 @@ module.exports = async () => { ```js // teardown.js -module.exports = async function() { +module.exports = async function () { await global.__MONGOD__.stop(); }; ``` diff --git a/website/versioned_docs/version-25.1/MockFunctions.md b/website/versioned_docs/version-25.1/MockFunctions.md index a319bf22042e..f9ada1561dba 100644 --- a/website/versioned_docs/version-25.1/MockFunctions.md +++ b/website/versioned_docs/version-25.1/MockFunctions.md @@ -87,10 +87,7 @@ const myMock = jest.fn(); console.log(myMock()); // > undefined -myMock - .mockReturnValueOnce(10) - .mockReturnValueOnce('x') - .mockReturnValue(true); +myMock.mockReturnValueOnce(10).mockReturnValueOnce('x').mockReturnValue(true); console.log(myMock(), myMock(), myMock(), myMock()); // > 10, 'x', true, true @@ -170,7 +167,7 @@ The `mockImplementation` method is useful when you need to define the default im ```js // foo.js -module.exports = function() { +module.exports = function () { // some implementation; }; @@ -221,7 +218,7 @@ const myObj = { // is the same as const otherObj = { - myMethod: jest.fn(function() { + myMethod: jest.fn(function () { return this; }), }; diff --git a/yarn.lock b/yarn.lock index 447344cd6006..0e3dd886f653 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11745,11 +11745,16 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@^1.13.4, prettier@^1.19.0: +prettier@^1.13.4: version "1.19.1" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== +prettier@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.1.tgz#3f00ac71263be34684b2b2c8d7e7f63737592dac" + integrity sha512-piXGBcY1zoFOG0MvHpNE5reAGseLmaCRifQ/fmfF49BcYkInEs/naD/unxGNAeOKFA5+JxVrPyMvMlpzcd20UA== + pretty-format@^24.7.0, pretty-format@^24.8.0, pretty-format@^24.9.0: version "24.9.0" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-24.9.0.tgz#12fac31b37019a4eea3c11aa9a959eb7628aa7c9"