Skip to content

Commit

Permalink
test: switch to vitest (#124)
Browse files Browse the repository at this point in the history
* test: switch to vitest

* ci: use yarn not npm
  • Loading branch information
dsanders11 authored Oct 4, 2024
1 parent 485fca6 commit 8cb252f
Show file tree
Hide file tree
Showing 7 changed files with 536 additions and 1,983 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
node-version: lts/*
- name: Lint
run: |
npm install
npm run lint
yarn install
yarn lint
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # tag: v4.0.4
with:
node-version: lts/*
- name: npm install, build, and test
- name: yarn install, build, and test
run: |
npm install
npm test
yarn install
yarn test
18 changes: 0 additions & 18 deletions jest.config.js

This file was deleted.

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@
},
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/jest": "^29.0.3",
"@types/node": "^16.11.7",
"husky": "^8.0.0",
"jest": "^29.0.3",
"lint-staged": "^13.0.4",
"nock": "^13.5.5",
"prettier": "^2.7.1",
"ts-jest": "^29.0.1",
"typescript": "^5.6.2"
"typescript": "^5.6.2",
"vitest": "^2.1.2"
},
"scripts": {
"build": "tsc",
"lint": "prettier --list-different \"src/**/*.{ts,tsx}\"",
"prettier:write": "prettier --write \"src/**/*.{ts,tsx}\"",
"postinstall": "tsc",
"start": "DEBUG=* probot run ./lib/index.js",
"test": "jest",
"test:watch": "jest --watch",
"test": "vitest run",
"test:watch": "vitest watch",
"prepare": "husky install"
},
"lint-staged": {
Expand Down
20 changes: 11 additions & 9 deletions test/comment.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import nock from 'nock';
import { Probot } from 'probot';

import { probotRunner } from '../src/index';
import * as noteUtils from '../src/note-utils';
import { SEMANTIC_BUILD_PREFIX } from '../src/constants';
import { PullRequestOpenedEvent, PullRequestClosedEvent } from '@octokit/webhooks-types';

const nock = require('nock');

const GH_API = 'https://api.github.com';

describe('probotRunner', () => {
Expand All @@ -24,13 +26,13 @@ describe('probotRunner', () => {
});

afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
nock.cleanAll();
nock.enableNetConnect();
});

it('should post a failure status if release notes are missing', async () => {
jest.spyOn(noteUtils, 'findNoteInPRBody').mockReturnValue(null);
vi.spyOn(noteUtils, 'findNoteInPRBody').mockReturnValue(null);

const payload = {
action: 'opened',
Expand Down Expand Up @@ -67,7 +69,7 @@ describe('probotRunner', () => {
});

it('should add "Notes: none" to Dependabot PR body', async () => {
jest.spyOn(noteUtils, 'findNoteInPRBody').mockReturnValue(null);
vi.spyOn(noteUtils, 'findNoteInPRBody').mockReturnValue(null);

const payload = {
action: 'opened',
Expand Down Expand Up @@ -97,7 +99,7 @@ describe('probotRunner', () => {
});

it('should add "Notes: none" to build PR body', async () => {
jest.spyOn(noteUtils, 'findNoteInPRBody').mockReturnValue(null);
vi.spyOn(noteUtils, 'findNoteInPRBody').mockReturnValue(null);

const payload = {
action: 'opened',
Expand Down Expand Up @@ -125,7 +127,7 @@ describe('probotRunner', () => {
});

it('should post a success status if release notes are found', async () => {
jest.spyOn(noteUtils, 'findNoteInPRBody').mockReturnValue('Notes: added a new feature');
vi.spyOn(noteUtils, 'findNoteInPRBody').mockReturnValue('Notes: added a new feature');

const payload = {
action: 'opened',
Expand Down Expand Up @@ -163,8 +165,8 @@ describe('probotRunner', () => {

it('should create a comment if release notes are found and shouldComment is true', async () => {
const releaseNotesComment = 'Comment from release notes';
jest.spyOn(noteUtils, 'findNoteInPRBody').mockReturnValue('Added a new feature');
jest.spyOn(noteUtils, 'createPRCommentFromNotes').mockReturnValue(releaseNotesComment);
vi.spyOn(noteUtils, 'findNoteInPRBody').mockReturnValue('Added a new feature');
vi.spyOn(noteUtils, 'createPRCommentFromNotes').mockReturnValue(releaseNotesComment);

const payload = {
action: 'closed',
Expand Down
2 changes: 2 additions & 0 deletions test/note.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import * as constants from '../src/constants';
import * as noteUtils from '../src/note-utils';

Expand Down
Loading

0 comments on commit 8cb252f

Please sign in to comment.