Skip to content

Commit

Permalink
changed: debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Pasynok committed Nov 3, 2024
1 parent cb93454 commit 6d96697
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
67 changes: 67 additions & 0 deletions src/compose/__tests__/__snapshots__/up.debug.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`up.debug 1`] = `
[
"[2024-01-01T00:00:00.000Z] app-compose:",
"{
"a": "idle",
"b": "idle",
"c": "idle"
}",
]
`;

exports[`up.debug 2`] = `
[
"[2024-01-01T00:00:00.000Z] app-compose:",
"{
"a": "pending",
"b": "idle",
"c": "idle"
}",
]
`;

exports[`up.debug 3`] = `
[
"[2024-01-01T00:00:00.000Z] app-compose:",
"{
"a": "pending",
"b": "idle",
"c": "pending"
}",
]
`;

exports[`up.debug 4`] = `
[
"[2024-01-01T00:00:00.000Z] app-compose:",
"{
"a": "done",
"b": "idle",
"c": "pending"
}",
]
`;

exports[`up.debug 5`] = `
[
"[2024-01-01T00:00:00.000Z] app-compose:",
"{
"a": "done",
"b": "idle",
"c": "done"
}",
]
`;

exports[`up.debug 6`] = `
[
"[2024-01-01T00:00:00.000Z] app-compose:",
"{
"a": "done",
"b": "off",
"c": "done"
}",
]
`;
16 changes: 10 additions & 6 deletions src/compose/__tests__/up.debug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import { compose } from '../index';

test('up.debug', async () => {
const consoleLogSpy = vi.spyOn(console, 'debug').mockImplementation(() => {});
const fixedDate = new Date('2024-01-01T00:00:00.000Z');

vi.setSystemTime(fixedDate);

const a = createContainer({ id: 'a', start: () => ({ api: null }) });
const b = createContainer({ id: 'b', dependsOn: [a], enable: () => false, start: () => ({ api: null }) });
const c = createContainer({ id: 'c', start: () => ({ api: null }) });

await compose.up([a, b, c], { debug: true });

expect(consoleLogSpy.mock.calls[0]).toStrictEqual([{ a: 'idle', b: 'idle', c: 'idle' }]);
expect(consoleLogSpy.mock.calls[1]).toStrictEqual([{ a: 'pending', b: 'idle', c: 'idle' }]);
expect(consoleLogSpy.mock.calls[2]).toStrictEqual([{ a: 'pending', b: 'idle', c: 'pending' }]);
expect(consoleLogSpy.mock.calls[3]).toStrictEqual([{ a: 'done', b: 'idle', c: 'pending' }]);
expect(consoleLogSpy.mock.calls[4]).toStrictEqual([{ a: 'done', b: 'idle', c: 'done' }]);
expect(consoleLogSpy.mock.calls[5]).toStrictEqual([{ a: 'done', b: 'off', c: 'done' }]);
expect(consoleLogSpy.mock.calls[0]).toMatchSnapshot();
expect(consoleLogSpy.mock.calls[1]).toMatchSnapshot();
expect(consoleLogSpy.mock.calls[2]).toMatchSnapshot();
expect(consoleLogSpy.mock.calls[3]).toMatchSnapshot();
expect(consoleLogSpy.mock.calls[4]).toMatchSnapshot();
expect(consoleLogSpy.mock.calls[5]).toMatchSnapshot();

consoleLogSpy.mockRestore();
vi.useRealTimers();
});
4 changes: 3 additions & 1 deletion src/compose/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const upFn = (containers: AnyContainer[], config?: { debug?: boolean }) => {
});

if (config?.debug) {
$result.watch((x) => console.debug(x.statuses));
$result.watch((x) => {
console.debug(`[${new Date().toISOString()}] app-compose:`, JSON.stringify(x.statuses, null, 2));
});
}

for (const container of containers) {
Expand Down

0 comments on commit 6d96697

Please sign in to comment.