Skip to content

Commit

Permalink
test: tag.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Oct 14, 2022
1 parent 83556fc commit 022ad36
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 4 deletions.
65 changes: 65 additions & 0 deletions test/unit/__snapshots__/tag.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Vitest Snapshot v1

exports[`Tag Object > get latest() 1`] = `"v0.0.1"`;

exports[`Tag Object > get latest() 2`] = `"v1"`;

exports[`Tag Object > get latest() 3`] = `"latest"`;

exports[`Tag Object > get latest() 4`] = `"v1-rc1"`;

exports[`Tag Object > get latest() 5`] = `"v1-beta"`;

exports[`Tag Object > get latest() 6`] = `"alpha"`;

exports[`Tag Object > get latest() 7`] = `"beta"`;

exports[`Tag Object > get latest() 8`] = `"rc1"`;

exports[`Tag Object > isFreezed() 1`] = `false`;

exports[`Tag Object > isFreezed() 2`] = `false`;

exports[`Tag Object > isFreezed() 3`] = `false`;

exports[`Tag Object > isFreezed() 4`] = `false`;

exports[`Tag Object > isFreezed() 5`] = `false`;

exports[`Tag Object > isFreezed() 6`] = `false`;

exports[`Tag Object > isFreezed() 7`] = `false`;

exports[`Tag Object > isFreezed() 8`] = `false`;

exports[`Tag Object > isFreezed() 9`] = `true`;

exports[`Tag Object > isFreezed() 10`] = `false`;

exports[`Tag Object > isFreezed() 11`] = `false`;

exports[`Tag Object > isFreezed() 12`] = `false`;

exports[`Tag Object > isFreezed() 13`] = `false`;

exports[`Tag Object > isFreezed() 14`] = `true`;

exports[`Tag Object > isFreezed() 15`] = `false`;

exports[`Tag Object > isFreezed() 16`] = `false`;

exports[`Tag Object > isFreezed() 17`] = `true`;

exports[`Tag Object > isFreezed() 18`] = `false`;

exports[`Tag Object > isFreezed() 19`] = `false`;

exports[`Tag Object > isFreezed() 20`] = `true`;

exports[`Tag Object > isFreezed() 21`] = `false`;

exports[`Tag Object > isFreezed() 22`] = `false`;

exports[`Tag Object > isFreezed() 23`] = `false`;

exports[`Tag Object > isFreezed() 24`] = `false`;
6 changes: 6 additions & 0 deletions test/unit/fixtures/tag.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Tag } from '../../../src/tag';

export interface ITagTestContext {
tags: Tag[];
tagPolicy: string[][];
invalid: Tag[];
}

Expand All @@ -12,8 +13,13 @@ export const tagContextFixture: ITagTestContext = {
new Tag('latest'),
new Tag('v1-rc1'),
new Tag('v1-beta'),
new Tag('alpha'),
new Tag('beta'),
new Tag('rc1'),
],

tagPolicy: [['^S*-rcd$'], ['alpha', 'beta'], ['latest']],

invalid: [
// @ts-expect-error: Let's ignore a type error, it's required for testing
new Tag(),
Expand Down
26 changes: 22 additions & 4 deletions test/unit/tag.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { describe, it, expect, beforeEach, test } from 'vitest';

import { tagContextFixture, ITagTestContext } from './fixtures/tag.fixture';

describe('Tag Object', () => {
beforeEach<ITagTestContext>(context => {
context.tags = tagContextFixture.tags;
context.tagPolicy = tagContextFixture.tagPolicy;
context.invalid = tagContextFixture.invalid;
});

it<ITagTestContext>('can be instantiated', context => {
context.tags.map(item => expect(item).toBeDefined());
});
it<ITagTestContext>('can be instantiated', context =>
context.tags.map(tagsItem => expect(tagsItem).toBeDefined()));

it.todo<ITagTestContext>(
'is invalid' /*, async context => {
context.invalid.map(async item =>
expect(Metadata.validate(item)).resolves.toMatchSnapshot()
);
}*/
);

test<ITagTestContext>('get latest()', context =>
context.tags.map(tagsItem => expect(tagsItem.latest).toMatchSnapshot()));

test<ITagTestContext>('isFreezed()', context =>
context.tags.map(tagsItem =>
context.tagPolicy.map(tagPolicyItem =>
expect(tagsItem.isFreezed(tagPolicyItem)).toMatchSnapshot()
)
));
});

0 comments on commit 022ad36

Please sign in to comment.