From ff469e09c46bd86f80b3c9c5d0520cc306c7089b Mon Sep 17 00:00:00 2001 From: Recca Tsai Date: Thu, 28 Sep 2017 19:56:24 +0800 Subject: [PATCH] --showConfig change to show all config, jest-editor-support fails (#4494) * --showConfig to show all project configs #4078 * return configs * new method getConfigs * new method getConfigs * call completed * eslint --- packages/jest-editor-support/src/Settings.js | 13 +++++-- .../src/__tests__/settings.test.js | 35 +++++++++++++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 5b7a3c46bd0b..36f93e98d283 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -54,19 +54,19 @@ export default class Settings extends EventEmitter { }; } - getConfig(completed: any) { + getConfigs(completed: any) { this.getConfigProcess = this._createProcess(this.workspace, [ '--showConfig', ]); 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; }); // They could have an older build of Jest which @@ -75,4 +75,11 @@ export default class Settings extends EventEmitter { completed(); }); } + + getConfig(completed: any) { + this.getConfigs(() => { + 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 e0372357c29c..90ad492eea94 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.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( 'root_path', @@ -34,9 +63,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', }; @@ -52,7 +81,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', () => {