Skip to content

Commit

Permalink
--showConfig change to show all config, jest-editor-support fails (#4494
Browse files Browse the repository at this point in the history
)

* --showConfig to show all project configs #4078

* return configs

* new method getConfigs

* new method getConfigs

* call completed

* eslint
  • Loading branch information
recca0120 authored and cpojer committed Sep 28, 2017
1 parent 9548c16 commit ff469e0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
13 changes: 10 additions & 3 deletions packages/jest-editor-support/src/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,4 +75,11 @@ export default class Settings extends EventEmitter {
completed();
});
}

getConfig(completed: any) {
this.getConfigs(() => {
this.settings = this.settings[0];
completed();
});
}
}
35 changes: 32 additions & 3 deletions packages/jest-editor-support/src/__tests__/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
};

Expand All @@ -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', () => {
Expand Down

0 comments on commit ff469e0

Please sign in to comment.