diff --git a/lib/manager/html/update.spec.ts b/lib/manager/html/update.spec.ts index d3912ec548bc1e862e4571dc35ade4881dc49fdf..d9cdbb5f85f859f347a7a07c5db866eaf80740cb 100644 --- a/lib/manager/html/update.spec.ts +++ b/lib/manager/html/update.spec.ts @@ -6,7 +6,7 @@ import _got from '../../util/got'; const got: jest.Mock<any> = _got as any; jest.mock('../../util/got'); -const content = readFileSync( +const fileContent = readFileSync( resolve(__dirname, `./__fixtures__/sample.html`), 'utf8' ); @@ -22,15 +22,15 @@ describe('manager/html/update', () => { }); it('updates dependency', async () => { got.mockResolvedValueOnce({ body: axiosJson }); - const { deps } = extractPackageFile(content); + const { deps } = extractPackageFile(fileContent); const dep = deps.pop(); const upgrade = { ...dep, newValue: '0.19.2', }; const { currentValue, newValue } = upgrade; - const newFileContent = await updateDependency(content, upgrade); - const cmpContent = content + const newFileContent = await updateDependency({ fileContent, upgrade }); + const cmpContent = fileContent .replace(currentValue, newValue) .replace( 'sha256-mpnrJ5DpEZZkwkE1ZgkEQQJW/46CSEh/STrZKOB/qoM=', @@ -39,43 +39,49 @@ describe('manager/html/update', () => { expect(newFileContent).toEqual(cmpContent); }); it('returns same string for already updated dependency', async () => { - const { deps } = extractPackageFile(content); + const { deps } = extractPackageFile(fileContent); const dep = deps.pop(); const upgrade = { ...dep, newValue: '9.9.999', }; const { currentValue } = upgrade; - const alreadyUpdated = content + const alreadyUpdated = fileContent .replace(currentValue, '9.9.999') .replace( 'sha256-mpnrJ5DpEZZkwkE1ZgkEQQJW/46CSEh/STrZKOB/qoM=', 'sha256-T/f7Sju1ZfNNfBh7skWn0idlCBcI3RwdLSS4/I7NQKQ=' ); - const newFileContent = await updateDependency(alreadyUpdated, upgrade); + const newFileContent = await updateDependency({ + fileContent: alreadyUpdated, + upgrade, + }); expect(newFileContent).toBe(alreadyUpdated); }); it('returns null if content has changed', async () => { - const { deps } = extractPackageFile(content); + const { deps } = extractPackageFile(fileContent); const dep = deps.pop(); const upgrade = { ...dep, newValue: '9.9.999', }; const { currentValue } = upgrade; - const alreadyUpdated = content.replace(currentValue, '2020.1'); - const newFileContent = await updateDependency(alreadyUpdated, upgrade); + const alreadyUpdated = fileContent.replace(currentValue, '2020.1'); + const newFileContent = await updateDependency({ + fileContent: alreadyUpdated, + upgrade, + }); expect(newFileContent).toBeNull(); }); it('returns null if hash is not found', async () => { got.mockResolvedValueOnce({ body: axiosJson }); - const { deps } = extractPackageFile(content); + const { deps } = extractPackageFile(fileContent); const dep = deps.pop(); const upgrade = { ...dep, newValue: '9.9.999', }; - const newFileContent = await updateDependency(content, upgrade); + const newFileContent = await updateDependency({ fileContent, upgrade }); expect(newFileContent).toBeNull(); }); }); diff --git a/lib/manager/html/update.ts b/lib/manager/html/update.ts index 12d15a3dabbdbebc849f85b938f7615c7d31d926..c2ace1d3f107233ec3a4821782a2189dcc6b05ec 100644 --- a/lib/manager/html/update.ts +++ b/lib/manager/html/update.ts @@ -1,5 +1,5 @@ import { logger } from '../../logger'; -import { PackageDependency, Upgrade } from '../common'; +import { PackageDependency, UpdateDependencyConfig } from '../common'; import { extractDep } from './extract'; import * as cdnjs from '../../datasource/cdnjs'; import got from '../../util/got'; @@ -37,10 +37,10 @@ async function fetchNewHash( return result; } -export async function updateDependency( - fileContent: string, - upgrade: Upgrade -): Promise<string | null> { +export async function updateDependency({ + fileContent, + upgrade, +}: UpdateDependencyConfig): Promise<string> { const { currentValue, newValue, managerData } = upgrade; const { tagPosition, tagLength } = managerData; const leftPart = fileContent.slice(0, tagPosition);