diff --git a/.eslintrc.js b/.eslintrc.js index 075a0c763dfd..49eafb955758 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -132,7 +132,7 @@ module.exports = { '**/__mocks__/**', '**/?(*.)(spec|test).js?(x)', 'scripts/**', - 'eslintImportResolver.js', + 'babel.config.js', 'testSetupFile.js', ], }, diff --git a/babel.config.js b/babel.config.js index f062b0d8739f..b01524bb0f50 100644 --- a/babel.config.js +++ b/babel.config.js @@ -5,6 +5,11 @@ * LICENSE file in the root directory of this source tree. */ +const semver = require('semver'); +const pkg = require('./package.json'); + +const supportedNodeVersion = semver.minVersion(pkg.engines.node).version; + module.exports = { babelrcRoots: ['examples/*'], // we don't wanna run the transforms in this file over react native @@ -15,7 +20,7 @@ module.exports = { 'babel-plugin-typescript-strip-namespaces', 'babel-plugin-replace-ts-export-assignment', require.resolve( - './scripts/babel-plugin-jest-replace-ts-require-assignment.js' + './scripts/babel-plugin-jest-replace-ts-require-assignment.js', ), ], presets: ['@babel/preset-typescript'], @@ -31,7 +36,7 @@ module.exports = { { exclude: ['@babel/plugin-proposal-dynamic-import'], shippedProposals: true, - targets: {node: '8.3'}, + targets: {node: supportedNodeVersion}, }, ], ], @@ -48,7 +53,7 @@ module.exports = { '@babel/preset-env', { shippedProposals: true, - targets: {node: '8.3'}, + targets: {node: supportedNodeVersion}, }, ], ], diff --git a/e2e/__tests__/__snapshots__/each.test.ts.snap b/e2e/__tests__/__snapshots__/each.test.ts.snap index 188a2727b2b9..98edb0ecb406 100644 --- a/e2e/__tests__/__snapshots__/each.test.ts.snap +++ b/e2e/__tests__/__snapshots__/each.test.ts.snap @@ -205,7 +205,7 @@ FAIL __tests__/failure.test.js 28 | ({left, right}) => { > 29 | expect(left).toBe(right); | ^ - 30 | } + 30 | }, 31 | ); 32 | @@ -222,7 +222,7 @@ FAIL __tests__/failure.test.js 39 | ({left, right}) => { > 40 | expect(left).toBe(right); | ^ - 41 | } + 41 | }, 42 | ); 43 | @@ -239,7 +239,7 @@ FAIL __tests__/failure.test.js 39 | ({left, right}) => { > 40 | expect(left).toBe(right); | ^ - 41 | } + 41 | }, 42 | ); 43 | @@ -256,7 +256,7 @@ FAIL __tests__/failure.test.js 46 | word => { > 47 | expect(/z/.test(word)).toBe(true); | ^ - 48 | } + 48 | }, 49 | ); 50 | @@ -273,7 +273,7 @@ FAIL __tests__/failure.test.js 46 | word => { > 47 | expect(/z/.test(word)).toBe(true); | ^ - 48 | } + 48 | }, 49 | ); 50 | @@ -290,7 +290,7 @@ FAIL __tests__/failure.test.js 46 | word => { > 47 | expect(/z/.test(word)).toBe(true); | ^ - 48 | } + 48 | }, 49 | ); 50 | @@ -308,7 +308,7 @@ FAIL __tests__/failure.test.js > 59 | expect(left).toBe(right); | ^ 60 | }); - 61 | } + 61 | }, 62 | ); at Object.toBe (__tests__/failure.test.js:59:20) @@ -325,7 +325,7 @@ FAIL __tests__/failure.test.js > 59 | expect(left).toBe(right); | ^ 60 | }); - 61 | } + 61 | }, 62 | ); at Object.toBe (__tests__/failure.test.js:59:20) @@ -342,7 +342,7 @@ FAIL __tests__/failure.test.js > 71 | expect(left).toBe(right); | ^ 72 | }); - 73 | } + 73 | }, 74 | ); at Object.toBe (__tests__/failure.test.js:71:20) @@ -359,7 +359,7 @@ FAIL __tests__/failure.test.js > 71 | expect(left).toBe(right); | ^ 72 | }); - 73 | } + 73 | }, 74 | ); at Object.toBe (__tests__/failure.test.js:71:20) diff --git a/e2e/__tests__/__snapshots__/errorOnDeprecated.test.ts.snap b/e2e/__tests__/__snapshots__/errorOnDeprecated.test.ts.snap index 613a80ca77b8..ab3b25ed0f25 100644 --- a/e2e/__tests__/__snapshots__/errorOnDeprecated.test.ts.snap +++ b/e2e/__tests__/__snapshots__/errorOnDeprecated.test.ts.snap @@ -138,7 +138,7 @@ FAIL __tests__/jasmine.objectContaining.test.js 9 | test('jasmine.objectContaining', () => { 10 | expect({input: 'trash', output: 'trash'}).toEqual( - > 11 | jasmine.objectContaining({output: 'trash'}) + > 11 | jasmine.objectContaining({output: 'trash'}), | ^ 12 | ); 13 | }); diff --git a/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.ts.snap b/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.ts.snap index b7d07fa98db9..0c2dd06fe47c 100644 --- a/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.ts.snap +++ b/e2e/__tests__/__snapshots__/expectAsyncMatcher.test.ts.snap @@ -77,7 +77,7 @@ FAIL __tests__/failure.test.js 21 | it('fail with expected promise values and not', () => > 22 | expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync( | ^ - 23 | Promise.resolve(2) + 23 | Promise.resolve(2), 24 | )); 25 | diff --git a/e2e/__tests__/__snapshots__/toMatchInlineSnapshot.test.ts.snap b/e2e/__tests__/__snapshots__/toMatchInlineSnapshot.test.ts.snap index 1abfcc0e03ad..a64fb6a82fde 100644 --- a/e2e/__tests__/__snapshots__/toMatchInlineSnapshot.test.ts.snap +++ b/e2e/__tests__/__snapshots__/toMatchInlineSnapshot.test.ts.snap @@ -71,7 +71,7 @@ test('handles property matchers', () => { Object { "createdAt": Any, } - \` + \`, ); }); @@ -85,7 +85,7 @@ expect({createdAt: "string"}).toMatchInlineSnapshot( Object { "createdAt": Any, } -\` +\`, ); }); `; @@ -98,7 +98,7 @@ test('handles property matchers', () => { Object { "createdAt": Any, } - \` + \`, ); }); @@ -112,7 +112,7 @@ test('handles property matchers', () => { Object { "createdAt": Any, } - \` + \`, ); }); @@ -192,7 +192,7 @@ test('removes obsolete external snapshots', () => { exports[`supports async matchers 1`] = ` test('inline snapshots', async () => { expect(Promise.resolve('success')).resolves.toMatchInlineSnapshot( - \`"success"\` + \`"success"\`, ); expect(Promise.reject('fail')).rejects.toMatchInlineSnapshot(\`"fail"\`); }); @@ -221,7 +221,7 @@ expect.extend({ createdAt: expect.any(Date), id: expect.any(Number), }, - ...args + ...args, ); }, }); @@ -242,7 +242,7 @@ test('inline snapshots', () => { "id": Any, "name": "LeBron James", } - \` + \`, ); expect(user).toMatchUserInlineSnapshot(\` Object { diff --git a/e2e/__tests__/__snapshots__/toThrowErrorMatchingInlineSnapshot.test.ts.snap b/e2e/__tests__/__snapshots__/toThrowErrorMatchingInlineSnapshot.test.ts.snap index eb1a037f29aa..7e68215ed3f3 100644 --- a/e2e/__tests__/__snapshots__/toThrowErrorMatchingInlineSnapshot.test.ts.snap +++ b/e2e/__tests__/__snapshots__/toThrowErrorMatchingInlineSnapshot.test.ts.snap @@ -3,7 +3,7 @@ exports[`should support rejecting promises 1`] = ` test('should support rejecting promises', async () => { await expect( - Promise.reject(new Error('octopus')) + Promise.reject(new Error('octopus')), ).rejects.toThrowErrorMatchingInlineSnapshot(\`"octopus"\`); }); diff --git a/e2e/coverage-handlebars/__tests__/greet.js b/e2e/coverage-handlebars/__tests__/greet.js index f5775645112e..ac8485e7e7a2 100644 --- a/e2e/coverage-handlebars/__tests__/greet.js +++ b/e2e/coverage-handlebars/__tests__/greet.js @@ -8,6 +8,6 @@ const greet = require('../greet.hbs'); test('am', () => { expect(greet({am: true, name: 'Joe'})).toEqual( - '

Good\n morning\nJoe!

\n' + '

Good\n morning\nJoe!

\n', ); }); diff --git a/e2e/coverage-report/notRequiredInTestSuite.js b/e2e/coverage-report/notRequiredInTestSuite.js index 8bbc209edb50..7d3ca5a4b994 100644 --- a/e2e/coverage-report/notRequiredInTestSuite.js +++ b/e2e/coverage-report/notRequiredInTestSuite.js @@ -7,7 +7,7 @@ throw new Error( `this error should not be a problem because` + - `this file is never required or executed` + `this file is never required or executed`, ); // Flow annotations to make sure istanbul can instrument non ES6 source diff --git a/e2e/custom-test-sequencer/testSequencerAsync.js b/e2e/custom-test-sequencer/testSequencerAsync.js index cf379c64752d..15b562b85d8d 100644 --- a/e2e/custom-test-sequencer/testSequencerAsync.js +++ b/e2e/custom-test-sequencer/testSequencerAsync.js @@ -13,7 +13,7 @@ class CustomSequencer extends Sequencer { setTimeout(() => { const copyTests = Array.from(tests); resolve( - copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1)) + copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1)), ); }, 50); }); diff --git a/e2e/each/__tests__/describeOnly.test.js b/e2e/each/__tests__/describeOnly.test.js index 854ecd89d8b3..577c4e25bdcb 100644 --- a/e2e/each/__tests__/describeOnly.test.js +++ b/e2e/each/__tests__/describeOnly.test.js @@ -23,5 +23,5 @@ describe.each([[false, true]])( it('fails', () => { expect(left).toBe(right); }); - } + }, ); diff --git a/e2e/each/__tests__/eachException.test.js b/e2e/each/__tests__/eachException.test.js index 4e017576ac68..1cb350067c4e 100644 --- a/e2e/each/__tests__/eachException.test.js +++ b/e2e/each/__tests__/eachException.test.js @@ -13,7 +13,7 @@ it.each` 'throws exception when one argument too few are supplied $left == $right', ({left, right}) => { expect(left).toBe(right); - } + }, ); it.each` @@ -23,5 +23,5 @@ it.each` 'throws exception when not enough arguments are supplied $left == $right', ({left, right}) => { expect(left).toBe(right); - } + }, ); diff --git a/e2e/each/__tests__/eachOnly.test.js b/e2e/each/__tests__/eachOnly.test.js index 9be757e5b1ab..ea6a8cf19d18 100644 --- a/e2e/each/__tests__/eachOnly.test.js +++ b/e2e/each/__tests__/eachOnly.test.js @@ -37,5 +37,5 @@ it.each` 'Should not be ran: fails all rows expected $left == $right', ({left, right}) => { expect(left).toBe(right); - } + }, ); diff --git a/e2e/each/__tests__/eachSkip.test.js b/e2e/each/__tests__/eachSkip.test.js index 3ca62df48835..fa4f7ed1cac7 100644 --- a/e2e/each/__tests__/eachSkip.test.js +++ b/e2e/each/__tests__/eachSkip.test.js @@ -35,7 +35,7 @@ it.skip.each` 'Should not be ran: fails all rows expected $left == $right', ({left, right}) => { expect(left).toBe(right); - } + }, ); describe.skip.each([ diff --git a/e2e/each/__tests__/failure.test.js b/e2e/each/__tests__/failure.test.js index 7175885bb7ad..ee25783ee553 100644 --- a/e2e/each/__tests__/failure.test.js +++ b/e2e/each/__tests__/failure.test.js @@ -27,7 +27,7 @@ it.each` 'template table fails on one row expected: $left == $right', ({left, right}) => { expect(left).toBe(right); - } + }, ); it.each` @@ -38,14 +38,14 @@ it.each` 'template table fails on all rows expected: $left == $right', ({left, right}) => { expect(left).toBe(right); - } + }, ); test.each(['red', 'green', 'bean'])( "The word %s contains the letter 'z'", word => { expect(/z/.test(word)).toBe(true); - } + }, ); describe.each` @@ -58,7 +58,7 @@ describe.each` it('fails ', () => { expect(left).toBe(right); }); - } + }, ); describe.each([ @@ -70,5 +70,5 @@ describe.each([ it('fails', () => { expect(left).toBe(right); }); - } + }, ); diff --git a/e2e/each/__tests__/success.test.js b/e2e/each/__tests__/success.test.js index 523a4542e513..da26207f78d1 100644 --- a/e2e/each/__tests__/success.test.js +++ b/e2e/each/__tests__/success.test.js @@ -9,7 +9,7 @@ test.each(['red', 'green', 'bean'])( "The word %s contains the letter 'e'", word => { expect(/e/.test(word)).toBe(true); - } + }, ); it.each([ diff --git a/e2e/error-on-deprecated/__tests__/jasmine.objectContaining.test.js b/e2e/error-on-deprecated/__tests__/jasmine.objectContaining.test.js index 3b9683aba277..993a375b1a41 100644 --- a/e2e/error-on-deprecated/__tests__/jasmine.objectContaining.test.js +++ b/e2e/error-on-deprecated/__tests__/jasmine.objectContaining.test.js @@ -8,6 +8,6 @@ test('jasmine.objectContaining', () => { expect({input: 'trash', output: 'trash'}).toEqual( - jasmine.objectContaining({output: 'trash'}) + jasmine.objectContaining({output: 'trash'}), ); }); diff --git a/e2e/expect-async-matcher/__tests__/failure.test.js b/e2e/expect-async-matcher/__tests__/failure.test.js index 206948d90a9b..5f9a4880e173 100644 --- a/e2e/expect-async-matcher/__tests__/failure.test.js +++ b/e2e/expect-async-matcher/__tests__/failure.test.js @@ -20,5 +20,5 @@ it('fail with expected promise values', () => it('fail with expected promise values and not', () => expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync( - Promise.resolve(2) + Promise.resolve(2), )); diff --git a/e2e/expect-async-matcher/__tests__/success.test.js b/e2e/expect-async-matcher/__tests__/success.test.js index 8f597b9788ea..ed4a169f6a08 100644 --- a/e2e/expect-async-matcher/__tests__/success.test.js +++ b/e2e/expect-async-matcher/__tests__/success.test.js @@ -20,5 +20,5 @@ it('works with expected promise values', () => it('works with expected promise values and not', () => expect(Promise.resolve([1, 2])).resolves.not.toHaveLengthAsync( - Promise.resolve(1) + Promise.resolve(1), )); diff --git a/e2e/expect-async-matcher/matchers.js b/e2e/expect-async-matcher/matchers.js index 842139ca1ba6..b148b807b44b 100644 --- a/e2e/expect-async-matcher/matchers.js +++ b/e2e/expect-async-matcher/matchers.js @@ -8,7 +8,7 @@ export async function toHaveLengthAsync( received: any, - lengthPromise: Promise + lengthPromise: Promise, ) { const length = await lengthPromise; diff --git a/e2e/expect-in-vm/__tests__/expect-in-vm.test.js b/e2e/expect-in-vm/__tests__/expect-in-vm.test.js index 32b9ce2d7754..183364245d92 100644 --- a/e2e/expect-in-vm/__tests__/expect-in-vm.test.js +++ b/e2e/expect-in-vm/__tests__/expect-in-vm.test.js @@ -14,7 +14,7 @@ it('correctly expects RegExp inside a new VM context', () => { `(function(require, module, exports, __dirname, __filename, expect) { expect('ab12cd').toMatch(/ab12cd/); })`, - global + global, ); const module = { @@ -28,6 +28,6 @@ it('correctly expects RegExp inside a new VM context', () => { module.exports, __dirname, __filename, - expect + expect, ); }); diff --git a/e2e/jasmine-async/__tests__/promiseBeforeAll.test.js b/e2e/jasmine-async/__tests__/promiseBeforeAll.test.js index 42ce500c408c..f3a40d8f9159 100644 --- a/e2e/jasmine-async/__tests__/promiseBeforeAll.test.js +++ b/e2e/jasmine-async/__tests__/promiseBeforeAll.test.js @@ -15,7 +15,7 @@ describe('promise beforeAll', () => { process.nextTick(resolve); }).then(() => { flag = 1; - }) + }), ); beforeAll(() => new Promise(resolve => setTimeout(resolve, 10)), 500); diff --git a/e2e/jasmine-async/__tests__/promiseBeforeEach.test.js b/e2e/jasmine-async/__tests__/promiseBeforeEach.test.js index 846eeb8e6636..45c16c2ef6de 100644 --- a/e2e/jasmine-async/__tests__/promiseBeforeEach.test.js +++ b/e2e/jasmine-async/__tests__/promiseBeforeEach.test.js @@ -13,7 +13,7 @@ describe('promise beforeEach', () => { process.nextTick(resolve); }).then(() => { this.flag = 1; - }) + }), ); // passing tests diff --git a/e2e/jasmine-async/__tests__/promiseIt.test.js b/e2e/jasmine-async/__tests__/promiseIt.test.js index aa688659a7d9..c02d38788494 100644 --- a/e2e/jasmine-async/__tests__/promiseIt.test.js +++ b/e2e/jasmine-async/__tests__/promiseIt.test.js @@ -31,7 +31,7 @@ describe('promise it', () => { new Promise(resolve => { if (this.someContextValue !== 'value') { throw new Error( - 'expected this.someContextValue to be set: ' + this.someContextValue + 'expected this.someContextValue to be set: ' + this.someContextValue, ); } resolve(); @@ -90,13 +90,13 @@ describe('promise it', () => { it( 'succeeds if the test finishes in time', () => new Promise(resolve => setTimeout(resolve, 10)), - 250 + 250, ); // failing tests it( 'fails if a custom timeout is exceeded', () => new Promise(resolve => setTimeout(resolve, 100)), - 10 + 10, ); }); diff --git a/e2e/native-esm/__tests__/native-esm.test.js b/e2e/native-esm/__tests__/native-esm.test.js index 05dc9e5fc328..0603e5d67e1d 100644 --- a/e2e/native-esm/__tests__/native-esm.test.js +++ b/e2e/native-esm/__tests__/native-esm.test.js @@ -21,7 +21,7 @@ test('should have correct import.meta', () => { url: expect.any(String), }); expect( - import.meta.url.endsWith('/e2e/native-esm/__tests__/native-esm.test.js') + import.meta.url.endsWith('/e2e/native-esm/__tests__/native-esm.test.js'), ).toBe(true); }); diff --git a/e2e/reset-modules/__tests__/resetModules.test.js b/e2e/reset-modules/__tests__/resetModules.test.js index 01eea7be6e20..f0d09ff11d8c 100644 --- a/e2e/reset-modules/__tests__/resetModules.test.js +++ b/e2e/reset-modules/__tests__/resetModules.test.js @@ -12,7 +12,7 @@ global.testObject = new Proxy( get: function getter(target, key) { return key; }, - } + }, ); test('jest.resetModules should not error when _isMockFunction is defined but not boolean', () => { jest.resetModules(); diff --git a/e2e/resolve-with-paths/__tests__/resolveWithPaths.test.js b/e2e/resolve-with-paths/__tests__/resolveWithPaths.test.js index 43a4dd97402e..f6891ea61742 100644 --- a/e2e/resolve-with-paths/__tests__/resolveWithPaths.test.js +++ b/e2e/resolve-with-paths/__tests__/resolveWithPaths.test.js @@ -10,19 +10,19 @@ import {resolve} from 'path'; test('finds a module relative to one of the given paths', () => { expect(require.resolve('./mod.js', {paths: ['../dir']})).toEqual( - resolve(__dirname, '..', 'dir', 'mod.js') + resolve(__dirname, '..', 'dir', 'mod.js'), ); }); test('finds a module without a leading "./" relative to one of the given paths', () => { expect(require.resolve('mod.js', {paths: ['../dir']})).toEqual( - resolve(__dirname, '..', 'dir', 'mod.js') + resolve(__dirname, '..', 'dir', 'mod.js'), ); }); test('finds a node_module above one of the given paths', () => { expect(require.resolve('mod', {paths: ['../dir']})).toEqual( - resolve(__dirname, '..', 'node_modules', 'mod', 'index.js') + resolve(__dirname, '..', 'node_modules', 'mod', 'index.js'), ); }); @@ -32,12 +32,12 @@ test('finds a native node module when paths are given', () => { test('throws an error if the module cannot be found from given paths', () => { expect(() => require.resolve('./mod.js', {paths: ['..']})).toThrowError( - "Cannot resolve module './mod.js' from paths ['..'] from " + "Cannot resolve module './mod.js' from paths ['..'] from ", ); }); test('throws module not found error if the module cannot be found from given paths', () => { expect(() => require.resolve('./mod.js', {paths: ['..']})).toThrow( - expect.objectContaining({code: 'MODULE_NOT_FOUND'}) + expect.objectContaining({code: 'MODULE_NOT_FOUND'}), ); }); diff --git a/e2e/resolve/__tests__/resolve.test.js b/e2e/resolve/__tests__/resolve.test.js index bd993a99f8aa..e3d3500d6b8c 100644 --- a/e2e/resolve/__tests__/resolve.test.js +++ b/e2e/resolve/__tests__/resolve.test.js @@ -66,7 +66,7 @@ test('should resolve filename.json', () => { test('should preserve identity for symlinks', () => { expect(require('../../../packages/jest-resolve')).toBe( - require('jest-resolve') + require('jest-resolve'), ); }); @@ -113,7 +113,7 @@ test('should throw module not found error if the module has dependencies that ca Test7.js __tests__/resolve.test.js\n `, - }) + }), ); }); @@ -122,6 +122,6 @@ test('should throw module not found error if the module cannot be found', () => expect.objectContaining({ code: 'MODULE_NOT_FOUND', message: "Cannot find module 'Test8' from 'resolve.test.js'", - }) + }), ); }); diff --git a/e2e/snapshot/__tests__/snapshot.test.js b/e2e/snapshot/__tests__/snapshot.test.js index 22722a34f77d..280d16caba18 100644 --- a/e2e/snapshot/__tests__/snapshot.test.js +++ b/e2e/snapshot/__tests__/snapshot.test.js @@ -30,7 +30,7 @@ describe('snapshot', () => { it('cannot be used with .not', () => { expect(() => expect('').not.toMatchSnapshot()).toThrow( - 'Snapshot matchers cannot be used with not' + 'Snapshot matchers cannot be used with not', ); }); diff --git a/e2e/typescript-coverage/typescriptPreprocessor.js b/e2e/typescript-coverage/typescriptPreprocessor.js index f70981612673..8633bdab5a95 100644 --- a/e2e/typescript-coverage/typescriptPreprocessor.js +++ b/e2e/typescript-coverage/typescriptPreprocessor.js @@ -17,7 +17,7 @@ module.exports = { module: tsc.ModuleKind.CommonJS, }, path, - [] + [], ); } return src; diff --git a/examples/angular/app.component.spec.ts b/examples/angular/app.component.spec.ts index acd80ab8fd2d..86136edd82f6 100644 --- a/examples/angular/app.component.spec.ts +++ b/examples/angular/app.component.spec.ts @@ -8,7 +8,7 @@ const getTitleFn = jest.fn().mockReturnValue(title); const dataServiceSpy = jest.fn().mockImplementation( (): Partial => ({ getTitle: getTitleFn, - }) + }), ); describe('AppComponent', () => { @@ -36,7 +36,7 @@ describe('AppComponent', () => { fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelector('h1').textContent).toContain( - `Welcome to ${title}!` + `Welcome to ${title}!`, ); }); }); diff --git a/examples/angular/setupJest.js b/examples/angular/setupJest.js index c8a41202d6e7..64db898071a7 100644 --- a/examples/angular/setupJest.js +++ b/examples/angular/setupJest.js @@ -14,5 +14,5 @@ const testingModule = require('@angular/platform-browser-dynamic/testing'); getTestBed().initTestEnvironment( testingModule.BrowserDynamicTestingModule, - testingModule.platformBrowserDynamicTesting() + testingModule.platformBrowserDynamicTesting(), ); diff --git a/examples/async/__mocks__/request.js b/examples/async/__mocks__/request.js index 51784974d8fa..e593301d672f 100644 --- a/examples/async/__mocks__/request.js +++ b/examples/async/__mocks__/request.js @@ -15,7 +15,7 @@ export default function request(url) { ? resolve(users[userID]) : reject({ error: 'User with ' + userID + ' not found.', - }) + }), ); }); } diff --git a/examples/async/__tests__/user.test.js b/examples/async/__tests__/user.test.js index 2e02f9e727dc..a81de93b1cd4 100644 --- a/examples/async/__tests__/user.test.js +++ b/examples/async/__tests__/user.test.js @@ -45,7 +45,7 @@ test('tests error with promises', async () => { return user.getUserName(2).catch(e => expect(e).toEqual({ error: 'User with 2 not found.', - }) + }), ); }); diff --git a/examples/manual-mocks/__tests__/file_summarizer.test.js b/examples/manual-mocks/__tests__/file_summarizer.test.js index d097ab7cdb73..2429e47acf5c 100644 --- a/examples/manual-mocks/__tests__/file_summarizer.test.js +++ b/examples/manual-mocks/__tests__/file_summarizer.test.js @@ -18,7 +18,7 @@ describe('listFilesInDirectorySync', () => { it('includes all files in the directory in the summary', () => { const FileSummarizer = require('../FileSummarizer'); const fileSummary = FileSummarizer.summarizeFilesInDirectorySync( - '/path/to' + '/path/to', ); expect(fileSummary.length).toBe(2); diff --git a/examples/react-native/__tests__/intro.test.js b/examples/react-native/__tests__/intro.test.js index ebb1100b6d2c..a1d246799fe1 100644 --- a/examples/react-native/__tests__/intro.test.js +++ b/examples/react-native/__tests__/intro.test.js @@ -52,7 +52,7 @@ it('renders the FlatList component', () => { data={['apple', 'banana', 'kiwi']} keyExtractor={item => item} renderItem={({item}) => {item}} - /> + />, ) .toJSON(); expect(tree).toMatchSnapshot(); diff --git a/examples/react-testing-library/__tests__/CheckboxWithLabel-test.js b/examples/react-testing-library/__tests__/CheckboxWithLabel-test.js index 73aeeb99f4e6..cfc95680c90b 100644 --- a/examples/react-testing-library/__tests__/CheckboxWithLabel-test.js +++ b/examples/react-testing-library/__tests__/CheckboxWithLabel-test.js @@ -10,7 +10,7 @@ afterEach(cleanup); it('CheckboxWithLabel changes the text after click', () => { const {queryByLabelText, getByLabelText} = render( - + , ); expect(queryByLabelText(/off/i)).toBeTruthy(); diff --git a/examples/react/__tests__/CheckboxWithLabel-test.js b/examples/react/__tests__/CheckboxWithLabel-test.js index 494504ca9cc5..b887304d42aa 100644 --- a/examples/react/__tests__/CheckboxWithLabel-test.js +++ b/examples/react/__tests__/CheckboxWithLabel-test.js @@ -15,7 +15,7 @@ it('CheckboxWithLabel changes the text after click', () => { inputRef={checkboxInputRef} labelOn="On" labelOff="Off" - /> + />, ); const labelNode = checkboxLabelRef.current; diff --git a/examples/snapshot/__tests__/link.react.test.js b/examples/snapshot/__tests__/link.react.test.js index fd9b87115c42..1d9300b82772 100644 --- a/examples/snapshot/__tests__/link.react.test.js +++ b/examples/snapshot/__tests__/link.react.test.js @@ -27,7 +27,7 @@ it('properly escapes quotes', () => { it('changes the class when hovered', () => { const component = renderer.create( - Facebook + Facebook, ); let tree = component.toJSON(); expect(tree).toMatchSnapshot(); diff --git a/examples/typescript/__tests__/CheckboxWithLabel-test.tsx b/examples/typescript/__tests__/CheckboxWithLabel-test.tsx index 59afe50a027f..85159d2d4b15 100644 --- a/examples/typescript/__tests__/CheckboxWithLabel-test.tsx +++ b/examples/typescript/__tests__/CheckboxWithLabel-test.tsx @@ -15,7 +15,7 @@ it('CheckboxWithLabel changes the text after click', () => { inputRef={checkboxInputRef} labelOn="On" labelOff="Off" - /> + />, ); const labelNode = checkboxLabelRef.current; diff --git a/package.json b/package.json index 337123a5d1f9..3e5841ea2d8c 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "realpath-native": "^2.0.0", "resolve": "^1.15.0", "rimraf": "^3.0.0", + "semver": "^6.3.0", "slash": "^3.0.0", "string-length": "^3.1.0", "strip-ansi": "^6.0.0", @@ -126,22 +127,8 @@ "arrowParens": "avoid", "overrides": [ { - "excludeFiles": [ - "e2e/__tests__/**/*", - "website/versioned_docs/**/*.md" - ], - "files": [ - "examples/**/*", - "scripts/**/*", - "e2e/*/**/*", - "website/*.js", - "website/*/**/*", - "eslintImportResolver.js", - "babel.config.js" - ], + "files": "website/**/*.js", "options": { - "printWidth": 80, - "singleQuote": true, "trailingComma": "es5" } } diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 5bf8cb86877e..763858ae640b 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -19,5 +19,8 @@ "ansi-regex": "^5.0.0", "ansi-styles": "^4.1.0", "semver": "^6.3.0" + }, + "engines": { + "node": ">= 8.3" } } diff --git a/scripts/babel-plugin-jest-native-globals.js b/scripts/babel-plugin-jest-native-globals.js index c1e60921917a..148a8eeb22e3 100644 --- a/scripts/babel-plugin-jest-native-globals.js +++ b/scripts/babel-plugin-jest-native-globals.js @@ -70,7 +70,7 @@ module.exports = ({template}) => { path.node.name === 'fs' && path.parent.property && ['readFileSync', 'writeFileSync', 'existsSync'].includes( - path.parent.property.name + path.parent.property.name, ) ) { if ( diff --git a/scripts/babel-plugin-jest-replace-ts-require-assignment.js b/scripts/babel-plugin-jest-replace-ts-require-assignment.js index 72451255239b..aeb5ddd2aaf1 100644 --- a/scripts/babel-plugin-jest-replace-ts-require-assignment.js +++ b/scripts/babel-plugin-jest-replace-ts-require-assignment.js @@ -23,7 +23,7 @@ module.exports = ({template}) => { moduleExportsDeclaration({ IMPORT: node.moduleReference.expression, NAME: node.id, - }) + }), ); }, }, diff --git a/scripts/browserBuild.js b/scripts/browserBuild.js index a335d47ca206..4c3257380c71 100644 --- a/scripts/browserBuild.js +++ b/scripts/browserBuild.js @@ -62,7 +62,7 @@ function browserBuild(pkgName, entryPath, destination) { alias: { chalk: path.resolve( __dirname, - '../packages/expect/build/fakeChalk.js' + '../packages/expect/build/fakeChalk.js', ), }, extensions: ['.js', '.json', '.ts'], @@ -78,7 +78,7 @@ function browserBuild(pkgName, entryPath, destination) { return; } resolve(stats); - } + }, ); }); } diff --git a/scripts/build.js b/scripts/build.js index ff06ba44adf0..7c5e0f5c3ba7 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -84,7 +84,7 @@ function buildBrowserPackage(p) { if (browser) { if (browser.indexOf(BUILD_ES5_DIR) !== 0) { throw new Error( - `browser field for ${pkgJsonPath} should start with "${BUILD_ES5_DIR}"` + `browser field for ${pkgJsonPath} should start with "${BUILD_ES5_DIR}"`, ); } let indexFile = path.resolve(srcDir, 'index.js'); @@ -113,7 +113,7 @@ function buildFile(file, silent) { process.stdout.write( chalk.dim(' \u2022 ') + path.relative(PACKAGES_DIR, file) + - ' (ignore)\n' + ' (ignore)\n', ); return; } @@ -131,7 +131,7 @@ function buildFile(file, silent) { chalk.red(' \u21D2 ') + path.relative(PACKAGES_DIR, destPath) + ' (copy)' + - '\n' + '\n', ); } else { const options = Object.assign({}, transformOptions); @@ -141,7 +141,7 @@ function buildFile(file, silent) { // The modules in the blacklist are injected into the user's sandbox // We need to guard some globals there. options.plugins.push( - require.resolve('./babel-plugin-jest-native-globals') + require.resolve('./babel-plugin-jest-native-globals'), ); } else { options.plugins = options.plugins.map(plugin => { @@ -174,7 +174,7 @@ function buildFile(file, silent) { path.relative(PACKAGES_DIR, file) + chalk.green(' \u21D2 ') + path.relative(PACKAGES_DIR, destPath) + - '\n' + '\n', ); } } diff --git a/scripts/buildTs.js b/scripts/buildTs.js index cf734188267e..af57239ed718 100644 --- a/scripts/buildTs.js +++ b/scripts/buildTs.js @@ -7,6 +7,7 @@ 'use strict'; +const assert = require('assert'); const fs = require('fs'); const os = require('os'); const path = require('path'); @@ -20,25 +21,23 @@ const {getPackages} = require('./buildUtils'); const packages = getPackages(); const packagesWithTs = packages.filter(p => - fs.existsSync(path.resolve(p, 'tsconfig.json')) + fs.existsSync(path.resolve(p, 'tsconfig.json')), ); packagesWithTs.forEach(pkgDir => { const pkg = require(pkgDir + '/package.json'); - if (!pkg.types) { - throw new Error(`Package ${pkg.name} is missing \`types\` field`); - } - - if (!pkg.typesVersions) { - throw new Error(`Package ${pkg.name} is missing \`typesVersions\` field`); - } + assert.ok(pkg.types, `Package ${pkg.name} is missing \`types\` field`); + assert.ok( + pkg.typesVersions, + `Package ${pkg.name} is missing \`typesVersions\` field`, + ); - if (pkg.main.replace(/\.js$/, '.d.ts') !== pkg.types) { - throw new Error( - `\`main\` and \`types\` field of ${pkg.name} does not match` - ); - } + assert.equal( + pkg.types, + pkg.main.replace(/\.js$/, '.d.ts'), + `\`main\` and \`types\` field of ${pkg.name} does not match`, + ); }); const args = [ @@ -54,11 +53,11 @@ console.log(chalk.inverse(' Building TypeScript definition files ')); try { execa.sync('yarn', args, {stdio: 'inherit'}); console.log( - chalk.inverse.green(' Successfully built TypeScript definition files ') + chalk.inverse.green(' Successfully built TypeScript definition files '), ); } catch (e) { console.error( - chalk.inverse.red(' Unable to build TypeScript definition files ') + chalk.inverse.red(' Unable to build TypeScript definition files '), ); console.error(e.stack); process.exitCode = 1; @@ -79,19 +78,19 @@ Promise.all( rimraf.sync(path.resolve(pkgDir, 'build/ts3.4')); return execa('yarn', downlevelArgs, {cwd: pkgDir, stdio: 'inherit'}); - }) - ) + }), + ), ) .then(() => { console.log( chalk.inverse.green( - ' Successfully downleveled TypeScript definition files ' - ) + ' Successfully downleveled TypeScript definition files ', + ), ); }) .catch(e => { console.error( - chalk.inverse.red(' Unable to downlevel TypeScript definition files ') + chalk.inverse.red(' Unable to downlevel TypeScript definition files '), ); console.error(e.stack); process.exitCode = 1; diff --git a/scripts/buildUtils.js b/scripts/buildUtils.js index 0e0775795cc4..90e9bb71bc4a 100644 --- a/scripts/buildUtils.js +++ b/scripts/buildUtils.js @@ -5,10 +5,14 @@ * LICENSE file in the root directory of this source tree. */ +'use strict'; + +const assert = require('assert'); const fs = require('fs'); const path = require('path'); const chalk = require('chalk'); const stringLength = require('string-length'); +const rootPackage = require('../package.json'); const PACKAGES_DIR = path.resolve(__dirname, '../packages'); @@ -16,10 +20,26 @@ const OK = chalk.reset.inverse.bold.green(' DONE '); // Get absolute paths of all directories under packages/* module.exports.getPackages = function getPackages() { - return fs + const packages = fs .readdirSync(PACKAGES_DIR) .map(file => path.resolve(PACKAGES_DIR, file)) .filter(f => fs.lstatSync(path.resolve(f)).isDirectory()); + + const nodeEngineRequiremnt = rootPackage.engines.node; + + packages.forEach(packageDir => { + const pkg = require(`${packageDir}/package.json`); + + assert.ok(pkg.engines, `Engine requirement in ${pkg.name} should exist`); + + assert.equal( + pkg.engines.node, + nodeEngineRequiremnt, + `Engine requirement in ${pkg.name} should match root`, + ); + }); + + return packages; }; module.exports.adjustToTerminalWidth = function adjustToTerminalWidth(str) { diff --git a/scripts/checkCopyrightHeaders.js b/scripts/checkCopyrightHeaders.js index 12d4eb78be3c..762d0581003c 100755 --- a/scripts/checkCopyrightHeaders.js +++ b/scripts/checkCopyrightHeaders.js @@ -140,7 +140,7 @@ function check() { !IGNORED_PATTERNS.some(pattern => pattern.test(file)) && !isDirectory(file) && !isBinaryFileSync(file) && - needsCopyrightHeader(file) + needsCopyrightHeader(file), ); if (invalidFiles.length > 0) { diff --git a/scripts/mapCoverage.js b/scripts/mapCoverage.js index deab981034f4..ce146ce8c855 100644 --- a/scripts/mapCoverage.js +++ b/scripts/mapCoverage.js @@ -35,17 +35,17 @@ const map = istanbulCoverage.createCoverageMap(); const mapFileCoverage = fileCoverage => { fileCoverage.path = fileCoverage.path.replace( /(.*packages\/.*\/)(build)(\/.*)/, - '$1src$3' + '$1src$3', ); return fileCoverage; }; Object.keys(coverage).forEach(filename => - map.addFileCoverage(mapFileCoverage(coverage[filename])) + map.addFileCoverage(mapFileCoverage(coverage[filename])), ); const context = istanbulReport.createContext({coverageMap: map}); ['json', 'lcov', 'text'].forEach(reporter => - istanbulReports.create(reporter, {}).execute(context) + istanbulReports.create(reporter, {}).execute(context), ); diff --git a/scripts/verifyOldTs.js b/scripts/verifyOldTs.js index 34fbbd670a6b..e1d864cd77ca 100644 --- a/scripts/verifyOldTs.js +++ b/scripts/verifyOldTs.js @@ -35,16 +35,16 @@ try { execa.sync('yarn', ['add', 'typescript@~3.4'], {cwd, stdio: 'inherit'}); fs.writeFileSync( path.join(cwd, 'tsconfig.json'), - JSON.stringify(tsConfig, null, 2) + JSON.stringify(tsConfig, null, 2), ); fs.writeFileSync( path.join(cwd, 'index.ts'), - `import jest = require('${jestDirectory}');` + `import jest = require('${jestDirectory}');`, ); execa.sync('yarn', ['tsc', '--project', '.'], {cwd, stdio: 'inherit'}); console.log( - chalk.inverse.green(' Successfully compiled Jest with TypeScript 3.4 ') + chalk.inverse.green(' Successfully compiled Jest with TypeScript 3.4 '), ); } finally { rimraf.sync(cwd); diff --git a/scripts/watch.js b/scripts/watch.js index 0f04a8342d3a..5af9c3ee9b50 100644 --- a/scripts/watch.js +++ b/scripts/watch.js @@ -34,7 +34,7 @@ chokidar { ignoreInitial: true, ignored: /(^|[\/\\])\../, // ignore dotfiles - } + }, ) .on('all', (event, filePath) => { if ( @@ -43,7 +43,7 @@ chokidar ) { console.log( chalk.green('->'), - `${event}: ${path.relative(PACKAGES_DIR, filePath)}` + `${event}: ${path.relative(PACKAGES_DIR, filePath)}`, ); rebuild(filePath); } else { @@ -51,7 +51,7 @@ chokidar const buildFile = filePath .replace( path.join(path.sep, 'src', path.sep), - path.join(path.sep, 'build', path.sep) + path.join(path.sep, 'build', path.sep), ) .replace(/\.ts$/, '.js'); try { @@ -59,8 +59,8 @@ chokidar process.stdout.write( `${chalk.red(' \u2022 ')}${path.relative( PACKAGES_DIR, - buildFile - )} (deleted)\n` + buildFile, + )} (deleted)\n`, ); } catch (e) {} }