Skip to content

Commit a044c8e

Browse files
committed
test: replace uvu with AVA
1 parent 79f6a2e commit a044c8e

File tree

9 files changed

+225
-199
lines changed

9 files changed

+225
-199
lines changed

ava.config.integration.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import defaultConfig from './ava.config.mjs';
2+
3+
export default {
4+
...defaultConfig,
5+
files: ['./test/integration/**/*.test.{ts,tsx}'],
6+
};

ava.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
files: ['./test/unit/**/*.test.{ts,tsx}'],
3+
extensions: {
4+
ts: 'module',
5+
tsx: 'module',
6+
},
7+
nodeArguments: ['--no-warnings', '--loader=tsx'],
8+
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
"compile": "tsc --build",
3333
"lint": "eslint src test --ext '.ts,.tsx'",
3434
"copy:paste:detection": "jscpd src test",
35-
"test:unit": "TS_NODE_PROJECT=tsconfig.base.json uvu -r ts-node/register/transpile-only 'test/unit/' '.*\\.test\\.(ts|tsx)$'",
35+
"test:unit": "ava",
3636
"test:unit:coverage": "c8 npm run test:unit",
37-
"test:integration": "TS_NODE_PROJECT=tsconfig.base.json uvu -r ts-node/register/transpile-only 'test/integration/' '.*\\.test\\.(ts|tsx)$'",
37+
"test:integration": "ava --config ava.config.integration.mjs",
3838
"test:unit:mutation": "stryker run"
3939
},
4040
"dependencies": {

test/integration/deletePipelines.test.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
2-
import { test } from 'uvu';
3-
import * as assert from 'uvu/assert';
2+
import test from 'ava';
43
import { render, cleanup } from 'ink-testing-library';
54
import { parseISO } from 'date-fns';
65
import delay from 'delay';
@@ -11,7 +10,7 @@ import { App } from '../../src/App';
1110
import { deletePipeline, filterPipelinesByDate, listPipelines } from '../../src/gitlab';
1211
import { getRequest, deleteRequest } from '../../src/network';
1312

14-
test.after.each(cleanup);
13+
test.afterEach(cleanup);
1514

1615
async function waitUntilDeleted(frames: string[]) {
1716
if (frames.some((frame) => frame.includes('Pipelines deleted'))) {
@@ -53,30 +52,30 @@ function renderApp(gitlabUrl: string) {
5352
);
5453
}
5554

56-
test(
55+
test.serial(
5756
'deletes 4 old pipelines that are older than 30 days',
58-
withGitLabServer({}, async (url) => {
57+
withGitLabServer({}, async (t, url) => {
5958
const { lastFrame, frames } = renderApp(url);
6059
await waitUntilDeleted(frames);
6160

6261
const actual = lastFrame();
6362
const expected =
6463
'4 pipelines found\nDeleting pipeline with id 32 for project 42\nDeleting pipeline with id 33 for project 42\nDeleting pipeline with id 34 for project 42\nDeleting pipeline with id 35 for project 42\n\u001b[32mPipelines deleted\u001b[39m';
65-
assert.equal(actual, expected);
64+
65+
t.is(actual, expected);
6666
}),
6767
);
6868

69-
test(
69+
test.serial(
7070
'fails with the response error message when a GitLab delete request fails',
71-
withGitLabServer({ failOnDelete: true }, async (url) => {
71+
withGitLabServer({ failOnDelete: true }, async (t, url) => {
7272
const { lastFrame, frames } = renderApp(url);
7373
await waitUntilDeleted(frames);
7474

7575
const actual = lastFrame();
7676
const expected =
7777
"35 pipelines found\nDeleting pipeline with id 36 for project 42\nDeleting pipeline with id 37 for project 42\nDeleting pipeline with id 38 for project 42\nDeleting pipeline with id 39 for project 42\nDeleting pipeline with id 40 for project 42\nDeleting pipeline with id 41 for project 42\n\u001b[31mThere was an error while deleting the pipelines: Response code 418 (I'm a Teapot)\u001b[39m";
78-
assert.equal(actual, expected);
78+
79+
t.is(actual, expected);
7980
}),
8081
);
81-
82-
test.run();

test/integration/gitlabServer.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Factory } from 'fishery';
55
import { subDays, formatISO, parseISO } from 'date-fns';
66
import { IncomingHttpHeaders } from 'http';
77
import { Pipeline } from '../../src/network';
8-
import { Callback } from 'uvu';
8+
import { ExecutionContext, ImplementationFn } from 'ava';
99

1010
interface PipelineTransientParams {
1111
readonly startDate: Date;
@@ -59,13 +59,17 @@ function createRoutes(config: Config): RequestHandler[] {
5959
];
6060
}
6161

62-
export function withGitLabServer(config: Config, test: (url: string) => void | Promise<void>): Callback {
63-
return async () => {
62+
export function withGitLabServer(
63+
config: Config,
64+
test: (t: ExecutionContext<unknown>, url: string) => void | Promise<void>,
65+
): ImplementationFn<[]> {
66+
return async (t) => {
6467
const routes = createRoutes(config);
6568
const server = micro(router(...routes));
6669
try {
6770
const url = await listen(server);
68-
await test(url);
71+
72+
await test(t, url);
6973
} finally {
7074
server.close();
7175
}

test/unit/App.test.tsx

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
2-
import { test } from 'uvu';
3-
import * as assert from 'uvu/assert';
2+
import test from 'ava';
43
import { render, cleanup } from 'ink-testing-library';
54
import sinon from 'sinon';
65
import delay from 'delay';
@@ -9,7 +8,7 @@ import { App, AppProps } from '../../src/App';
98
import { Pipeline } from '../../src/network';
109
import { createAppProps } from './factory';
1110

12-
test.after.each(cleanup);
11+
test.afterEach(cleanup);
1312

1413
const pipelineFactory = Factory.define<Pipeline>(({ sequence }) => {
1514
return {
@@ -37,34 +36,35 @@ function renderApp(overrides: Partial<AppProps> = {}) {
3736
);
3837
}
3938

40-
test('renders initially a loading spinner', async () => {
39+
test.serial('renders initially a loading spinner', async (t) => {
4140
const { frames } = renderApp();
4241
await delay(1);
4342

4443
const actual = frames[0];
4544
const expected = '⠋';
46-
assert.equal(actual, expected);
45+
46+
t.is(actual, expected);
4747
});
4848

49-
test('shows how many pipelines are found in the beginning', async () => {
49+
test.serial('shows how many pipelines are found in the beginning', async (t) => {
5050
const { lastFrame } = renderApp();
5151
await delay(1);
5252

5353
const actual = lastFrame()?.startsWith('0 pipelines found\n');
54-
const expected = true;
55-
assert.equal(actual, expected);
54+
55+
t.true(actual);
5656
});
5757

58-
test("shows the success message 'Pipelines deleted' when deletion is finished", async () => {
58+
test.serial("shows the success message 'Pipelines deleted' when deletion is finished", async (t) => {
5959
const { lastFrame } = renderApp();
6060
await delay(1);
6161

6262
const actual = lastFrame()?.endsWith('\u001b[32mPipelines deleted\u001b[39m');
63-
const expected = true;
64-
assert.equal(actual, expected);
63+
64+
t.true(actual);
6565
});
6666

67-
test('shows the delete progress while it deletes the pipelines', async () => {
67+
test.serial('shows the delete progress while it deletes the pipelines', async (t) => {
6868
const pipelines = pipelineFactory.buildList(5);
6969
const { lastFrame } = renderApp({
7070
filterPipelinesByDate: sinon.fake.returns(pipelines),
@@ -74,10 +74,11 @@ test('shows the delete progress while it deletes the pipelines', async () => {
7474
const actual = lastFrame();
7575
const expected =
7676
'5 pipelines found\nDeleting pipeline with id 1 for project 42\nDeleting pipeline with id 2 for project 42\nDeleting pipeline with id 3 for project 42\nDeleting pipeline with id 4 for project 42\nDeleting pipeline with id 5 for project 42\n\u001b[32mPipelines deleted\u001b[39m';
77-
assert.equal(actual, expected);
77+
78+
t.is(actual, expected);
7879
});
7980

80-
test('deletes pipelines of multiple projects', async () => {
81+
test.serial('deletes pipelines of multiple projects', async (t) => {
8182
const { lastFrame } = renderApp({
8283
filterPipelinesByDate: sinon
8384
.stub()
@@ -94,21 +95,23 @@ test('deletes pipelines of multiple projects', async () => {
9495
const actual = lastFrame();
9596
const expected =
9697
'3 pipelines found\nDeleting pipeline with id 6 for project 1\nDeleting pipeline with id 7 for project 3\nDeleting pipeline with id 8 for project 3\n\u001b[32mPipelines deleted\u001b[39m';
97-
assert.equal(actual, expected);
98+
99+
t.is(actual, expected);
98100
});
99101

100-
test('renders an error message when an error occurred', async () => {
102+
test.serial('renders an error message when an error occurred', async (t) => {
101103
const { lastFrame } = renderApp({
102104
listPipelines: sinon.fake.rejects(new Error('Test Error')),
103105
});
104106
await delay(1);
105107

106108
const actual = lastFrame();
107109
const expected = '\u001b[31mThere was an error while deleting the pipelines: Test Error\u001b[39m';
108-
assert.equal(actual, expected);
110+
111+
t.is(actual, expected);
109112
});
110113

111-
test('renders an error message when a delete request fails', async () => {
114+
test.serial('renders an error message when a delete request fails', async (t) => {
112115
const pipelines = pipelineFactory.buildList(1);
113116
const { lastFrame } = renderApp({
114117
filterPipelinesByDate: sinon.fake.returns(pipelines),
@@ -119,21 +122,24 @@ test('renders an error message when a delete request fails', async () => {
119122
const actual = lastFrame();
120123
const expected =
121124
'1 pipelines found\nDeleting pipeline with id 9 for project 42\n\u001b[31mThere was an error while deleting the pipelines: Failed to delete\u001b[39m';
122-
assert.equal(actual, expected);
123-
});
124-
125-
test('renders an error message with stack trace when an error occurred and showStackTraces is true', async () => {
126-
const error = new Error('Test Error');
127-
error.stack = 'the-stack-trace';
128-
const { lastFrame } = renderApp({
129-
listPipelines: sinon.fake.rejects(error),
130-
showStackTraces: true,
131-
});
132-
await delay(1);
133125

134-
const actual = lastFrame();
135-
const expected = '\u001b[31mThere was an error while deleting the pipelines: the-stack-trace\u001b[39m';
136-
assert.equal(actual, expected);
126+
t.is(actual, expected);
137127
});
138128

139-
test.run();
129+
test.serial(
130+
'renders an error message with stack trace when an error occurred and showStackTraces is true',
131+
async (t) => {
132+
const error = new Error('Test Error');
133+
error.stack = 'the-stack-trace';
134+
const { lastFrame } = renderApp({
135+
listPipelines: sinon.fake.rejects(error),
136+
showStackTraces: true,
137+
});
138+
await delay(1);
139+
140+
const actual = lastFrame();
141+
const expected = '\u001b[31mThere was an error while deleting the pipelines: the-stack-trace\u001b[39m';
142+
143+
t.is(actual, expected);
144+
},
145+
);

test/unit/Error.test.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from 'react';
2-
import { test } from 'uvu';
3-
import * as assert from 'uvu/assert';
2+
import test from 'ava';
43
import sinon from 'sinon';
54
import { render, cleanup } from 'ink-testing-library';
65
import { Error, ErrorProps } from '../../src/Error';
76

8-
test.after.each(cleanup);
7+
test.afterEach(cleanup);
98

109
function renderError(text: string, overrides: Partial<ErrorProps> = {}) {
1110
const props: ErrorProps = {
@@ -24,18 +23,21 @@ function renderError(text: string, overrides: Partial<ErrorProps> = {}) {
2423
);
2524
}
2625

27-
test('renders a red error message', () => {
26+
test.serial('renders a red error message', (t) => {
2827
const { lastFrame } = renderError('Test error');
28+
2929
const actual = lastFrame();
3030
const expected = '\u001b[31mTest error\u001b[39m';
31-
assert.equal(actual, expected);
31+
32+
t.is(actual, expected);
3233
});
3334

34-
test('calls given exit() callback after it was rendered', () => {
35+
test.serial('calls given exit() callback after it was rendered', (t) => {
3536
const exit = sinon.fake();
37+
3638
const { unmount } = renderError('Test error', { exit });
3739
unmount();
40+
3841
sinon.assert.calledOnce(exit);
42+
t.pass();
3943
});
40-
41-
test.run();

0 commit comments

Comments
 (0)