Skip to content

Commit

Permalink
Expect executeLifecycleScript to be called properly
Browse files Browse the repository at this point in the history
  • Loading branch information
AlicanC committed Oct 28, 2016
1 parent 5b43a02 commit 46cd7b5
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 19 deletions.
68 changes: 58 additions & 10 deletions __tests__/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,78 @@ const path = require('path');

const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'run');

jest.mock('../../src/util/execute-lifecycle-script');
const executeLifecycleScript = (require('../../src/util/execute-lifecycle-script').default: $FlowFixMe);

async function runRun(
flags: Object,
args: Array<string>,
name: string,
): Promise<void> {
): Promise<Config> {
const cwd = path.join(fixturesLoc, name);
const reporter = new reporters.NoopReporter();
const config = new Config(reporter);
await config.init({cwd});
return run(config, reporter, flags, args);
await run(config, reporter, flags, args);
return config;
}

test.concurrent('run should run script', (): Promise<void> => {
return runRun({}, ['some-script'], 'run-should-run-script');
beforeEach(() => {
executeLifecycleScript.mockClear();
});

test.concurrent('run should run binary', (): Promise<void> => {
return runRun({}, ['echo'], 'run-should-run-binary');
it('run should run script', async (): Promise<void> => {
const config = await runRun({}, ['some-script'], 'run-should-run-script');

const expectedCall = [
'some-script',
config,
config.cwd,
`echo success `,
];

expect(executeLifecycleScript.mock.calls.length).toEqual(1);
expect(executeLifecycleScript).toBeCalledWith(...expectedCall);
});

test.concurrent('run should run binary with args', (): Promise<void> => {
return runRun({}, ['echo', '--test-arg'], 'run-should-run-binary-with-args');
it('run should run binary', async (): Promise<void> => {
const config = await runRun({}, ['some-binary'], 'run-should-run-binary');

const expectedCall = [
'some-binary',
config,
config.cwd,
`"${path.join(config.cwd, 'node_modules/.bin/some-binary')}" `,
];

expect(executeLifecycleScript.mock.calls.length).toEqual(1);
expect(executeLifecycleScript).toBeCalledWith(...expectedCall);
});

test.concurrent('run should run binary with space in path', (): Promise<void> => {
return runRun({}, ['echo'], 'run should run binary with space in path');
it('run should run binary with args', async (): Promise<void> => {
const config = await runRun({}, ['some-binary', '--test-arg'], 'run-should-run-binary-with-args');

const expectedCall = [
'some-binary',
config,
config.cwd,
`"${path.join(config.cwd, 'node_modules/.bin/some-binary')}" --test-arg`,
];

expect(executeLifecycleScript.mock.calls.length).toEqual(1);
expect(executeLifecycleScript).toBeCalledWith(...expectedCall);
});

it('run should run binary with space in path', async (): Promise<void> => {
const config = await runRun({}, ['some-binary'], 'run should run binary with space in path');

const expectedCall = [
'some-binary',
config,
config.cwd,
`"${path.join(config.cwd, 'node_modules/.bin/some-binary')}" `,
];

expect(executeLifecycleScript.mock.calls.length).toEqual(1);
expect(executeLifecycleScript).toBeCalledWith(...expectedCall);
});

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 46cd7b5

Please sign in to comment.