Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Node.js version, editor settings, jest, and linting configurations #567

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate jest to vitest
kamiazya committed Feb 5, 2024
commit d30e381cd293dff2bbea66dc9585b4527a4e6760
9 changes: 0 additions & 9 deletions jest.config.ts

This file was deleted.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -14,25 +14,22 @@
"lint": "eslint src && prettier --check src/**/*.ts",
"format": "prettier --write src/**/*.ts",
"build": "tsc",
"test": "jest"
"test": "vitest"
},
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/tool-cache": "^2.0.1"
},
"devDependencies": {
"@types/jest": "^28.1.7",
"@types/node": "^20.11.13",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"eslint": "^8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.8.3",
"jest": "^28.1.3",
"prettier": "^2.7.1",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
"typescript": "^5.3.2",
"vitest": "^1.2.2"
}
}
115 changes: 58 additions & 57 deletions src/__tests__/GraphvizInstaller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
jest.mock('@actions/core');
jest.mock('@actions/exec');
import { vi, describe, beforeEach, beforeAll, afterAll, it, test, expect, MockInstance } from 'vitest';
vi.mock('@actions/core');
vi.mock('@actions/exec');

import { getInput, getBooleanInput } from '@actions/core';
import * as exec from '@actions/exec';
@@ -13,7 +14,7 @@ describe('class GraphvizInstaller', () => {
Object.defineProperty(process, 'platform', { value: platform });
};

const mockNamedInputs = (mock: jest.Mock, name: string, value: string | boolean) => {
const mockNamedInputs = (mock: MockInstance, name: string, value: string | boolean) => {
mock.mockImplementation((input: string) => {
if (input == name)
return value;
@@ -23,7 +24,7 @@ describe('class GraphvizInstaller', () => {

beforeEach(() => {
installer = new GraphvizInstaller();
jest.clearAllMocks();
vi.clearAllMocks();
});

describe('Supported platforms', () => {
@@ -33,7 +34,7 @@ describe('class GraphvizInstaller', () => {
});

it('brewInstall method called on "darwin" platform', async () => {
const brewInstall = jest.fn();
const brewInstall = vi.fn();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(installer as any).brewInstall = brewInstall;

@@ -44,41 +45,41 @@ describe('class GraphvizInstaller', () => {

describe('inputs works', () => {
test('default', async () => {
mockNamedInputs(getBooleanInput as jest.Mock, 'macos-skip-brew-update', false);
const execSpy = jest.spyOn(exec, 'exec');
mockNamedInputs(getBooleanInput as unknown as MockInstance, 'macos-skip-brew-update', false);
const execSpy = vi.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(2);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"brew",
Array [
[
"update",
],
]
`);
expect(execSpy.mock.calls[1]).toMatchInlineSnapshot(`
Array [
[
"brew",
Array [
[
"install",
"graphviz",
],
]
`);
});
test('skip brew update', async () => {
mockNamedInputs(getBooleanInput as jest.Mock, 'macos-skip-brew-update', true);
const execSpy = jest.spyOn(exec, 'exec');
mockNamedInputs(getBooleanInput as unknown as MockInstance, 'macos-skip-brew-update', true);
const execSpy = vi.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(1);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"brew",
Array [
[
"install",
"graphviz",
],
@@ -94,7 +95,7 @@ describe('class GraphvizInstaller', () => {
});

it('getAptInstall method called on "linux" platform', async () => {
const getAptInstall = jest.fn();
const getAptInstall = vi.fn();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(installer as any).getAptInstall = getAptInstall;

@@ -105,16 +106,16 @@ describe('class GraphvizInstaller', () => {

describe('inputs works', () => {
test('skip apt update', async () => {
mockNamedInputs(getBooleanInput as jest.Mock, 'ubuntu-skip-apt-update', true);
const execSpy = jest.spyOn(exec, 'exec');
mockNamedInputs(getBooleanInput as unknown as MockInstance, 'ubuntu-skip-apt-update', true);
const execSpy = vi.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(1);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"sudo",
Array [
[
"apt-get",
"install",
"-y",
@@ -127,26 +128,26 @@ describe('class GraphvizInstaller', () => {
});

test('graphviz version not set', async () => {
(getInput as jest.Mock).mockReturnValue('');
(getBooleanInput as jest.Mock).mockReturnValue(false);
const execSpy = jest.spyOn(exec, 'exec');
(getInput as unknown as MockInstance).mockReturnValue('');
(getBooleanInput as unknown as MockInstance).mockReturnValue(false);
const execSpy = vi.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(2);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"sudo",
Array [
[
"apt-get",
"update",
],
]
`);
expect(execSpy.mock.calls[1]).toMatchInlineSnapshot(`
Array [
[
"sudo",
Array [
[
"apt-get",
"install",
"-y",
@@ -159,7 +160,7 @@ describe('class GraphvizInstaller', () => {
});

test('input graphviz version set to "1.1.1" and libgraphviz_dev version set to "2.2.2"', async () => {
(getInput as jest.Mock).mockImplementation((input) => {
(getInput as unknown as MockInstance).mockImplementation((input) => {
switch (input) {
case 'ubuntu-graphviz-version':
return '1.1.1';
@@ -169,25 +170,25 @@ describe('class GraphvizInstaller', () => {
return '';
}
});
(getBooleanInput as jest.Mock).mockReturnValue(false);
const execSpy = jest.spyOn(exec, 'exec');
(getBooleanInput as unknown as MockInstance).mockReturnValue(false);
const execSpy = vi.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(2);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"sudo",
Array [
[
"apt-get",
"update",
],
]
`);
expect(execSpy.mock.calls[1]).toMatchInlineSnapshot(`
Array [
[
"sudo",
Array [
[
"apt-get",
"install",
"-y",
@@ -200,33 +201,33 @@ describe('class GraphvizInstaller', () => {
});

test('input graphviz version set to "3.3.3" and libgraphviz_dev version not set', async () => {
(getInput as jest.Mock).mockImplementation((input) => {
(getInput as unknown as MockInstance).mockImplementation((input) => {
switch (input) {
case 'ubuntu-graphviz-version':
return '3.3.3';
default:
return '';
}
});
(getBooleanInput as jest.Mock).mockReturnValue(false);
const execSpy = jest.spyOn(exec, 'exec');
(getBooleanInput as unknown as MockInstance).mockReturnValue(false);
const execSpy = vi.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(2);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"sudo",
Array [
[
"apt-get",
"update",
],
]
`);
expect(execSpy.mock.calls[1]).toMatchInlineSnapshot(`
Array [
[
"sudo",
Array [
[
"apt-get",
"install",
"-y",
@@ -239,33 +240,33 @@ describe('class GraphvizInstaller', () => {
});

test('input graphviz not set and libgraphviz_dev set to 4.4.4', async () => {
(getInput as jest.Mock).mockImplementation((input) => {
(getInput as unknown as MockInstance).mockImplementation((input) => {
switch (input) {
case 'ubuntu-libgraphvizdev-version':
return '4.4.4';
default:
return '';
}
});
(getBooleanInput as jest.Mock).mockReturnValue(false);
const execSpy = jest.spyOn(exec, 'exec');
(getBooleanInput as unknown as MockInstance).mockReturnValue(false);
const execSpy = vi.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(2);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"sudo",
Array [
[
"apt-get",
"update",
],
]
`);
expect(execSpy.mock.calls[1]).toMatchInlineSnapshot(`
Array [
[
"sudo",
Array [
[
"apt-get",
"install",
"-y",
@@ -285,7 +286,7 @@ describe('class GraphvizInstaller', () => {
});

it('chocoInstall method called on "win32" platform', async () => {
const chocoInstall = jest.fn();
const chocoInstall = vi.fn();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(installer as any).chocoInstall = chocoInstall;

@@ -296,16 +297,16 @@ describe('class GraphvizInstaller', () => {

describe('inputs works', () => {
test('graphviz version not set', async () => {
(getInput as jest.Mock).mockReturnValue('');
const execSpy = jest.spyOn(exec, 'exec');
(getInput as unknown as MockInstance).mockReturnValue('');
const execSpy = vi.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(1);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"choco",
Array [
[
"install",
"graphviz",
],
@@ -314,16 +315,16 @@ describe('class GraphvizInstaller', () => {
});

test('graphviz version seted to "1.1.1"', async () => {
mockNamedInputs(getInput as jest.Mock, 'windows-graphviz-version', '1.1.1');
const execSpy = jest.spyOn(exec, 'exec');
mockNamedInputs(getInput as unknown as MockInstance, 'windows-graphviz-version', '1.1.1');
const execSpy = vi.spyOn(exec, 'exec');

await installer.get();

expect(execSpy).toBeCalledTimes(1);
expect(execSpy.mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"choco",
Array [
[
"install",
"graphviz",
"--version=1.1.1",
2,464 changes: 590 additions & 1,874 deletions yarn.lock

Large diffs are not rendered by default.