Skip to content

Commit

Permalink
Scrollable task spinner (#909)
Browse files Browse the repository at this point in the history
* feat: feat rework task spinner

* feat: fix task order

* feat: fix & stabilize e2e tests

* feat: make task-tree scroll

* feat: add tree completed component

* feat: factorize task flatener

* feat: add stats at then end

* fix: build error

* fix: remove old tests

* fix: handle no raw mode

* fix: e2e tests

* fix: remove cast

* fix: tests

* fix: lockfile

* fix: task command tests

* fix: sonarcloud review

---------

Co-authored-by: Julien Capellari <[email protected]>
  • Loading branch information
Jujulego and julien-capellari authored Nov 25, 2023
1 parent 6dfbda3 commit 684966d
Show file tree
Hide file tree
Showing 28 changed files with 535 additions and 383 deletions.
22 changes: 13 additions & 9 deletions e2e/each.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ describe('jill each', () => {
expect(res.code).toBe(0);

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run start in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run build in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run start in wks-a \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run build in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run start in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 4 done$/),
]);

// Check script result
Expand All @@ -111,13 +112,14 @@ describe('jill each', () => {
expect(res.code).toBe(0);

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. In sequence \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run build in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run start in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. In sequence \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run build in wks-a \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run start in wks-a \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. In sequence \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run build in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run start in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 5 done$/),
]);

// Check script result
Expand All @@ -144,9 +146,10 @@ describe('jill each', () => {
expect(res.code).toBe(0);

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run hooked in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run hooked in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run hooked in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 7 done$/),
]);

// Check script result
Expand Down Expand Up @@ -179,9 +182,10 @@ describe('jill each', () => {
expect(res.code).toBe(1);

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run fails in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}.( yarn exec)? node -e "process.exit\(1\)" \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 1 done, . 1 failed$/),
]);

// Check script result
Expand Down
4 changes: 4 additions & 0 deletions e2e/exec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('jill exec', () => {

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^.( yarn exec)? node -e "require\('node:fs'\).+ \(took [0-9.]+m?s\)/),
expect.ignoreColor(/^. 1 done$/),
]);

// Check script result
Expand All @@ -72,6 +73,7 @@ describe('jill exec', () => {

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^.( yarn exec)? echo toto \(took [0-9.]+m?s\)/),
expect.ignoreColor(/^. 1 done$/),
]);

expect(res.stderr).toMatchLines([
Expand All @@ -98,6 +100,7 @@ describe('jill exec', () => {

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^.( yarn exec)? node -e "process.exit\(1\)" \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 1 failed$/),
]);
});

Expand All @@ -110,6 +113,7 @@ describe('jill exec', () => {
expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^.( yarn exec)? node -e "require\('node:fs'\).+ \(took [0-9.]+m?s\)/),
expect.ignoreColor(/^. 2 done$/),
]);

// Check scripts result
Expand Down
16 changes: 13 additions & 3 deletions e2e/group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe('jill group', () => {
expect.ignoreColor(/^. In parallel \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run test1 in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run test2 in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 2 done$/),
]);

// Check script result
Expand All @@ -95,6 +96,7 @@ describe('jill group', () => {
expect.ignoreColor(/^ {2}. Run test1 in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run fails in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {4}.( yarn exec)? node -e "process.exit\(1\)" \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 1 done, . 1 failed$/),
]);

// Check script result
Expand All @@ -109,10 +111,11 @@ describe('jill group', () => {
expect(res.code).toBe(0);

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. In parallel \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run test1 in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run test2 in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 3 done$/),
]);

// Check script result
Expand All @@ -135,6 +138,7 @@ describe('jill group', () => {
expect.ignoreColor(/^. In sequence \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run test1 in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run test2 in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 2 done$/),
]);

// Check script result
Expand All @@ -153,6 +157,7 @@ describe('jill group', () => {
expect.ignoreColor(/^ {2}. Run test1 in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run fails in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {4}.( yarn exec)? node -e "process.exit\(1\)" \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 1 done, . 1 failed$/),
]);

// Check script result
Expand All @@ -167,10 +172,11 @@ describe('jill group', () => {
expect(res.code).toBe(0);

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. In sequence \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run test1 in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run test2 in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 3 done$/),
]);

// Check script result
Expand All @@ -193,6 +199,7 @@ describe('jill group', () => {
expect.ignoreColor(/^. Fallbacks \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run test1 in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run fails in wks-c$/),
expect.ignoreColor(/^. 1 done$/),
]);

// Check script result
Expand All @@ -211,6 +218,7 @@ describe('jill group', () => {
expect.ignoreColor(/^ {2}. Run fails in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {4}.( yarn exec)? node -e "process.exit\(1\)" \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run test2 in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 1 done, . 1 failed$/),
]);

// Check script result
Expand All @@ -230,6 +238,7 @@ describe('jill group', () => {
expect.ignoreColor(/^ {4}.( yarn exec)? node -e "process.exit\(1\)" \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run fails2 in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {4}.( yarn exec)? node -e "process.exit\(1\)" \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 2 failed/),
]);
});

Expand All @@ -240,11 +249,12 @@ describe('jill group', () => {
expect(res.code).toBe(0);

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Fallbacks \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run fails in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {4}.( yarn exec)? node -e "process.exit\(1\)" \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run test2 in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 2 done, . 1 failed$/),
]);

// Check script result
Expand Down
8 changes: 7 additions & 1 deletion e2e/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('jill run', () => {

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run start in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 1 done$/),
]);

// Check script result
Expand All @@ -89,6 +90,7 @@ describe('jill run', () => {
expect.ignoreColor(/^. In sequence \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run start in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 2 done$/),
]);

// Check script result
Expand All @@ -107,6 +109,7 @@ describe('jill run', () => {

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run hooked in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 3 done$/),
]);

// Check script result
Expand All @@ -129,6 +132,7 @@ describe('jill run', () => {
expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run fails in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}.( yarn exec)? node -e "process.exit\(1\)" \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 1 failed$/),
]);
});

Expand All @@ -143,6 +147,7 @@ describe('jill run', () => {
expect.ignoreColor(/^ {2}. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {2}. Run fails in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^ {4}.( yarn exec)? node -e "process.exit\(1\)" \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 1 done, . 1 failed$/),
]);
});

Expand All @@ -164,8 +169,9 @@ describe('jill run', () => {
expect(res.code).toBe(0);

expect(res.screen.screen).toMatchLines([
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run start in wks-b \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. Run build in wks-c \(took [0-9.]+m?s\)$/),
expect.ignoreColor(/^. 2 done$/),
]);

// Check scripts result
Expand Down
6 changes: 0 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,12 @@ export { CONFIG } from './config/config-loader.ts';
export { type IConfig } from './config/types.ts';

// Ui
export { default as GroupTaskSpinner } from './ui/group-task-spinner.tsx';
export * from './ui/group-task-spinner.tsx';

export { default as Layout } from './ui/layout.tsx';
export * from './ui/layout.tsx';

export { default as List } from './ui/list.tsx';
export * from './ui/list.tsx';

export { default as TaskManagerSpinner } from './ui/task-manager-spinner.tsx';
export * from './ui/task-manager-spinner.tsx';

export { default as TaskName } from './ui/task-name.tsx';
export * from './ui/task-name.tsx';

Expand Down
8 changes: 6 additions & 2 deletions src/modules/task-command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { isScriptCtx } from '@/src/tasks/script-task.ts';
import { TASK_MANAGER } from '@/src/tasks/task-manager.config.ts';
import { type AwaitableGenerator } from '@/src/types.ts';
import List from '@/src/ui/list.tsx';
import TaskManagerSpinner from '@/src/ui/task-manager-spinner.tsx';
import TaskTreeCompleted from '@/src/ui/task-tree-completed.tsx';
import TaskTreeSpinner from '@/src/ui/task-tree-spinner.tsx';
import { ExitException } from '@/src/utils/exit.ts';
import { printJson } from '@/src/utils/json.ts';

Expand Down Expand Up @@ -73,13 +74,16 @@ export abstract class TaskCommand<A = unknown> extends InkCommand<A> {
}
} else if (tasks.tasks.length > 0) {
// Render
yield <TaskManagerSpinner manager={this.manager} />;
yield <TaskTreeSpinner manager={this.manager} />;

// Start tasks
tasks.start(this.manager);

const result = await waitFor$(tasks, 'finished');

this.app.clear();
yield <TaskTreeCompleted manager={this.manager} />;

if (result.failed > 0) {
throw new ExitException(1);
}
Expand Down
6 changes: 3 additions & 3 deletions src/tasks/task-expression.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ export class TaskExpressionService {
let group: GroupTask;

if (node.operator === '//') {
group = new ParallelGroup('In parallel', {}, {
group = new ParallelGroup('In parallel', { workspace }, {
logger: this._logger,
});
} else if (node.operator === '||') {
group = new FallbackGroup('Fallbacks', {}, {
group = new FallbackGroup('Fallbacks', { workspace }, {
logger: this._logger,
});
} else {
Expand All @@ -227,7 +227,7 @@ export class TaskExpressionService {
TaskExpressionService._sequenceOperatorWarn = true;
}

group = new SequenceGroup('In sequence', {}, {
group = new SequenceGroup('In sequence', { workspace }, {
logger: this._logger,
});
}
Expand Down
85 changes: 0 additions & 85 deletions src/ui/group-task-spinner.tsx

This file was deleted.

Loading

0 comments on commit 684966d

Please sign in to comment.