Skip to content

Commit

Permalink
feat: fix & stabilize e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jujulego committed Nov 24, 2023
1 parent 8c74eda commit 0efef26
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
18 changes: 9 additions & 9 deletions e2e/each.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ 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\)$/),
]);

// Check script result
Expand All @@ -111,13 +111,13 @@ 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\)$/),
]);

// Check script result
Expand All @@ -144,9 +144,9 @@ 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\)$/),
]);

// Check script result
Expand Down Expand Up @@ -179,9 +179,9 @@ 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\)$/),
]);

// Check script result
Expand Down
2 changes: 1 addition & 1 deletion e2e/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ 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\)$/),
]);

// Check scripts result
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
27 changes: 18 additions & 9 deletions src/ui/task-tree-spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { FallbackGroup, GroupTask, SequenceGroup, Task, TaskManager } from '@jujulego/tasks';
import { GroupTask, Task, TaskManager } from '@jujulego/tasks';
import { Box } from 'ink';
import { useLayoutEffect, useMemo, useState } from 'react';

import { CONFIG } from '@/src/config/config-loader.ts';
import { container } from '@/src/inversify.config.ts';
import { Workspace } from '@/src/project/workspace.ts';
import { isCommandCtx } from '@/src/tasks/command-task.ts';
import { isScriptCtx } from '@/src/tasks/script-task.ts';
import { ScriptTask } from '@/src/tasks/script-task.ts';
import TaskSpinner from '@/src/ui/task-spinner.tsx';

// Types
Expand All @@ -15,18 +16,26 @@ export interface TaskTreeSpinnerProps {

// Utils
function comparator(a: Task, b: Task) {
// 1 - compare workspaces
const wksA = isScriptCtx(a.context) ? a.context.workspace.name : '';
const wksB = isScriptCtx(b.context) ? b.context.workspace.name : '';
// 1 - compare kind
const kindA = a instanceof ScriptTask ? 1 : 0;
const kindB = b instanceof ScriptTask ? 1 : 0;

if (kindA !== kindB) {
return kindB - kindA;
}

// 2 - compare workspaces
const wksA = 'workspace' in a.context ? (a.context.workspace as Workspace).name : '\uffff';
const wksB = 'workspace' in b.context ? (b.context.workspace as Workspace).name : '\uffff';
const wksDiff = wksA.localeCompare(wksB);

if (wksDiff !== 0) {
return wksDiff;
}

// 2 - compare scripts
const scriptA = isScriptCtx(a.context) ? a.context.script : '';
const scriptB = isScriptCtx(b.context) ? b.context.script : '';
// 1 - compare scripts
const scriptA = 'script' in a.context ? a.context.script as string : '\uffff';
const scriptB = 'script' in b.context ? b.context.script as string : '\uffff';

return scriptA.localeCompare(scriptB);
}
Expand All @@ -47,7 +56,7 @@ function *extractTasks(groupId: string | undefined, tasks: readonly Task[], isVe
if (isVerbose || isCommandGroup || hasFailed || isStarted) {
let tasks = task.tasks;

if (!(task instanceof SequenceGroup || task instanceof FallbackGroup)) {
if (task instanceof ScriptTask) {
tasks = [...tasks].sort(comparator);
}

Expand Down

0 comments on commit 0efef26

Please sign in to comment.