Skip to content

Commit

Permalink
added: basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Pasynok committed Nov 3, 2024
1 parent 31992d5 commit 5264f11
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
61 changes: 61 additions & 0 deletions src/compose/__tests__/up..spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { genContainerId } from '../../__fixtures__';
import { CONTAINER_STATUS, createContainer } from '../../createContainer';
import { compose } from '../index';

describe('compose.up', () => {
describe('single | without any deps', () => {
test('enabled=true by default', () => {
const a = createContainer({ id: genContainerId(), start: () => ({ api: null }) });

expect(compose.up([a])).resolves.toStrictEqual({
done: true,
hasErrors: false,
statuses: { [a.id]: CONTAINER_STATUS.done },
});
});
test('enabled=true', () => {
const a = createContainer({ id: genContainerId(), start: () => ({ api: null }), enable: () => true });

expect(compose.up([a])).resolves.toStrictEqual({
done: true,
hasErrors: false,
statuses: { [a.id]: CONTAINER_STATUS.done },
});
});
test('enabled=Promise<true>', () => {
const a = createContainer({
id: genContainerId(),
start: () => ({ api: null }),
enable: () => Promise.resolve(true),
});

expect(compose.up([a])).resolves.toStrictEqual({
done: true,
hasErrors: false,
statuses: { [a.id]: CONTAINER_STATUS.done },
});
});
test('enabled=false', () => {
const a = createContainer({ id: genContainerId(), start: () => ({ api: null }), enable: () => false });

expect(compose.up([a])).resolves.toStrictEqual({
done: true,
hasErrors: false,
statuses: { [a.id]: CONTAINER_STATUS.off },
});
});
test('enabled=Promise<false>', () => {
const a = createContainer({
id: genContainerId(),
start: () => ({ api: null }),
enable: () => Promise.resolve(false),
});

expect(compose.up([a])).resolves.toStrictEqual({
done: true,
hasErrors: false,
statuses: { [a.id]: CONTAINER_STATUS.off },
});
});
});
});
4 changes: 2 additions & 2 deletions src/compose/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ const upFn = (containers: AnyContainer[]) => {
if (x.done === true) {
// fixme: clear all nodes
if (x.hasErrors) {
reject(x.statuses);
reject(x);
}

resolve(x.statuses);
resolve(x);
}
});
});
Expand Down

0 comments on commit 5264f11

Please sign in to comment.