2023-09-01 06:13:19 -07:00
|
|
|
import { exec } from 'child_process';
|
|
|
|
import { access as fsAccess, mkdir as fsMkdir } from 'fs/promises';
|
|
|
|
import axios from 'axios';
|
2023-10-09 07:09:23 -07:00
|
|
|
import { mocked } from 'jest-mock';
|
|
|
|
import Container from 'typedi';
|
|
|
|
import type { PublicInstalledPackage } from 'n8n-workflow';
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
import {
|
|
|
|
NODE_PACKAGE_PREFIX,
|
|
|
|
NPM_COMMAND_TOKENS,
|
|
|
|
NPM_PACKAGE_STATUS_GOOD,
|
|
|
|
RESPONSE_ERROR_MESSAGES,
|
|
|
|
} from '@/constants';
|
|
|
|
import config from '@/config';
|
2023-10-09 07:09:23 -07:00
|
|
|
import { InstalledPackages } from '@db/entities/InstalledPackages';
|
2023-09-01 06:13:19 -07:00
|
|
|
import type { CommunityPackages } from '@/Interfaces';
|
2023-10-09 07:09:23 -07:00
|
|
|
import { CommunityPackagesService } from '@/services/communityPackages.service';
|
2023-11-10 06:04:26 -08:00
|
|
|
import { InstalledNodesRepository } from '@db/repositories/installedNodes.repository';
|
|
|
|
import { InstalledPackagesRepository } from '@db/repositories/installedPackages.repository';
|
|
|
|
import { InstalledNodes } from '@db/entities/InstalledNodes';
|
2023-10-09 07:09:23 -07:00
|
|
|
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
|
|
|
|
2023-11-10 06:04:26 -08:00
|
|
|
import { mockInstance } from '../../shared/mocking';
|
2023-09-01 06:13:19 -07:00
|
|
|
import {
|
|
|
|
COMMUNITY_NODE_VERSION,
|
|
|
|
COMMUNITY_PACKAGE_VERSION,
|
|
|
|
} from '../../integration/shared/constants';
|
2023-10-09 07:09:23 -07:00
|
|
|
import { randomName } from '../../integration/shared/random';
|
2023-11-10 06:04:26 -08:00
|
|
|
import { mockPackageName, mockPackagePair } from '../../integration/shared/utils';
|
2024-03-11 10:12:20 -07:00
|
|
|
import { InstanceSettings, PackageDirectoryLoader } from 'n8n-core';
|
|
|
|
import { Logger } from '@/Logger';
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
jest.mock('fs/promises');
|
|
|
|
jest.mock('child_process');
|
|
|
|
jest.mock('axios');
|
|
|
|
|
|
|
|
type ExecOptions = NonNullable<Parameters<typeof exec>[1]>;
|
|
|
|
type ExecCallback = NonNullable<Parameters<typeof exec>[2]>;
|
|
|
|
|
|
|
|
const execMock = ((...args) => {
|
|
|
|
const cb = args[args.length - 1] as ExecCallback;
|
|
|
|
cb(null, 'Done', '');
|
|
|
|
}) as typeof exec;
|
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
describe('CommunityPackagesService', () => {
|
2023-09-01 06:13:19 -07:00
|
|
|
const installedNodesRepository = mockInstance(InstalledNodesRepository);
|
|
|
|
installedNodesRepository.create.mockImplementation(() => {
|
|
|
|
const nodeName = randomName();
|
|
|
|
|
|
|
|
return Object.assign(new InstalledNodes(), {
|
|
|
|
name: nodeName,
|
|
|
|
type: nodeName,
|
|
|
|
latestVersion: COMMUNITY_NODE_VERSION.CURRENT.toString(),
|
|
|
|
packageName: 'test',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const installedPackageRepository = mockInstance(InstalledPackagesRepository);
|
|
|
|
installedPackageRepository.create.mockImplementation(() => {
|
|
|
|
return Object.assign(new InstalledPackages(), {
|
|
|
|
packageName: mockPackageName(),
|
|
|
|
installedVersion: COMMUNITY_PACKAGE_VERSION.CURRENT,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
mockInstance(LoadNodesAndCredentials);
|
|
|
|
|
|
|
|
const communityPackagesService = Container.get(CommunityPackagesService);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
config.load(config.default);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('parseNpmPackageName()', () => {
|
|
|
|
test('should fail with empty package name', () => {
|
2023-10-09 07:09:23 -07:00
|
|
|
expect(() => communityPackagesService.parseNpmPackageName('')).toThrowError();
|
2023-09-01 06:13:19 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should fail with invalid package prefix name', () => {
|
|
|
|
expect(() =>
|
2023-10-09 07:09:23 -07:00
|
|
|
communityPackagesService.parseNpmPackageName('INVALID_PREFIX@123'),
|
2023-09-01 06:13:19 -07:00
|
|
|
).toThrowError();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should parse valid package name', () => {
|
|
|
|
const name = mockPackageName();
|
2023-10-09 07:09:23 -07:00
|
|
|
const parsed = communityPackagesService.parseNpmPackageName(name);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(parsed.rawString).toBe(name);
|
|
|
|
expect(parsed.packageName).toBe(name);
|
|
|
|
expect(parsed.scope).toBeUndefined();
|
|
|
|
expect(parsed.version).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should parse valid package name and version', () => {
|
|
|
|
const name = mockPackageName();
|
|
|
|
const version = '0.1.1';
|
|
|
|
const fullPackageName = `${name}@${version}`;
|
2023-10-09 07:09:23 -07:00
|
|
|
const parsed = communityPackagesService.parseNpmPackageName(fullPackageName);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(parsed.rawString).toBe(fullPackageName);
|
|
|
|
expect(parsed.packageName).toBe(name);
|
|
|
|
expect(parsed.scope).toBeUndefined();
|
|
|
|
expect(parsed.version).toBe(version);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should parse valid package name, scope and version', () => {
|
|
|
|
const scope = '@n8n';
|
|
|
|
const name = mockPackageName();
|
|
|
|
const version = '0.1.1';
|
|
|
|
const fullPackageName = `${scope}/${name}@${version}`;
|
2023-10-09 07:09:23 -07:00
|
|
|
const parsed = communityPackagesService.parseNpmPackageName(fullPackageName);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(parsed.rawString).toBe(fullPackageName);
|
|
|
|
expect(parsed.packageName).toBe(`${scope}/${name}`);
|
|
|
|
expect(parsed.scope).toBe(scope);
|
|
|
|
expect(parsed.version).toBe(version);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('executeCommand()', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mocked(fsAccess).mockReset();
|
|
|
|
mocked(fsMkdir).mockReset();
|
|
|
|
mocked(exec).mockReset();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should call command with valid options', async () => {
|
|
|
|
const execMock = ((...args) => {
|
|
|
|
const arg = args[1] as ExecOptions;
|
|
|
|
expect(arg.cwd).toBeDefined();
|
|
|
|
expect(arg.env).toBeDefined();
|
|
|
|
// PATH or NODE_PATH may be undefined depending on environment so we don't check for these keys.
|
|
|
|
const cb = args[args.length - 1] as ExecCallback;
|
|
|
|
cb(null, 'Done', '');
|
|
|
|
}) as typeof exec;
|
|
|
|
|
|
|
|
mocked(exec).mockImplementation(execMock);
|
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
await communityPackagesService.executeNpmCommand('ls');
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(fsAccess).toHaveBeenCalled();
|
|
|
|
expect(exec).toHaveBeenCalled();
|
|
|
|
expect(fsMkdir).toBeCalledTimes(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should make sure folder exists', async () => {
|
|
|
|
mocked(exec).mockImplementation(execMock);
|
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
await communityPackagesService.executeNpmCommand('ls');
|
2023-09-01 06:13:19 -07:00
|
|
|
expect(fsAccess).toHaveBeenCalled();
|
|
|
|
expect(exec).toHaveBeenCalled();
|
|
|
|
expect(fsMkdir).toBeCalledTimes(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should try to create folder if it does not exist', async () => {
|
|
|
|
mocked(exec).mockImplementation(execMock);
|
|
|
|
mocked(fsAccess).mockImplementation(() => {
|
|
|
|
throw new Error('Folder does not exist.');
|
|
|
|
});
|
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
await communityPackagesService.executeNpmCommand('ls');
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(fsAccess).toHaveBeenCalled();
|
|
|
|
expect(exec).toHaveBeenCalled();
|
|
|
|
expect(fsMkdir).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should throw especial error when package is not found', async () => {
|
|
|
|
const erroringExecMock = ((...args) => {
|
|
|
|
const cb = args[args.length - 1] as ExecCallback;
|
|
|
|
const msg = `Something went wrong - ${NPM_COMMAND_TOKENS.NPM_PACKAGE_NOT_FOUND_ERROR}. Aborting.`;
|
|
|
|
cb(new Error(msg), '', '');
|
|
|
|
}) as typeof exec;
|
|
|
|
|
|
|
|
mocked(exec).mockImplementation(erroringExecMock);
|
|
|
|
|
2024-01-17 07:08:50 -08:00
|
|
|
const call = async () => await communityPackagesService.executeNpmCommand('ls');
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
await expect(call).rejects.toThrowError(RESPONSE_ERROR_MESSAGES.PACKAGE_NOT_FOUND);
|
|
|
|
|
|
|
|
expect(fsAccess).toHaveBeenCalled();
|
|
|
|
expect(exec).toHaveBeenCalled();
|
|
|
|
expect(fsMkdir).toHaveBeenCalledTimes(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('crossInformationPackage()', () => {
|
|
|
|
test('should return same list if availableUpdates is undefined', () => {
|
|
|
|
const fakePkgs = mockPackagePair();
|
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
const crossedPkgs = communityPackagesService.matchPackagesWithUpdates(fakePkgs);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(crossedPkgs).toEqual(fakePkgs);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should correctly match update versions for packages', () => {
|
|
|
|
const [pkgA, pkgB] = mockPackagePair();
|
|
|
|
|
|
|
|
const updates: CommunityPackages.AvailableUpdates = {
|
|
|
|
[pkgA.packageName]: {
|
|
|
|
current: pkgA.installedVersion,
|
|
|
|
wanted: pkgA.installedVersion,
|
|
|
|
latest: '0.2.0',
|
|
|
|
location: pkgA.packageName,
|
|
|
|
},
|
|
|
|
[pkgB.packageName]: {
|
|
|
|
current: pkgA.installedVersion,
|
|
|
|
wanted: pkgA.installedVersion,
|
|
|
|
latest: '0.3.0',
|
|
|
|
location: pkgA.packageName,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const [crossedPkgA, crossedPkgB]: PublicInstalledPackage[] =
|
2023-10-09 07:09:23 -07:00
|
|
|
communityPackagesService.matchPackagesWithUpdates([pkgA, pkgB], updates);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(crossedPkgA.updateAvailable).toBe('0.2.0');
|
|
|
|
expect(crossedPkgB.updateAvailable).toBe('0.3.0');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should correctly match update versions for single package', () => {
|
|
|
|
const [pkgA, pkgB] = mockPackagePair();
|
|
|
|
|
|
|
|
const updates: CommunityPackages.AvailableUpdates = {
|
|
|
|
[pkgB.packageName]: {
|
|
|
|
current: pkgA.installedVersion,
|
|
|
|
wanted: pkgA.installedVersion,
|
|
|
|
latest: '0.3.0',
|
|
|
|
location: pkgA.packageName,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const [crossedPkgA, crossedPkgB]: PublicInstalledPackage[] =
|
2023-10-09 07:09:23 -07:00
|
|
|
communityPackagesService.matchPackagesWithUpdates([pkgA, pkgB], updates);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(crossedPkgA.updateAvailable).toBeUndefined();
|
|
|
|
expect(crossedPkgB.updateAvailable).toBe('0.3.0');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('matchMissingPackages()', () => {
|
|
|
|
test('should not match failed packages that do not exist', () => {
|
|
|
|
const fakePkgs = mockPackagePair();
|
2023-10-09 07:09:23 -07:00
|
|
|
setMissingPackages([
|
|
|
|
`${NODE_PACKAGE_PREFIX}very-long-name-that-should-never-be-generated@1.0.0`,
|
|
|
|
`${NODE_PACKAGE_PREFIX}another-very-long-name-that-never-is-seen`,
|
|
|
|
]);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
const matchedPackages = communityPackagesService.matchMissingPackages(fakePkgs);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(matchedPackages).toEqual(fakePkgs);
|
|
|
|
|
|
|
|
const [first, second] = matchedPackages;
|
|
|
|
|
|
|
|
expect(first.failedLoading).toBeUndefined();
|
|
|
|
expect(second.failedLoading).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should match failed packages that should be present', () => {
|
|
|
|
const [pkgA, pkgB] = mockPackagePair();
|
2023-10-09 07:09:23 -07:00
|
|
|
setMissingPackages([
|
|
|
|
`${NODE_PACKAGE_PREFIX}very-long-name-that-should-never-be-generated@1.0.0`,
|
|
|
|
`${pkgA.packageName}@${pkgA.installedVersion}`,
|
|
|
|
]);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
const [matchedPkgA, matchedPkgB] = communityPackagesService.matchMissingPackages([
|
|
|
|
pkgA,
|
|
|
|
pkgB,
|
|
|
|
]);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(matchedPkgA.failedLoading).toBe(true);
|
|
|
|
expect(matchedPkgB.failedLoading).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should match failed packages even if version is wrong', () => {
|
|
|
|
const [pkgA, pkgB] = mockPackagePair();
|
2023-10-09 07:09:23 -07:00
|
|
|
setMissingPackages([
|
|
|
|
`${NODE_PACKAGE_PREFIX}very-long-name-that-should-never-be-generated@1.0.0`,
|
|
|
|
`${pkgA.packageName}@123.456.789`,
|
|
|
|
]);
|
|
|
|
const [matchedPkgA, matchedPkgB] = communityPackagesService.matchMissingPackages([
|
|
|
|
pkgA,
|
|
|
|
pkgB,
|
|
|
|
]);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(matchedPkgA.failedLoading).toBe(true);
|
|
|
|
expect(matchedPkgB.failedLoading).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('checkNpmPackageStatus()', () => {
|
|
|
|
test('should call axios.post', async () => {
|
2023-10-09 07:09:23 -07:00
|
|
|
await communityPackagesService.checkNpmPackageStatus(mockPackageName());
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(axios.post).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not fail if request fails', async () => {
|
|
|
|
mocked(axios.post).mockImplementation(() => {
|
|
|
|
throw new Error('Something went wrong');
|
|
|
|
});
|
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
const result = await communityPackagesService.checkNpmPackageStatus(mockPackageName());
|
2023-09-01 06:13:19 -07:00
|
|
|
|
|
|
|
expect(result.status).toBe(NPM_PACKAGE_STATUS_GOOD);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should warn if package is banned', async () => {
|
|
|
|
mocked(axios.post).mockResolvedValue({ data: { status: 'Banned', reason: 'Not good' } });
|
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
const result = (await communityPackagesService.checkNpmPackageStatus(
|
2023-09-01 06:13:19 -07:00
|
|
|
mockPackageName(),
|
|
|
|
)) as CommunityPackages.PackageStatusCheck;
|
|
|
|
|
|
|
|
expect(result.status).toBe('Banned');
|
|
|
|
expect(result.reason).toBe('Not good');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hasPackageLoadedSuccessfully()', () => {
|
|
|
|
test('should return true when failed package list does not exist', () => {
|
2023-10-09 07:09:23 -07:00
|
|
|
setMissingPackages([]);
|
|
|
|
expect(communityPackagesService.hasPackageLoaded('package')).toBe(true);
|
2023-09-01 06:13:19 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should return true when package is not in the list of missing packages', () => {
|
2023-10-09 07:09:23 -07:00
|
|
|
setMissingPackages(['packageA@0.1.0', 'packageB@0.1.0']);
|
|
|
|
expect(communityPackagesService.hasPackageLoaded('packageC')).toBe(true);
|
2023-09-01 06:13:19 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should return false when package is in the list of missing packages', () => {
|
2023-10-09 07:09:23 -07:00
|
|
|
setMissingPackages(['packageA@0.1.0', 'packageB@0.1.0']);
|
|
|
|
expect(communityPackagesService.hasPackageLoaded('packageA')).toBe(false);
|
2023-09-01 06:13:19 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removePackageFromMissingList()', () => {
|
|
|
|
test('should do nothing if key does not exist', () => {
|
2023-10-09 07:09:23 -07:00
|
|
|
setMissingPackages([]);
|
|
|
|
communityPackagesService.removePackageFromMissingList('packageA');
|
2023-09-01 06:13:19 -07:00
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
expect(communityPackagesService.missingPackages).toBeEmptyArray();
|
2023-09-01 06:13:19 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should remove only correct package from list', () => {
|
2023-10-09 07:09:23 -07:00
|
|
|
setMissingPackages(['packageA@0.1.0', 'packageB@0.2.0', 'packageC@0.2.0']);
|
2023-09-01 06:13:19 -07:00
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
communityPackagesService.removePackageFromMissingList('packageB');
|
2023-09-01 06:13:19 -07:00
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
expect(communityPackagesService.missingPackages).toEqual([
|
|
|
|
'packageA@0.1.0',
|
|
|
|
'packageC@0.2.0',
|
|
|
|
]);
|
2023-09-01 06:13:19 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should not remove if package is not in the list', () => {
|
2023-10-09 07:09:23 -07:00
|
|
|
const failedToLoadList = ['packageA@0.1.0', 'packageB@0.2.0', 'packageB@0.2.0'];
|
|
|
|
setMissingPackages(failedToLoadList);
|
|
|
|
communityPackagesService.removePackageFromMissingList('packageC');
|
2023-09-01 06:13:19 -07:00
|
|
|
|
2023-10-09 07:09:23 -07:00
|
|
|
expect(communityPackagesService.missingPackages).toEqual(failedToLoadList);
|
2023-09-01 06:13:19 -07:00
|
|
|
});
|
|
|
|
});
|
2023-10-09 07:09:23 -07:00
|
|
|
|
|
|
|
const setMissingPackages = (missingPackages: string[]) => {
|
|
|
|
Object.assign(communityPackagesService, { missingPackages });
|
|
|
|
};
|
2024-03-11 10:12:20 -07:00
|
|
|
|
|
|
|
describe('updateNpmModule', () => {
|
|
|
|
let packageDirectoryLoader: PackageDirectoryLoader;
|
|
|
|
let communityPackagesService: CommunityPackagesService;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
jest.restoreAllMocks();
|
|
|
|
|
|
|
|
packageDirectoryLoader = mockInstance(PackageDirectoryLoader);
|
|
|
|
const loadNodesAndCredentials = mockInstance(LoadNodesAndCredentials);
|
|
|
|
loadNodesAndCredentials.loadPackage.mockResolvedValue(packageDirectoryLoader);
|
|
|
|
const instanceSettings = mockInstance(InstanceSettings);
|
|
|
|
const logger = mockInstance(Logger);
|
|
|
|
const installedPackagesRepository = mockInstance(InstalledPackagesRepository);
|
|
|
|
|
|
|
|
communityPackagesService = new CommunityPackagesService(
|
|
|
|
instanceSettings,
|
|
|
|
logger,
|
|
|
|
installedPackagesRepository,
|
|
|
|
loadNodesAndCredentials,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
jest.restoreAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should call `exec` with the correct command ', async () => {
|
|
|
|
//
|
|
|
|
// ARRANGE
|
|
|
|
//
|
|
|
|
const nodeName = randomName();
|
|
|
|
packageDirectoryLoader.loadedNodes = [{ name: nodeName, version: 1 }];
|
|
|
|
|
|
|
|
const installedPackage = new InstalledPackages();
|
|
|
|
installedPackage.packageName = mockPackageName();
|
|
|
|
|
|
|
|
mocked(exec).mockImplementation(execMock);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ACT
|
|
|
|
//
|
|
|
|
await communityPackagesService.updateNpmModule(
|
|
|
|
installedPackage.packageName,
|
|
|
|
installedPackage,
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ASSERT
|
|
|
|
//
|
|
|
|
|
|
|
|
expect(exec).toHaveBeenCalledTimes(1);
|
|
|
|
expect(exec).toHaveBeenNthCalledWith(
|
|
|
|
1,
|
|
|
|
`npm install ${installedPackage.packageName}@latest`,
|
|
|
|
expect.any(Object),
|
|
|
|
expect.any(Function),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2023-09-01 06:13:19 -07:00
|
|
|
});
|