Skip to content

Commit 4c39359

Browse files
committed
♻️ Migrate tests to Vitest syntax
A good exercice in regex :)
1 parent ceba4f8 commit 4c39359

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+541
-557
lines changed

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"lint:fix": "npm run lint:tests -- --fix && npm run lint:examples -- --fix && npm run lint:src:agile -- --fix && npm run lint:src:clients -- --fix && npm run lint:src:services -- --fix && npm run lint:src:version2 -- --fix && npm run lint:src:version3 -- --fix && npm run lint:src:serviceDesk -- --fix && npm run lint:src:files -- --fix",
3636
"doc": "typedoc --name \"Jira.js - Jira Cloud API library\" --out docs ./src/index.ts --plugin typedoc-plugin-extras --footerDate --footerTime --footerTypedocVersion --favicon https://svgshare.com/i/bHF.svg",
3737
"test": "npm run test:unit && npm run test:integration",
38-
"test:unit": "ava tests/unit --timeout=2m -с 8",
39-
"test:integration": "ava --timeout=2m --fail-fast --no-worker-threads -c 1 -s tests/integration/**/*.test.ts",
38+
"test:unit": "vitest tests/unit --timeout=2m -с 8",
39+
"test:integration": "vitest --timeout=2m --fail-fast --no-worker-threads -c 1 -s tests/integration/**/*.test.ts",
4040
"replace:all": "npm run replace:permissions:version2 && npm run replace:permissions:version3 && npm run replace:pagination:version2 && npm run replace:pagination:version3 && npm run replace:async:version2 && npm run replace:async:version3 && npm run replace:expansion:version2 && npm run replace:expansion:version3 && npm run replace:ordering:version2 && npm run replace:ordering:version3 && npm run replace:groupMember:version2 && npm run replace:workflowPaginated:version2",
4141
"replace:permissions:version2": "grep -rl \"(#permissions)\" ./src/version2 | xargs sed -i '' 's/(#permissions)/(https:\\/\\/developer.atlassian.com\\/cloud\\/jira\\/platform\\/rest\\/v2\\/intro\\/#permissions)/g'",
4242
"replace:permissions:version3": "grep -rl \"(#permissions)\" ./src/version3 | xargs sed -i '' 's/(#permissions)/(https:\\/\\/developer.atlassian.com\\/cloud\\/jira\\/platform\\/rest\\/v3\\/intro\\/#permissions)/g'",
@@ -71,7 +71,6 @@
7171
"@types/sinon": "^17.0.3",
7272
"@typescript-eslint/eslint-plugin": "^7.9.0",
7373
"@typescript-eslint/parser": "^7.9.0",
74-
"ava": "^6.1.3",
7574
"dotenv": "^16.4.5",
7675
"eslint": "^8.57.0",
7776
"eslint-config-airbnb-base": "^15.0.0",
@@ -83,7 +82,8 @@
8382
"ts-node": "^10.9.2",
8483
"typedoc": "^0.25.13",
8584
"typedoc-plugin-extras": "^3.0.0",
86-
"typescript": "^5.4.5"
85+
"typescript": "^5.4.5",
86+
"vitest": "^1.6.0"
8787
},
8888
"dependencies": {
8989
"axios": "^1.6.8",
+18-24
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
import test from 'ava';
1+
import { afterAll, beforeAll, test } from 'vitest';
22
import { AgileModels } from '../../../src/index.js';
33
import { Constants } from '../constants.js';
4-
import {
5-
createAgileProject, deleteAgileProject, getAgileClient, getVersion3Client,
6-
} from '../utils/index.js';
4+
import { createAgileProject, deleteAgileProject, getAgileClient, getVersion3Client } from '../utils/index.js';
75

86
const client = getAgileClient();
97

108
let board: any;
119
let sprint: AgileModels.Sprint;
1210

13-
test.before(async () => {
11+
beforeAll(async () => {
1412
await createAgileProject();
1513
});
1614

17-
test.after(async () => {
15+
afterAll(async () => {
1816
await deleteAgileProject();
1917
});
2018

21-
test.serial('should create new sprint', async t => {
19+
test.sequential('should create new sprint', async ({ expect }) => {
2220
const boards = await client.board.getAllBoards({ name: Constants.testAgileProjectKey });
2321

24-
t.is(boards.total, 1);
22+
expect(boards.total).toBe(1);
2523

2624
[board] = boards.values;
2725

@@ -30,12 +28,12 @@ test.serial('should create new sprint', async t => {
3028
originBoardId: board.id,
3129
});
3230

33-
t.truthy(!!sprint);
34-
t.is(sprint.name, 'New sprint');
35-
t.is(sprint.state, 'future');
31+
expect(!!sprint).toBeTruthy();
32+
expect(sprint.name).toBe('New sprint');
33+
expect(sprint.state).toBe('future');
3634
});
3735

38-
test.serial('should create and move task to sprint', async t => {
36+
test.sequential('should create and move task to sprint', async ({ expect }) => {
3937
const issue = await getVersion3Client().issues.createIssue({
4038
fields: {
4139
summary: 'Test task',
@@ -57,33 +55,29 @@ test.serial('should create and move task to sprint', async t => {
5755
issues: [issue.key],
5856
});
5957

60-
t.truthy(!!issue);
58+
expect(!!issue).toBeTruthy();
6159
});
6260

63-
test.serial('should return issues for sprint', async t => {
61+
test.sequential('should return issues for sprint', async ({ expect }) => {
6462
const { issues } = await client.sprint.getIssuesForSprint({
6563
sprintId: sprint.id,
6664
});
6765

68-
t.truthy(!!issues);
69-
t.is(issues[0].fields?.summary, 'Test task');
66+
expect(!!issues).toBeTruthy();
67+
expect(issues[0].fields?.summary).toBe('Test task');
7068
});
7169

72-
test.serial('should partially update sprint', async t => {
70+
test.sequential('should partially update sprint', async ({ expect }) => {
7371
const newSprint = await client.sprint.partiallyUpdateSprint({
7472
sprintId: sprint.id,
7573
state: 'active',
7674
startDate: new Date(),
7775
endDate: new Date(Date.now() + 1000),
7876
});
7977

80-
t.is(newSprint.state, 'active');
78+
expect(newSprint.state).toBe('active');
8179
});
8280

83-
test.serial('should remove sprint', async t => {
84-
await client.sprint.deleteSprint({
85-
sprintId: sprint.id,
86-
});
87-
88-
t.pass();
81+
test.sequential('should remove sprint', async ({ expect }) => {
82+
await client.sprint.deleteSprint({ sprintId: sprint.id });
8983
});
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import test from 'ava';
1+
import { test } from 'vitest';
22
import type { Avatar } from '../../../src/version3/models/index.js';
33
import { getVersion2Client } from '../utils/index.js';
44

55
const client = getVersion2Client();
66

77
let avatar: Avatar | undefined;
88

9-
test.serial('should get all system avatars', async t => {
9+
test.sequential('should get all system avatars', async ({ expect }) => {
1010
const systemAvatars = await client.avatars.getAllSystemAvatars({ type: 'project' });
1111

1212
avatar = systemAvatars.system?.[0];
1313

14-
t.truthy(!!avatar);
14+
expect(!!avatar).toBeTruthy();
1515
});
1616

17-
test.serial('should return avatar image with contentType', async t => {
17+
test.sequential('should return avatar image with contentType', async ({ expect }) => {
1818
const avatarWithDetails = await client.avatars.getAvatarImageByID({ id: avatar!.id, type: 'project' });
1919

20-
t.is(avatarWithDetails.contentType, 'image/svg+xml');
21-
t.truthy(avatarWithDetails.avatar instanceof Uint8Array);
20+
expect(avatarWithDetails.contentType).toBe('image/svg+xml');
21+
expect(avatarWithDetails.avatar instanceof Uint8Array).toBeTruthy();
2222
});
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import test from 'ava';
1+
import { test } from 'vitest';
2+
import { Version2Models } from '../../../src/index.js';
23
import { Constants } from '../constants.js';
34
import { getVersion2Client } from '../utils/index.js';
4-
import { Version2Models } from '../../../src/index.js';
55

66
let dashboard: Version2Models.Dashboard;
77
const client = getVersion2Client();
88

9-
test.serial('should create dashboard', async t => {
9+
test.sequential('should create dashboard', async ({ expect }) => {
1010
dashboard = await client.dashboards.createDashboard({
1111
name: Constants.testDashboardName,
1212
sharePermissions: [],
1313
});
1414

15-
t.truthy(!!dashboard);
16-
t.is(dashboard.name, Constants.testDashboardName);
17-
t.deepEqual(dashboard.sharePermissions, []);
15+
expect(!!dashboard).toBeTruthy();
16+
expect(dashboard.name).toBe(Constants.testDashboardName);
17+
expect(dashboard.sharePermissions).toStrictEqual([]);
1818
});
1919

20-
test.serial('should remove dashboard', async t => {
20+
test.sequential('should remove dashboard', async ({ expect }) => {
2121
const response = await client.dashboards.deleteDashboard({
2222
id: dashboard.id,
2323
});
2424

25-
t.is(typeof response, 'string');
26-
t.is<string | void, string>(response, '');
25+
expect(typeof response).toBe('string');
26+
expect(response).toBe('');
2727
});
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import test from 'ava';
1+
import { test } from 'vitest';
22
import { Constants } from '../index.js';
33
import { getVersion2Client } from '../utils/index.js';
44

55
const client = getVersion2Client();
66

7-
test.serial('should create a group', async t => {
7+
test.sequential('should create a group', async ({ expect }) => {
88
const group = await client.groups.createGroup({
99
name: Constants.testGroupName,
1010
});
1111

12-
t.truthy(!!group);
13-
t.is(group.name, Constants.testGroupName);
12+
expect(!!group).toBeTruthy();
13+
expect(group.name).toBe(Constants.testGroupName);
1414
});
1515

16-
test.serial('should remove a group', async t => {
16+
test.sequential('should remove a group', async ({ expect }) => {
1717
const response = await client.groups.removeGroup({
1818
groupname: Constants.testGroupName,
1919
});
2020

21-
t.is(typeof response, 'string');
22-
t.is(response.trim(), '');
21+
expect(typeof response).toBe('string');
22+
expect(response.trim()).toBe('');
2323
});
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import * as fs from 'fs';
2-
import test from 'ava';
3-
import { Constants } from '../constants.js';
2+
import { afterAll, beforeAll, test } from 'vitest';
43
import type { Attachment, Issue } from '../../../src/version2/models/index.js';
4+
import { Constants } from '../constants.js';
55
import { cleanupEnvironment, getVersion2Client, prepareEnvironment } from '../utils/index.js';
66

77
const client = getVersion2Client({ noCheckAtlassianToken: true });
88

99
let issue: Issue;
1010
let attachments: Attachment[];
1111

12-
test.before(async () => {
12+
beforeAll(async () => {
1313
await prepareEnvironment();
1414
});
1515

16-
test.after(async () => {
16+
afterAll(async () => {
1717
await cleanupEnvironment();
1818
});
1919

20-
test.serial('should add attachment', async t => {
20+
test.sequential('should add attachment', async ({ expect }) => {
2121
issue = await client.issues.createIssue({
2222
fields: {
2323
summary: 'Issue with attachment',
@@ -30,7 +30,7 @@ test.serial('should add attachment', async t => {
3030
},
3131
});
3232

33-
t.truthy(!!issue);
33+
expect(!!issue).toBeTruthy();
3434

3535
attachments = await client.issueAttachments.addAttachment({
3636
issueIdOrKey: issue.key,
@@ -40,21 +40,17 @@ test.serial('should add attachment', async t => {
4040
},
4141
});
4242

43-
t.truthy(!!attachments);
44-
t.is(attachments[0].filename, 'issueAttachments.test.ts');
45-
t.is(attachments[0].mimeType, 'video/mp2t');
43+
expect(!!attachments).toBeTruthy();
44+
expect(attachments[0].filename).toBe('issueAttachments.test.ts');
45+
expect(attachments[0].mimeType).toBe('video/mp2t');
4646
});
4747

48-
test.serial('should getAttachmentContent', async t => {
48+
test.sequential('should getAttachmentContent', async ({ expect }) => {
4949
const content = await client.issueAttachments.getAttachmentContent({ id: attachments[0].id });
5050

51-
t.truthy(Buffer.isBuffer(content));
51+
expect(Buffer.isBuffer(content)).toBeTruthy();
5252
});
5353

54-
test.serial('should remove attachment', async t => {
55-
await client.issues.deleteIssue({
56-
issueIdOrKey: issue.key,
57-
});
58-
59-
t.pass();
54+
test.sequential('should remove attachment', async ({ expect }) => {
55+
await client.issues.deleteIssue({ issueIdOrKey: issue.key });
6056
});

tests/integration/version2/issueComments.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { AxiosError } from 'axios';
2-
import test from 'ava';
2+
import { afterAll, beforeAll, test } from 'vitest';
33
import { Constants } from '../constants.js';
44
import { cleanupEnvironment, getVersion2Client, prepareEnvironment } from '../utils/index.js';
55

6-
test.before(async () => {
6+
beforeAll(async () => {
77
await prepareEnvironment();
88
});
99

10-
test.after(async () => {
10+
afterAll(async () => {
1111
await cleanupEnvironment();
1212
});
1313

14-
test.serial('should update comment', async t => {
14+
test.sequential('should update comment', async ({ expect }) => {
1515
const client = getVersion2Client({ noCheckAtlassianToken: true });
1616

1717
const issue = await client.issues.createIssue({
@@ -26,7 +26,7 @@ test.serial('should update comment', async t => {
2626
},
2727
});
2828

29-
t.truthy(!!issue);
29+
expect(!!issue).toBeTruthy();
3030

3131
const comment = await client.issueComments
3232
.addComment({
@@ -39,16 +39,16 @@ test.serial('should update comment', async t => {
3939
throw error;
4040
});
4141

42-
t.truthy(!!comment);
42+
expect(!!comment).toBeTruthy();
4343

4444
const updatedComment = await client.issueComments.updateComment({
4545
issueIdOrKey: issue.key,
4646
id: comment.id,
4747
comment: 'updated comment',
4848
});
4949

50-
t.truthy(!!updatedComment);
51-
t.is(updatedComment.id, comment.id);
50+
expect(!!updatedComment).toBeTruthy();
51+
expect(updatedComment.id).toBe(comment.id);
5252

5353
await client.issues.deleteIssue({
5454
issueIdOrKey: issue.key,
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import test from 'ava';
1+
import { afterAll, beforeAll, test } from 'vitest';
22
import { cleanupEnvironment, getVersion2Client, prepareEnvironment } from '../utils/index.js';
33

4-
test.before(async () => {
4+
beforeAll(async () => {
55
await prepareEnvironment();
66
});
77

8-
test.after(async () => {
8+
afterAll(async () => {
99
await cleanupEnvironment();
1010
});
1111

12-
test.serial('searchForIssuesUsingJql should correctly calls', async t => {
12+
test.sequential('searchForIssuesUsingJql should correctly calls', async ({ expect }) => {
1313
const client = getVersion2Client({ noCheckAtlassianToken: true });
1414

1515
const issues = await client.issueSearch.searchForIssuesUsingJql({
1616
jql: 'assignee=currentuser()',
1717
});
1818

19-
t.is(issues.startAt, 0);
20-
t.is(issues.maxResults, 50);
21-
t.deepEqual(issues.issues, []);
19+
expect(issues.startAt).toBe(0);
20+
expect(issues.maxResults).toBe(50);
21+
expect(issues.issues).toStrictEqual([]);
2222
});

0 commit comments

Comments
 (0)