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

[Feature Request] Add success condition all but first #280

Closed
woody34 opened this issue May 31, 2021 · 3 comments · Fixed by #318
Closed

[Feature Request] Add success condition all but first #280

woody34 opened this issue May 31, 2021 · 3 comments · Fixed by #318

Comments

@woody34
Copy link

woody34 commented May 31, 2021

Description

I would like to add a third success condition that would allow you to spin up a service, complete a list of tasks in parallel, capture their exit status. Assuming all tasks exited successfully, exit application with success status.

Use case

I currently use concurrently to spin up storybook and complete cypress tests against a component library. I would like to be able to also perform jest visual regression tests.

Proposed Use Case

const concurrently = require('concurrently');
const waitForStorybook = 'npx wait-on http://localhost:6006/';
concurrently(
	[
		{ name: 'Storybook', command: 'npm:sb', prefixColor: 'bgMagenta.bold' },
		{ name: 'Cypress', command: `${waitForStorybook} && npm run test:cypress:run`, prefixColor: 'bgGreen.bold' },
		{ name: 'Jest', command: `${waitForStorybook} && npm run test:unit`, prefixColor: 'bgBlue.bold' },
	],
	{
		prefix: 'name',
		successCondition: 'all-but-first',
	},
)
	.catch(console.error);

I am currently nesting concurrently calls to achieve this behavior and it doesn't provide the best logs.

Proposed Acceptance Criteria

  1. run 3 tasks concurrently
  2. once task 2 and 3 complete with success, exit app with success
@woody34
Copy link
Author

woody34 commented May 31, 2021

// src/completion-listener.js
...
isSuccess(exitCodes) {
        switch (this.successCondition) {
        /* eslint-disable indent */
            case 'first':
                return exitCodes[0] === 0;

            case 'last':
                return exitCodes[exitCodes.length - 1] === 0;

            case 'all-but-first':
                const [, ...allButFirst] = exitCodes;
                return allButFirst.every(code => code === 0);

            default:
                return exitCodes.every(exitCode => exitCode === 0);
            /* eslint-enable indent */
        }
    }
...
// src/completion-listener.spec.js
...
describe('with success condition set to all-but-first', () => {
    beforeEach(() => {
        commands.push(createFakeCommand('oof'));
    });

    it('succeeds if all but first process to exit has code 0', () => {
        const result = createController('all-but-first').listen(commands);

        commands[0].close.next({ exitCode: 1 });
        commands[1].close.next({ exitCode: 0 });
        commands[2].close.next({ exitCode: 0 });

        scheduler.flush();

        return expect(result).resolves.toEqual([{ exitCode: 1 }, { exitCode: 0 }, { exitCode: 0 }]);
    });

    it('fails if last process to exit has non-0 code', () => {
        const result = createController('first').listen(commands);

        commands[0].close.next({ exitCode: 1 });
        commands[1].close.next({ exitCode: 0 });
        commands[2].close.next({ exitCode: 1 });

        scheduler.flush();

        return expect(result).rejects.toEqual([{ exitCode: 1 }, { exitCode: 0 }, { exitCode: 1 }]);
    });
});

@gustavohenke
Copy link
Member

hey @woody34, I'm sorry that you gave up with your PR 😢
I put up a new PR for this, #318. It implements a more flexible/future-proof syntax for --success flag.

@gustavohenke
Copy link
Member

Heya, v7.2.0 is shipped with an alternative for this! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants