From 1188a85a01377c69c2f97293ab337cfd48b72854 Mon Sep 17 00:00:00 2001 From: Recca Tsai Date: Sat, 16 Sep 2017 23:34:37 +0800 Subject: [PATCH 01/17] --showConfig to show all project configs #4078 --- packages/jest-editor-support/src/Settings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 7d5a747011ba..4426763aec68 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -61,13 +61,13 @@ export default class Settings extends EventEmitter { ]); this.getConfigProcess.stdout.on('data', (data: Buffer) => { - const {config, version} = JSON.parse(data.toString()); + const {configs, version} = JSON.parse(data.toString()); // We can give warnings to versions under 17 now // See https://github.com/facebook/jest/issues/2343 for moving this into // the config object this.jestVersionMajor = parseInt(version.split('.').shift(), 10); - this.settings = config; + this.settings = configs[0]; }); // They could have an older build of Jest which From 3941ce2e4de1876bd1aefdd715f51dc83ce730df Mon Sep 17 00:00:00 2001 From: Recca Tsai Date: Sun, 17 Sep 2017 00:02:51 +0800 Subject: [PATCH 02/17] return configs --- packages/jest-editor-support/src/__tests__/settings.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/jest-editor-support/src/__tests__/settings.test.js b/packages/jest-editor-support/src/__tests__/settings.test.js index bff0eef30faa..81ff24853a18 100644 --- a/packages/jest-editor-support/src/__tests__/settings.test.js +++ b/packages/jest-editor-support/src/__tests__/settings.test.js @@ -35,9 +35,9 @@ describe('Settings', () => { 1000, ); const completed = jest.fn(); - const config = {cacheDirectory: '/tmp/jest', name: '[md5 hash]'}; + const configs = [{cacheDirectory: '/tmp/jest', name: '[md5 hash]'}]; const json = { - config, + configs, version: '19.0.0', }; @@ -53,7 +53,7 @@ describe('Settings', () => { expect(completed).toHaveBeenCalled(); expect(settings.jestVersionMajor).toBe(19); - expect(settings.settings).toEqual(config); + expect(settings.settings).toEqual(configs[0]); }); it('calls callback even if no data is sent', () => { From b3932f5e23f3dd2d8b350ed71f3709d4a9c1c178 Mon Sep 17 00:00:00 2001 From: Recca Tsai Date: Sun, 17 Sep 2017 02:08:02 +0800 Subject: [PATCH 03/17] new method getConfigs --- packages/jest-editor-support/src/Settings.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 4426763aec68..75f77108ad02 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -55,7 +55,7 @@ export default class Settings extends EventEmitter { }; } - getConfig(completed: any) { + getConfigs(completed: any) { this.getConfigProcess = this._createProcess(this.workspace, [ '--showConfig', ]); @@ -67,7 +67,7 @@ export default class Settings extends EventEmitter { // the config object this.jestVersionMajor = parseInt(version.split('.').shift(), 10); - this.settings = configs[0]; + this.settings = configs; }); // They could have an older build of Jest which @@ -76,4 +76,10 @@ export default class Settings extends EventEmitter { completed(); }); } + + getConfig(completed: any) { + this.getConfigs(() => { + this.settings = this.settings[0]; + }) + } } From 19912a6607d993674ad19c87616dcda4139a1081 Mon Sep 17 00:00:00 2001 From: Recca Tsai Date: Sun, 17 Sep 2017 02:11:07 +0800 Subject: [PATCH 04/17] new method getConfigs --- .../src/__tests__/settings.test.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/jest-editor-support/src/__tests__/settings.test.js b/packages/jest-editor-support/src/__tests__/settings.test.js index 81ff24853a18..f4fa01446b6c 100644 --- a/packages/jest-editor-support/src/__tests__/settings.test.js +++ b/packages/jest-editor-support/src/__tests__/settings.test.js @@ -26,6 +26,35 @@ describe('Settings', () => { expect(settings.workspace).toEqual(workspace); expect(settings.settings).toEqual(expect.any(Object)); }); + + it('reads and parses the configs', () => { + const workspace = new ProjectWorkspace( + 'root_path', + 'path_to_jest', + 'test', + 1000, + ); + const completed = jest.fn(); + const configs = [{cacheDirectory: '/tmp/jest', name: '[md5 hash]'}]; + const json = { + configs, + version: '19.0.0', + }; + + const mockProcess: any = new EventEmitter(); + mockProcess.stdout = new EventEmitter(); + const createProcess = () => mockProcess; + const buffer = makeBuffer(JSON.stringify(json)); + const settings = new Settings(workspace, {createProcess}); + + settings.getConfigs(completed); + settings.getConfigProcess.stdout.emit('data', buffer); + settings.getConfigProcess.emit('close'); + + expect(completed).toHaveBeenCalled(); + expect(settings.jestVersionMajor).toBe(19); + expect(settings.settings).toEqual(configs); + }); it('reads and parses the config', () => { const workspace = new ProjectWorkspace( From fd4be030feab0c28c38e3631bf0ecafddc7d4fcd Mon Sep 17 00:00:00 2001 From: Recca Tsai Date: Sun, 17 Sep 2017 02:13:24 +0800 Subject: [PATCH 05/17] call completed --- packages/jest-editor-support/src/Settings.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 75f77108ad02..ca2c7f1ce2c2 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -80,6 +80,7 @@ export default class Settings extends EventEmitter { getConfig(completed: any) { this.getConfigs(() => { this.settings = this.settings[0]; - }) + completed(); + }); } } From 6a1aa10b6fe5f50981a1e49f37bc18520a004c61 Mon Sep 17 00:00:00 2001 From: recca0120 Date: Thu, 28 Sep 2017 10:43:01 +0800 Subject: [PATCH 06/17] eslint --- packages/jest-editor-support/src/__tests__/settings.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-editor-support/src/__tests__/settings.test.js b/packages/jest-editor-support/src/__tests__/settings.test.js index f4fa01446b6c..e2bd2cbad002 100644 --- a/packages/jest-editor-support/src/__tests__/settings.test.js +++ b/packages/jest-editor-support/src/__tests__/settings.test.js @@ -26,7 +26,7 @@ describe('Settings', () => { expect(settings.workspace).toEqual(workspace); expect(settings.settings).toEqual(expect.any(Object)); }); - + it('reads and parses the configs', () => { const workspace = new ProjectWorkspace( 'root_path', From 586bd80161dc654649cb4d19202ca76a30592dd0 Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sun, 1 Oct 2017 13:06:46 +0800 Subject: [PATCH 07/17] support jest 20 --- packages/jest-editor-support/src/Settings.js | 2 +- .../src/__tests__/settings.test.js | 27 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 36f93e98d283..c77be238f813 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -78,7 +78,7 @@ export default class Settings extends EventEmitter { getConfig(completed: any) { this.getConfigs(() => { - this.settings = this.settings[0]; + this.settings = this.settings[0] || this.settings; completed(); }); } diff --git a/packages/jest-editor-support/src/__tests__/settings.test.js b/packages/jest-editor-support/src/__tests__/settings.test.js index 90ad492eea94..57125002cda7 100644 --- a/packages/jest-editor-support/src/__tests__/settings.test.js +++ b/packages/jest-editor-support/src/__tests__/settings.test.js @@ -1,8 +1,9 @@ /** * Copyright (c) 2014-present, Facebook, Inc. 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. + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. * * @flow */ @@ -26,7 +27,7 @@ describe('Settings', () => { expect(settings.settings).toEqual(expect.any(Object)); }); - it('reads and parses the configs', () => { + it('[jest 20] reads and parses the config', () => { const workspace = new ProjectWorkspace( 'root_path', 'path_to_jest', @@ -34,9 +35,9 @@ describe('Settings', () => { 1000, ); const completed = jest.fn(); - const configs = [{cacheDirectory: '/tmp/jest', name: '[md5 hash]'}]; + const config = {cacheDirectory: '/tmp/jest', name: '[md5 hash]'}; const json = { - configs, + config, version: '19.0.0', }; @@ -46,16 +47,16 @@ describe('Settings', () => { const buffer = makeBuffer(JSON.stringify(json)); const settings = new Settings(workspace, {createProcess}); - settings.getConfigs(completed); + settings.getConfig(completed); settings.getConfigProcess.stdout.emit('data', buffer); settings.getConfigProcess.emit('close'); expect(completed).toHaveBeenCalled(); expect(settings.jestVersionMajor).toBe(19); - expect(settings.settings).toEqual(configs); + expect(settings.settings).toEqual(config); }); - - it('reads and parses the config', () => { + + it('[jest 21] reads and parses the configs', () => { const workspace = new ProjectWorkspace( 'root_path', 'path_to_jest', @@ -66,7 +67,7 @@ describe('Settings', () => { const configs = [{cacheDirectory: '/tmp/jest', name: '[md5 hash]'}]; const json = { configs, - version: '19.0.0', + version: '.0.0', }; const mockProcess: any = new EventEmitter(); @@ -75,13 +76,13 @@ describe('Settings', () => { const buffer = makeBuffer(JSON.stringify(json)); const settings = new Settings(workspace, {createProcess}); - settings.getConfig(completed); + settings.getConfigs(completed); settings.getConfigProcess.stdout.emit('data', buffer); settings.getConfigProcess.emit('close'); expect(completed).toHaveBeenCalled(); expect(settings.jestVersionMajor).toBe(19); - expect(settings.settings).toEqual(configs[0]); + expect(settings.settings).toEqual(configs); }); it('calls callback even if no data is sent', () => { @@ -112,4 +113,4 @@ const makeBuffer = (content: string) => { } return new Buffer(content); -}; +}; \ No newline at end of file From 60f29c7a0268b679eb290958dfc710d537690eba Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sun, 1 Oct 2017 13:19:10 +0800 Subject: [PATCH 08/17] lint --- packages/jest-editor-support/src/__tests__/settings.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-editor-support/src/__tests__/settings.test.js b/packages/jest-editor-support/src/__tests__/settings.test.js index 57125002cda7..40b4d1f6c2fb 100644 --- a/packages/jest-editor-support/src/__tests__/settings.test.js +++ b/packages/jest-editor-support/src/__tests__/settings.test.js @@ -55,7 +55,7 @@ describe('Settings', () => { expect(settings.jestVersionMajor).toBe(19); expect(settings.settings).toEqual(config); }); - + it('[jest 21] reads and parses the configs', () => { const workspace = new ProjectWorkspace( 'root_path', @@ -113,4 +113,4 @@ const makeBuffer = (content: string) => { } return new Buffer(content); -}; \ No newline at end of file +}; From d89539990d5a8ac1b14dc7b91bedb22a92a939ef Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sun, 1 Oct 2017 13:21:01 +0800 Subject: [PATCH 09/17] version --- packages/jest-editor-support/src/__tests__/settings.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-editor-support/src/__tests__/settings.test.js b/packages/jest-editor-support/src/__tests__/settings.test.js index 40b4d1f6c2fb..485e2a3d1af4 100644 --- a/packages/jest-editor-support/src/__tests__/settings.test.js +++ b/packages/jest-editor-support/src/__tests__/settings.test.js @@ -67,7 +67,7 @@ describe('Settings', () => { const configs = [{cacheDirectory: '/tmp/jest', name: '[md5 hash]'}]; const json = { configs, - version: '.0.0', + version: '21.0.0', }; const mockProcess: any = new EventEmitter(); From c834608f1d35292fddc635be9e67eea553e112aa Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sun, 1 Oct 2017 13:49:25 +0800 Subject: [PATCH 10/17] getConfig for jest21 --- packages/jest-editor-support/src/Settings.js | 4 ++- .../src/__tests__/settings.test.js | 31 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index c77be238f813..a46ca0826f6c 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -78,7 +78,9 @@ export default class Settings extends EventEmitter { getConfig(completed: any) { this.getConfigs(() => { - this.settings = this.settings[0] || this.settings; + if (this.jestVersionMajor >= 21) { + this.settings = this.settings[0]; + } completed(); }); } diff --git a/packages/jest-editor-support/src/__tests__/settings.test.js b/packages/jest-editor-support/src/__tests__/settings.test.js index 485e2a3d1af4..d28dd45c4bd8 100644 --- a/packages/jest-editor-support/src/__tests__/settings.test.js +++ b/packages/jest-editor-support/src/__tests__/settings.test.js @@ -56,6 +56,35 @@ describe('Settings', () => { expect(settings.settings).toEqual(config); }); + it('[jest 21] reads and parses the config', () => { + const workspace = new ProjectWorkspace( + 'root_path', + 'path_to_jest', + 'test', + 1000, + ); + const completed = jest.fn(); + const configs = [{cacheDirectory: '/tmp/jest', name: '[md5 hash]'}]; + const json = { + configs, + version: '21.0.0', + }; + + const mockProcess: any = new EventEmitter(); + mockProcess.stdout = new EventEmitter(); + const createProcess = () => mockProcess; + const buffer = makeBuffer(JSON.stringify(json)); + const settings = new Settings(workspace, {createProcess}); + + settings.getConfig(completed); + settings.getConfigProcess.stdout.emit('data', buffer); + settings.getConfigProcess.emit('close'); + + expect(completed).toHaveBeenCalled(); + expect(settings.jestVersionMajor).toBe(21); + expect(settings.settings).toEqual(configs[0]); + }); + it('[jest 21] reads and parses the configs', () => { const workspace = new ProjectWorkspace( 'root_path', @@ -81,7 +110,7 @@ describe('Settings', () => { settings.getConfigProcess.emit('close'); expect(completed).toHaveBeenCalled(); - expect(settings.jestVersionMajor).toBe(19); + expect(settings.jestVersionMajor).toBe(21); expect(settings.settings).toEqual(configs); }); From c14d2db453790f17bab0e2047bae7d2f9b413173 Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sun, 1 Oct 2017 13:54:19 +0800 Subject: [PATCH 11/17] lint --- packages/jest-editor-support/src/Settings.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index a46ca0826f6c..9599b2edc394 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -78,9 +78,9 @@ export default class Settings extends EventEmitter { getConfig(completed: any) { this.getConfigs(() => { - if (this.jestVersionMajor >= 21) { - this.settings = this.settings[0]; - } + if (this.jestVersionMajor >= 21) { + this.settings = this.settings[0]; + } completed(); }); } From 4e87ff7f5c09ddac7932045d6a68c872189c7e05 Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sun, 1 Oct 2017 17:44:58 +0800 Subject: [PATCH 12/17] fix jest20 bug --- packages/jest-editor-support/src/Settings.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 9599b2edc394..837c8d862caf 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -60,13 +60,12 @@ export default class Settings extends EventEmitter { ]); this.getConfigProcess.stdout.on('data', (data: Buffer) => { - const {configs, version} = JSON.parse(data.toString()); - // We can give warnings to versions under 17 now + const settings = JSON.parse(data.toString()); + this.jestVersionMajor = parseInt(settings.version.split('.').shift(), 10); + // We can give warnings to versions under 17 now // See https://github.com/facebook/jest/issues/2343 for moving this into // the config object - - this.jestVersionMajor = parseInt(version.split('.').shift(), 10); - this.settings = configs; + this.settings = this.jestVersionMajor >= 21 ? settings.configs : [settings.config] }); // They could have an older build of Jest which @@ -78,9 +77,7 @@ export default class Settings extends EventEmitter { getConfig(completed: any) { this.getConfigs(() => { - if (this.jestVersionMajor >= 21) { - this.settings = this.settings[0]; - } + this.settings = this.settings[0]; completed(); }); } From 531ec08c961c648a17a23a5c492f2f6bd9c40692 Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sun, 1 Oct 2017 17:54:44 +0800 Subject: [PATCH 13/17] fix bug --- packages/jest-editor-support/src/Settings.js | 7 ++----- .../jest-editor-support/src/__tests__/settings.test.js | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 837c8d862caf..8183cdca621e 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -65,7 +65,7 @@ export default class Settings extends EventEmitter { // We can give warnings to versions under 17 now // See https://github.com/facebook/jest/issues/2343 for moving this into // the config object - this.settings = this.jestVersionMajor >= 21 ? settings.configs : [settings.config] + this.settings = this.jestVersionMajor >= 21 ? settings.configs : settings.config }); // They could have an older build of Jest which @@ -76,9 +76,6 @@ export default class Settings extends EventEmitter { } getConfig(completed: any) { - this.getConfigs(() => { - this.settings = this.settings[0]; - completed(); - }); + this.getConfigs(completed); } } diff --git a/packages/jest-editor-support/src/__tests__/settings.test.js b/packages/jest-editor-support/src/__tests__/settings.test.js index d28dd45c4bd8..50fe30ec218f 100644 --- a/packages/jest-editor-support/src/__tests__/settings.test.js +++ b/packages/jest-editor-support/src/__tests__/settings.test.js @@ -1,9 +1,8 @@ /** * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. * * @flow */ From 7956948490692f2d915e2f7b013559f4018df2b1 Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sun, 1 Oct 2017 18:02:18 +0800 Subject: [PATCH 14/17] lint --- packages/jest-editor-support/src/Settings.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 8183cdca621e..35f7a3537c9f 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -62,10 +62,11 @@ export default class Settings extends EventEmitter { this.getConfigProcess.stdout.on('data', (data: Buffer) => { const settings = JSON.parse(data.toString()); this.jestVersionMajor = parseInt(settings.version.split('.').shift(), 10); - // We can give warnings to versions under 17 now + // We can give warnings to versions under 17 now // See https://github.com/facebook/jest/issues/2343 for moving this into // the config object - this.settings = this.jestVersionMajor >= 21 ? settings.configs : settings.config + this.settings = + this.jestVersionMajor >= 21 ? settings.configs : settings.config; }); // They could have an older build of Jest which From 024719fd294ca96ad671b7d9b32992b4802c0653 Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sun, 1 Oct 2017 18:15:59 +0800 Subject: [PATCH 15/17] add type ConfigRepresentations --- packages/jest-editor-support/src/Settings.js | 21 +++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 35f7a3537c9f..44bfdef5bbca 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -32,6 +32,8 @@ type ConfigRepresentation = { testMatch: Array, }; +type ConfigRepresentations = Array; + export default class Settings extends EventEmitter { getConfigProcess: ChildProcess; jestVersionMajor: number | null; @@ -39,7 +41,7 @@ export default class Settings extends EventEmitter { workspace: ProjectWorkspace, args: Array, ) => ChildProcess; - settings: ConfigRepresentation; + settings: ConfigRepresentations; workspace: ProjectWorkspace; constructor(workspace: ProjectWorkspace, options?: Options) { @@ -48,10 +50,12 @@ export default class Settings extends EventEmitter { this._createProcess = (options && options.createProcess) || createProcess; // Defaults for a Jest project - this.settings = { - testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'], - testRegex: '(/__tests__/.*|\\.(test|spec))\\.jsx?$', - }; + this.settings = [ + { + testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'], + testRegex: '(/__tests__/.*|\\.(test|spec))\\.jsx?$', + }, + ]; } getConfigs(completed: any) { @@ -66,7 +70,7 @@ export default class Settings extends EventEmitter { // See https://github.com/facebook/jest/issues/2343 for moving this into // the config object this.settings = - this.jestVersionMajor >= 21 ? settings.configs : settings.config; + this.jestVersionMajor >= 21 ? settings.configs : [settings.config]; }); // They could have an older build of Jest which @@ -77,6 +81,9 @@ export default class Settings extends EventEmitter { } getConfig(completed: any) { - this.getConfigs(completed); + this.getConfigs(() => { + this.settings = this.settings[0]; + completed(); + }); } } From f9c690af81da655fa0e50a6dac289ad40322f749 Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sun, 1 Oct 2017 18:22:23 +0800 Subject: [PATCH 16/17] remove ConfigRepresentations --- packages/jest-editor-support/src/Settings.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 44bfdef5bbca..7e6b6c8a45fd 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -32,8 +32,6 @@ type ConfigRepresentation = { testMatch: Array, }; -type ConfigRepresentations = Array; - export default class Settings extends EventEmitter { getConfigProcess: ChildProcess; jestVersionMajor: number | null; @@ -41,7 +39,7 @@ export default class Settings extends EventEmitter { workspace: ProjectWorkspace, args: Array, ) => ChildProcess; - settings: ConfigRepresentations; + settings: ConfigRepresentation; workspace: ProjectWorkspace; constructor(workspace: ProjectWorkspace, options?: Options) { @@ -50,12 +48,10 @@ export default class Settings extends EventEmitter { this._createProcess = (options && options.createProcess) || createProcess; // Defaults for a Jest project - this.settings = [ - { - testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'], - testRegex: '(/__tests__/.*|\\.(test|spec))\\.jsx?$', - }, - ]; + this.settings = { + testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'], + testRegex: '(/__tests__/.*|\\.(test|spec))\\.jsx?$', + }; } getConfigs(completed: any) { @@ -70,7 +66,7 @@ export default class Settings extends EventEmitter { // See https://github.com/facebook/jest/issues/2343 for moving this into // the config object this.settings = - this.jestVersionMajor >= 21 ? settings.configs : [settings.config]; + this.jestVersionMajor >= 21 ? settings.configs : settings.config; }); // They could have an older build of Jest which @@ -82,7 +78,9 @@ export default class Settings extends EventEmitter { getConfig(completed: any) { this.getConfigs(() => { - this.settings = this.settings[0]; + if (this.jestVersionMajor >= 21) { + this.settings = this.settings[0]; + } completed(); }); } From 5247dcd1f558420a43ceab62ab9ba025ac2c6f2c Mon Sep 17 00:00:00 2001 From: recca0120 Date: Sun, 1 Oct 2017 18:52:17 +0800 Subject: [PATCH 17/17] update --- packages/jest-editor-support/src/Settings.js | 18 +++++++++--------- .../src/__tests__/settings.test.js | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 7e6b6c8a45fd..9ad13b186346 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -32,6 +32,8 @@ type ConfigRepresentation = { testMatch: Array, }; +type ConfigRepresentations = Array; + export default class Settings extends EventEmitter { getConfigProcess: ChildProcess; jestVersionMajor: number | null; @@ -39,6 +41,7 @@ export default class Settings extends EventEmitter { workspace: ProjectWorkspace, args: Array, ) => ChildProcess; + configs: ConfigRepresentations; settings: ConfigRepresentation; workspace: ProjectWorkspace; @@ -52,6 +55,8 @@ export default class Settings extends EventEmitter { testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'], testRegex: '(/__tests__/.*|\\.(test|spec))\\.jsx?$', }; + + this.configs = [this.settings]; } getConfigs(completed: any) { @@ -62,11 +67,8 @@ export default class Settings extends EventEmitter { this.getConfigProcess.stdout.on('data', (data: Buffer) => { const settings = JSON.parse(data.toString()); this.jestVersionMajor = parseInt(settings.version.split('.').shift(), 10); - // We can give warnings to versions under 17 now - // See https://github.com/facebook/jest/issues/2343 for moving this into - // the config object - this.settings = - this.jestVersionMajor >= 21 ? settings.configs : settings.config; + this.configs = + this.jestVersionMajor >= 21 ? settings.configs : [settings.config]; }); // They could have an older build of Jest which @@ -76,11 +78,9 @@ export default class Settings extends EventEmitter { }); } - getConfig(completed: any) { + getConfig(completed: any, index: number = 0) { this.getConfigs(() => { - if (this.jestVersionMajor >= 21) { - this.settings = this.settings[0]; - } + this.settings = this.configs[index]; completed(); }); } diff --git a/packages/jest-editor-support/src/__tests__/settings.test.js b/packages/jest-editor-support/src/__tests__/settings.test.js index 50fe30ec218f..55debc02f7c1 100644 --- a/packages/jest-editor-support/src/__tests__/settings.test.js +++ b/packages/jest-editor-support/src/__tests__/settings.test.js @@ -110,7 +110,7 @@ describe('Settings', () => { expect(completed).toHaveBeenCalled(); expect(settings.jestVersionMajor).toBe(21); - expect(settings.settings).toEqual(configs); + expect(settings.configs).toEqual(configs); }); it('calls callback even if no data is sent', () => {