Skip to content

Commit

Permalink
Address feedback p1
Browse files Browse the repository at this point in the history
  • Loading branch information
kemmerle committed Jan 17, 2025
1 parent aad6d1b commit ee15a6b
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions lib/__tests__/dependencyManagement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ jest.mock('fs', () => ({
...jest.requireActual('fs'),
existsSync: jest.fn().mockReturnValue(true),
}));
jest.mock('util');

import util from 'util';
import { promisify } from 'util';
import {
isGloballyInstalled,
installPackages,
Expand All @@ -33,9 +34,7 @@ describe('lib/dependencyManagement', () => {

beforeEach(() => {
execMock = jest.fn();
util.promisify = jest
.fn()
.mockReturnValue(execMock) as unknown as typeof util.promisify;
(promisify as unknown as jest.Mock).mockReturnValue(execMock);
(getProjectConfig as jest.Mock).mockResolvedValue({
projectDir,
projectConfig: {
Expand All @@ -53,9 +52,7 @@ describe('lib/dependencyManagement', () => {
.fn()
.mockResolvedValueOnce({ stdout: JSON.stringify({ latest, next }) });

util.promisify = jest
.fn()
.mockReturnValueOnce(execMock) as unknown as typeof util.promisify;
(promisify as unknown as jest.Mock).mockReturnValue(execMock);
const actual = await getLatestCliVersion();
expect(actual).toEqual({ latest, next });
});
Expand All @@ -65,9 +62,7 @@ describe('lib/dependencyManagement', () => {
execMock = jest.fn().mockImplementationOnce(() => {
throw new Error(errorMessage);
});
util.promisify = jest
.fn()
.mockReturnValueOnce(execMock) as unknown as typeof util.promisify;
(promisify as unknown as jest.Mock).mockReturnValue(execMock);
await expect(() => getLatestCliVersion()).rejects.toThrowError(
errorMessage
);
Expand All @@ -86,9 +81,7 @@ describe('lib/dependencyManagement', () => {
execMock = jest.fn().mockImplementationOnce(() => {
throw new Error('unsuccessful');
});
util.promisify = jest
.fn()
.mockReturnValueOnce(execMock) as unknown as typeof util.promisify;
(promisify as unknown as jest.Mock).mockReturnValue(execMock);
const actual = await isGloballyInstalled('npm');
expect(actual).toBe(false);
expect(execMock).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -186,9 +179,7 @@ describe('lib/dependencyManagement', () => {
}
});

util.promisify = jest
.fn()
.mockReturnValue(execMock) as unknown as typeof util.promisify;
(promisify as unknown as jest.Mock).mockReturnValue(execMock);

const installLocations = [
path.join(appFunctionsDir, 'package.json'),
Expand Down Expand Up @@ -239,9 +230,7 @@ describe('lib/dependencyManagement', () => {
execMock = jest.fn().mockImplementation(() => {
throw new Error('OH NO');
});
util.promisify = jest
.fn()
.mockReturnValue(execMock) as unknown as typeof util.promisify;
(promisify as unknown as jest.Mock).mockReturnValue(execMock);
await expect(() => getProjectPackageJsonLocations()).rejects.toThrowError(
/This command depends on npm, install/
);
Expand Down

0 comments on commit ee15a6b

Please sign in to comment.