Skip to content

Commit

Permalink
Fix version variable name in Windows (#507)
Browse files Browse the repository at this point in the history
The version variable for windows was `window-graphviz-version`
instead of `windows-graphviz-version`.
Make the tests more strict too, to catch this kind of error.
  • Loading branch information
Maetveis authored Feb 5, 2024
1 parent 91a96bc commit 0844827
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/GraphvizInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class GraphvizInstaller {
}

private async chocoInstall() {
const graphvizVersion = getInput('window-graphviz-version');
const graphvizVersion = getInput('windows-graphviz-version');
await exec('choco', [
'install',
'graphviz',
Expand Down
26 changes: 17 additions & 9 deletions src/__tests__/GraphvizInstaller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ describe('class GraphvizInstaller', () => {
Object.defineProperty(process, 'platform', { value: platform });
};

const mockNamedInputs = (mock: jest.Mock, name: string, value: string | boolean) => {
mock.mockImplementation((input: string) => {
if (input == name)
return value;
return typeof value === 'string' ? '' : false;
})
};

beforeEach(() => {
installer = new GraphvizInstaller();
jest.clearAllMocks();
Expand All @@ -36,7 +44,7 @@ describe('class GraphvizInstaller', () => {

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

await installer.get();
Expand All @@ -61,7 +69,7 @@ describe('class GraphvizInstaller', () => {
`);
});
test('skip brew update', async () => {
(getBooleanInput as jest.Mock).mockReturnValue(true);
mockNamedInputs(getBooleanInput as jest.Mock, 'macos-skip-brew-update', true);
const execSpy = jest.spyOn(exec, 'exec');

await installer.get();
Expand Down Expand Up @@ -97,7 +105,7 @@ describe('class GraphvizInstaller', () => {

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

await installer.get();
Expand All @@ -118,7 +126,7 @@ describe('class GraphvizInstaller', () => {
`);
});

test('graphviz version not seted', async () => {
test('graphviz version not set', async () => {
(getInput as jest.Mock).mockReturnValue('');
(getBooleanInput as jest.Mock).mockReturnValue(false);
const execSpy = jest.spyOn(exec, 'exec');
Expand Down Expand Up @@ -150,7 +158,7 @@ describe('class GraphvizInstaller', () => {
`);
});

test('input graphviz version seted to "1.1.1" and libgraphviz_dev version seted to "2.2.2"', async () => {
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) => {
switch (input) {
case 'ubuntu-graphviz-version':
Expand Down Expand Up @@ -191,7 +199,7 @@ describe('class GraphvizInstaller', () => {
`);
});

test('input graphviz version seted to "3.3.3" and libgraphviz_dev version not seted', async () => {
test('input graphviz version set to "3.3.3" and libgraphviz_dev version not set', async () => {
(getInput as jest.Mock).mockImplementation((input) => {
switch (input) {
case 'ubuntu-graphviz-version':
Expand Down Expand Up @@ -230,7 +238,7 @@ describe('class GraphvizInstaller', () => {
`);
});

test('input graphviz not seted and libgraphviz_dev seted to 4.4.4', async () => {
test('input graphviz not set and libgraphviz_dev set to 4.4.4', async () => {
(getInput as jest.Mock).mockImplementation((input) => {
switch (input) {
case 'ubuntu-libgraphvizdev-version':
Expand Down Expand Up @@ -287,7 +295,7 @@ describe('class GraphvizInstaller', () => {
});

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

Expand All @@ -306,7 +314,7 @@ describe('class GraphvizInstaller', () => {
});

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

await installer.get();
Expand Down

0 comments on commit 0844827

Please sign in to comment.