Skip to content

Commit

Permalink
rework: use vitest instead of jest
Browse files Browse the repository at this point in the history
* also update dependencies
* remove jest related files
  • Loading branch information
jamacku committed Nov 21, 2024
1 parent 8377c53 commit 78c331b
Show file tree
Hide file tree
Showing 26 changed files with 1,230 additions and 2,577 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ jobs:
- name: Compile
run: yarn run build

- name: Start Bugzilla
run: ./itest/start_container.sh

- name: Test
run: yarn jest -c jest.ci.config.js --coverage
run: yarn run test

- name: Codecov
uses: codecov/codecov-action@v4
Expand Down
4 changes: 2 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/.github
/coverage
/scripts
/jest.ci.config.js
/jest.config.js
/vitest.ci.config.js
/vitest.config.js
/tsconfig.*
/test
/itest
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ lib/**/*

# Dependency directory
node_modules

.yarn/*
5 changes: 0 additions & 5 deletions itest/.eslintrc.js

This file was deleted.

32 changes: 32 additions & 0 deletions itest/bugzilla-environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { spawnSync } from 'child_process';
import path from 'path';
import type { Environment } from 'vitest/environments';

export default <Environment>{
name: 'server',
transformMode: 'ssr',
setup() {
spawnSync(path.join(__dirname, 'start_container.sh'), {
stdio: 'inherit',
});

spawnSync('docker', ['exec', 'integration', '/usr/local/bin/backup-db'], {
stdio: 'inherit',
});

return {
teardown() {
spawnSync(
'docker',
['exec', 'integration', '/usr/local/bin/restore-db'],
{
stdio: 'inherit',
},
);
spawnSync(path.join(__dirname, 'stop_container.sh'), {
stdio: 'inherit',
});
},
};
},
};
7 changes: 0 additions & 7 deletions itest/jest.ci.config.js

This file was deleted.

20 changes: 0 additions & 20 deletions itest/jest.config.js

This file was deleted.

8 changes: 0 additions & 8 deletions itest/setup.js

This file was deleted.

8 changes: 0 additions & 8 deletions itest/teardown.js

This file was deleted.

4 changes: 4 additions & 0 deletions itest/test/attachments.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// @vitest-environment bugzilla-environment

import { afterAll, beforeAll, expect, test } from 'vitest';

import BugzillaAPI from '../../src';

let api: BugzillaAPI;
Expand Down
4 changes: 4 additions & 0 deletions itest/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// @vitest-environment bugzilla-environment

import { expect, test } from 'vitest';

import BugzillaAPI from '../../src';

test('Public access', async () => {
Expand Down
4 changes: 4 additions & 0 deletions itest/test/bugs.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// @vitest-environment bugzilla-environment

import { afterEach, beforeEach, expect, test } from 'vitest';

import BugzillaAPI from '../../src';

let api: BugzillaAPI;
Expand Down
10 changes: 7 additions & 3 deletions itest/test/comments.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// @vitest-environment bugzilla-environment

import { afterEach, beforeEach, expect, test } from 'vitest';

import BugzillaAPI from '../../src';

let api: BugzillaAPI;
Expand Down Expand Up @@ -41,14 +45,14 @@ test('Create comment', async () => {
test('getComment', async () => {
await expect(api.getComment(3)).resolves.toEqual({
attachment_id: null,
bug_id: 3,
count: 0,
bug_id: 1,
count: 1,
creation_time: expect.anything(),
creator: '[email protected]',
id: 3,
is_private: false,
tags: [],
text: 'This is a test bug',
text: 'First comment!',
time: expect.anything(),
});
});
Expand Down
13 changes: 0 additions & 13 deletions itest/testSetup.js

This file was deleted.

14 changes: 0 additions & 14 deletions jest.ci.config.js

This file was deleted.

8 changes: 0 additions & 8 deletions jest.config.js

This file was deleted.

26 changes: 12 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"scripts": {
"build": "tsc -b tsconfig.build.json",
"build": "tsc",
"format": "prettier --write .",
"format-check": "prettier --check .",
"test": "jest",
"itest": "jest -c itest/jest.config.js",
"update-snapshots": "jest --updateSnapshot",
"test": "vitest run --coverage",
"all": "yarn run build && yarn run format-check && yarn run test",
"update-snapshots": "vitest run --update",
"prepack": "yarn run build",
"version": "node scripts/version.js && git add CHANGELOG.md",
"postversion": "node scripts/post-version.js && git add CHANGELOG.md && git commit -m 'Update CHANGELOG.md'"
Expand All @@ -34,19 +34,17 @@
},
"homepage": "https://github.com/redhat-plumbers-in-action/bugzilla#readme",
"devDependencies": {
"@mossop/config": "1.4.1",
"@types/jest": "29.5.12",
"@types/luxon": "3.4.2",
"@types/node": "20.12.11",
"jest": "29.7.0",
"msw": "2.3.0",
"prettier": "3.2.5",
"ts-jest": "29.1.2",
"typescript": "5.4.5"
"@types/node": "22.9.1",
"@vitest/coverage-v8": "^2.1.5",
"msw": "2.6.5",
"prettier": "3.3.3",
"typescript": "5.6.3",
"vitest": "^2.1.5"
},
"dependencies": {
"axios": "1.6.8",
"luxon": "3.4.4"
"axios": "1.7.7",
"luxon": "3.5.0"
},
"packageManager": "[email protected]"
}
12 changes: 9 additions & 3 deletions src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export function object<T>(
try {
result[field] = fieldValidator(val[field]);
} catch (e) {
throw new Error(`Error validating field '${field}': ${e.message}`);
throw new Error(
`Error validating field '${field}': ${e instanceof Error ? e.message : e}`,
);
}
}

Expand All @@ -53,7 +55,9 @@ export function array<T>(validator: Validator<T>): Validator<T[]> {
try {
return val.map(validator);
} catch (e) {
throw new Error(`Error validating array: ${e.message}`);
throw new Error(
`Error validating array: ${e instanceof Error ? e.message : e}`,
);
}
};
}
Expand Down Expand Up @@ -138,7 +142,9 @@ export function maybeArray<T>(validator: Validator<T>): Validator<T | T[]> {
try {
return val.map(validator);
} catch (e) {
throw new Error(`Error validating array: ${e.message}`);
throw new Error(
`Error validating array: ${e instanceof Error ? e.message : e}`,
);
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest';

import BugzillaAPI from '../src';

// Tests that rely on the network are not ideal but it's hard to otherwise
Expand Down
9 changes: 5 additions & 4 deletions test/link.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { URL } from 'url';
import { afterAll, afterEach, beforeAll, expect, test, vi } from 'vitest';

import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
Expand All @@ -15,7 +16,7 @@ afterAll(() => server.close());
test('PublicLink', async () => {
let link = new PublicLink(new URL('http://bugzilla.test.org/test/'));

let responseHandler = jest.fn(
let responseHandler = vi.fn(
() =>
new HttpResponse(
JSON.stringify({
Expand Down Expand Up @@ -58,7 +59,7 @@ test('ApiKeyLink', async () => {
'my-api-key',
);

let responseHandler = jest.fn(
let responseHandler = vi.fn(
() =>
new HttpResponse(
JSON.stringify({
Expand Down Expand Up @@ -103,7 +104,7 @@ test('PasswordLink', async () => {
true,
);

let loginHandler = jest.fn(
let loginHandler = vi.fn(
() =>
new HttpResponse(
JSON.stringify({
Expand All @@ -117,7 +118,7 @@ test('PasswordLink', async () => {
http.get('http://bugzilla.test.org/test/rest/login', loginHandler),
);

let responseHandler = jest.fn(
let responseHandler = vi.fn(
() =>
new HttpResponse(
JSON.stringify({
Expand Down
Loading

0 comments on commit 78c331b

Please sign in to comment.