1
Fork 0

Switch testing from ava to @holllo/test.

This commit is contained in:
Bauke 2024-01-24 19:27:42 +01:00
parent d8fa000181
commit f6ffc0182d
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
5 changed files with 77 additions and 75 deletions

View File

@ -1,21 +0,0 @@
import test from 'ava';
import {migrate, Migration} from '../source/migration-helper.js';
test('migrate<Date>', async (t) => {
const migrations: Array<Migration<Date, string, string>> = [
{
version: new Date('2022-01-01'),
migrate: async (data: string) => `${data} migrated`,
},
];
function offsetDate(offset: number): Date {
const d = new Date(migrations[0].version);
d.setDate(d.getDate() + offset);
return d;
}
const data = 'data';
t.is(await migrate(data, offsetDate(-1), migrations), 'data migrated');
t.is(await migrate(data, offsetDate(1), migrations), data);
});

77
tests/migrate.test.ts Normal file
View File

@ -0,0 +1,77 @@
import {setup} from '@holllo/test';
import {
migrate,
Migration,
SkipMigrationFn,
} from '../source/migration-helper.js';
await setup('migrate<T>', async (group) => {
group.test('T = Date', async (test) => {
const migrations: Array<Migration<Date, string, string>> = [
{
version: new Date('2022-01-01'),
migrate: async (data: string) => `${data} migrated`,
},
];
function offsetDate(offset: number): Date {
const d = new Date(migrations[0].version);
d.setDate(d.getDate() + offset);
return d;
}
const data = 'data';
test.equals(
await migrate(data, offsetDate(-1), migrations),
'data migrated',
);
test.equals(await migrate(data, offsetDate(1), migrations), data);
});
group.test('T = number', async (test) => {
const migrations: Array<Migration<number, string, string>> = [
{
version: 5,
migrate: async (data: string) => `${data} migrated`,
},
];
const data = 'data';
test.equals(await migrate(data, 4, migrations), 'data migrated');
test.equals(await migrate(data, 6, migrations), data);
});
group.test('T = {custom: number}', async (test) => {
type Custom = {
custom: number;
};
const skip: SkipMigrationFn<Custom> = (a, b) => a.custom > b.custom;
const migrations: Array<Migration<Custom, string, string>> = [
{
version: {custom: 5},
migrate: async (data: string) => `${data} migrated`,
},
];
const data = 'data';
test.equals(await migrate(data, {custom: 4}, migrations, skip), data);
test.equals(
await migrate(data, {custom: 6}, migrations, skip),
'data migrated',
);
});
group.test('T = string', async (test) => {
const migrations: Array<Migration<string, string, string>> = [
{
version: '0.2.4',
migrate: async (data: string) => `${data} migrated`,
},
];
const data = 'data';
test.equals(await migrate(data, '0.2.3', migrations), 'data migrated');
test.equals(await migrate(data, '0.2.5', migrations), data);
});
});

View File

@ -1,15 +0,0 @@
import test from 'ava';
import {migrate, Migration} from '../source/migration-helper.js';
test('migrate<number>', async (t) => {
const migrations: Array<Migration<number, string, string>> = [
{
version: 5,
migrate: async (data: string) => `${data} migrated`,
},
];
const data = 'data';
t.is(await migrate(data, 4, migrations), 'data migrated');
t.is(await migrate(data, 6, migrations), data);
});

View File

@ -1,24 +0,0 @@
import test from 'ava';
import {
migrate,
Migration,
SkipMigrationFn,
} from '../source/migration-helper.js';
test('migrate<{custom: number}>', async (t) => {
type Custom = {
custom: number;
};
const skip: SkipMigrationFn<Custom> = (a, b) => a.custom > b.custom;
const migrations: Array<Migration<Custom, string, string>> = [
{
version: {custom: 5},
migrate: async (data: string) => `${data} migrated`,
},
];
const data = 'data';
t.is(await migrate(data, {custom: 4}, migrations, skip), data);
t.is(await migrate(data, {custom: 6}, migrations, skip), 'data migrated');
});

View File

@ -1,15 +0,0 @@
import test from 'ava';
import {migrate, Migration} from '../source/migration-helper.js';
test('migrate<string>', async (t) => {
const migrations: Array<Migration<string, string, string>> = [
{
version: '0.2.4',
migrate: async (data: string) => `${data} migrated`,
},
];
const data = 'data';
t.is(await migrate(data, '0.2.3', migrations), 'data migrated');
t.is(await migrate(data, '0.2.5', migrations), data);
});