Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--showConfig support jest20 and jest21 #4575

Merged
merged 18 commits into from
Oct 1, 2017
4 changes: 3 additions & 1 deletion packages/jest-editor-support/src/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,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();
});
}
Expand Down
50 changes: 40 additions & 10 deletions packages/jest-editor-support/src/__tests__/settings.test.js
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please bring back the old license header? Thanks.

* 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
*/
Expand All @@ -26,17 +27,17 @@ 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',
'test',
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',
};

Expand All @@ -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 config', () => {
const workspace = new ProjectWorkspace(
'root_path',
'path_to_jest',
Expand All @@ -66,7 +67,7 @@ describe('Settings', () => {
const configs = [{cacheDirectory: '/tmp/jest', name: '[md5 hash]'}];
const json = {
configs,
version: '19.0.0',
version: '21.0.0',
};

const mockProcess: any = new EventEmitter();
Expand All @@ -80,10 +81,39 @@ describe('Settings', () => {
settings.getConfigProcess.emit('close');

expect(completed).toHaveBeenCalled();
expect(settings.jestVersionMajor).toBe(19);
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',
'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.getConfigs(completed);
settings.getConfigProcess.stdout.emit('data', buffer);
settings.getConfigProcess.emit('close');

expect(completed).toHaveBeenCalled();
expect(settings.jestVersionMajor).toBe(21);
expect(settings.settings).toEqual(configs);
});

it('calls callback even if no data is sent', () => {
const workspace = new ProjectWorkspace(
'root_path',
Expand Down