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

[dev-utils/withProcRunner] fix test that swallows promise rejection #22342

Merged
merged 3 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 0 additions & 3 deletions packages/kbn-dev-utils/src/proc_runner/__tests__/proc.sh

This file was deleted.

This file was deleted.

51 changes: 51 additions & 0 deletions packages/kbn-dev-utils/src/proc_runner/with_proc_runner.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { ToolingLog } from '../tooling_log';
import { withProcRunner } from './with_proc_runner';
import { ProcRunner } from './proc_runner';

it('passes proc runner to a function', async () => {
await withProcRunner(new ToolingLog(), async proc => {
Copy link
Member

Choose a reason for hiding this comment

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

optional nit: async proc --> proc here and tests below (await inside of withProcRunner should work fine even if callback doesn't return promise). But it's not a big deal, hence optional.

expect(proc).toBeInstanceOf(ProcRunner);
});
});

it('calls procRunner.teardown() if function resolves', async () => {
let teardownSpy;
await withProcRunner(new ToolingLog(), async proc => {
teardownSpy = jest.spyOn(proc, 'teardown');
});

expect(teardownSpy).toHaveBeenCalled();
});

it('calls procRunner.teardown() if function rejects, and rethrows the error', async () => {
const error = new Error('foo');
let teardownSpy;

await expect(
withProcRunner(new ToolingLog(), async proc => {
teardownSpy = jest.spyOn(proc, 'teardown');
throw error;
})
).rejects.toThrowError(error);

expect(teardownSpy).toHaveBeenCalled();
});