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 change to show all config, jest-editor-support fails #4494

Merged
merged 6 commits into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -55,19 +55,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 @@ -76,4 +76,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 @@ -27,6 +27,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 @@ -35,9 +64,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 @@ -53,7 +82,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