refactor: introduce Fixtures util class (#12638)
* refactor: introduce Fixtures util class * refactor: align yarn.spec * refactor: move fs mocks to __mocks__ folder * refactor: improve fs-extra mock * refactor: move callsite to dev deps * refactor: use fixtures class * refactor: use fixtures class * refactor: reduce external variables in tests * refactor: improve Fixtures * refactor: add type for realFs * refactor: remove obsolete snapshot * fix: by comments * refactor: provide ability to spy on mocked fs methods * refactor: fix build * refactor: fix by comments * refactor: add docs * refactor: fix unit test * refactor: return called times checks * refactor: fix by comments * refactor: adjust unit test * refactor: adjust unit test * refactor: fix unit test * refactor: fix by comments * refactor: fix by comments * refactor: update jsdoc * refactor: fix by comments Co-authored-by: Rhys Arkins <rhys@arkins.net> Co-authored-by: Jamie Magee <jamie.magee@gmail.com> Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
Родитель
38a6119154
Коммит
dabe3d0e29
|
@ -0,0 +1,3 @@
|
|||
import { fs } from 'memfs';
|
||||
|
||||
module.exports = fs;
|
|
@ -1,10 +1,10 @@
|
|||
import { loadFixture } from '../../test/util';
|
||||
import { Fixtures } from '../../test/fixtures';
|
||||
import { decryptConfig } from './decrypt';
|
||||
import { GlobalConfig } from './global';
|
||||
import type { RenovateConfig } from './types';
|
||||
|
||||
const privateKey = loadFixture('private.pem', '.');
|
||||
const privateKeyPgp = loadFixture('private-pgp.pem', '.');
|
||||
const privateKey = Fixtures.get('private.pem');
|
||||
const privateKeyPgp = Fixtures.get('private-pgp.pem');
|
||||
const repository = 'abc/def';
|
||||
|
||||
describe('config/decrypt', () => {
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
import { getPkgReleases } from '..';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import * as httpMock from '../../../test/http-mock';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
|
||||
import { range } from '../../util/range';
|
||||
import { datasource, defaultRegistryUrl, pageSize } from './common';
|
||||
|
||||
const res1 = loadFixture('page.json');
|
||||
const jre = loadFixture('jre.json');
|
||||
|
||||
function getPath(page: number, imageType = 'jdk'): string {
|
||||
return `/v3/info/release_versions?page_size=${pageSize}&image_type=${imageType}&project=jdk&release_type=ga&sort_method=DATE&sort_order=DESC&vendor=adoptium&page=${page}`;
|
||||
}
|
||||
|
@ -73,7 +70,10 @@ describe('datasource/adoptium-java/index', () => {
|
|||
});
|
||||
|
||||
it('processes real data', async () => {
|
||||
httpMock.scope(defaultRegistryUrl).get(getPath(0)).reply(200, res1);
|
||||
httpMock
|
||||
.scope(defaultRegistryUrl)
|
||||
.get(getPath(0))
|
||||
.reply(200, Fixtures.get('page.json'));
|
||||
const res = await getPkgReleases({
|
||||
datasource,
|
||||
depName,
|
||||
|
@ -83,7 +83,10 @@ describe('datasource/adoptium-java/index', () => {
|
|||
});
|
||||
|
||||
it('processes real data (jre)', async () => {
|
||||
httpMock.scope(defaultRegistryUrl).get(getPath(0, 'jre')).reply(200, jre);
|
||||
httpMock
|
||||
.scope(defaultRegistryUrl)
|
||||
.get(getPath(0, 'jre'))
|
||||
.reply(200, Fixtures.get('jre.json'));
|
||||
const res = await getPkgReleases({
|
||||
datasource,
|
||||
depName: 'java-jre',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { getPkgReleases } from '..';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import * as httpMock from '../../../test/http-mock';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
|
||||
import { logger } from '../../logger';
|
||||
import { joinUrlParts } from '../../util/url';
|
||||
|
@ -14,8 +14,8 @@ const testConfig = {
|
|||
registryUrls: [testRegistryUrl],
|
||||
depName: testLookupName,
|
||||
};
|
||||
const fixtureReleasesAsFolders = loadFixture('releases-as-folders.html');
|
||||
const fixtureReleasesAsFiles = loadFixture('releases-as-files.html');
|
||||
const fixtureReleasesAsFolders = Fixtures.get('releases-as-folders.html');
|
||||
const fixtureReleasesAsFiles = Fixtures.get('releases-as-files.html');
|
||||
|
||||
function getPath(folder: string): string {
|
||||
return `/${folder}`;
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import { getPkgReleases } from '..';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import * as httpMock from '../../../test/http-mock';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
|
||||
import { CdnJsDatasource } from '.';
|
||||
|
||||
const res1 = loadFixture('d3-force.json');
|
||||
const res2 = loadFixture('bulma.json');
|
||||
|
||||
const baseUrl = 'https://api.cdnjs.com/';
|
||||
|
||||
const pathFor = (s: string): string =>
|
||||
|
@ -105,7 +102,7 @@ describe('datasource/cdnjs/index', () => {
|
|||
httpMock
|
||||
.scope(baseUrl)
|
||||
.get(pathFor('d3-force/d3-force.js'))
|
||||
.reply(200, res1);
|
||||
.reply(200, Fixtures.get('d3-force.json'));
|
||||
const res = await getPkgReleases({
|
||||
datasource: CdnJsDatasource.id,
|
||||
depName: 'd3-force/d3-force.js',
|
||||
|
@ -117,7 +114,7 @@ describe('datasource/cdnjs/index', () => {
|
|||
httpMock
|
||||
.scope(baseUrl)
|
||||
.get(pathFor('bulma/only/0.7.5/style.css'))
|
||||
.reply(200, res2);
|
||||
.reply(200, Fixtures.get('bulma.json'));
|
||||
const res = await getPkgReleases({
|
||||
datasource: CdnJsDatasource.id,
|
||||
depName: 'bulma/only/0.7.5/style.css',
|
||||
|
|
|
@ -4,8 +4,8 @@ import _simpleGit from 'simple-git';
|
|||
import { DirectoryResult, dir } from 'tmp-promise';
|
||||
import { dirname, join } from 'upath';
|
||||
import { getPkgReleases } from '..';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import * as httpMock from '../../../test/http-mock';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { GlobalConfig } from '../../config/global';
|
||||
import type { RepoGlobalConfig } from '../../config/types';
|
||||
import * as memCache from '../../util/cache/memory';
|
||||
|
@ -15,10 +15,6 @@ import { CrateDatasource } from '.';
|
|||
jest.mock('simple-git');
|
||||
const simpleGit: any = _simpleGit;
|
||||
|
||||
const res1 = loadFixture('libc');
|
||||
const res2 = loadFixture('amethyst');
|
||||
const res3 = loadFixture('mypkg');
|
||||
|
||||
const baseUrl =
|
||||
'https://raw.githubusercontent.com/rust-lang/crates.io-index/master/';
|
||||
|
||||
|
@ -36,7 +32,7 @@ function setupGitMocks(delayMs?: number): { mockClone: jest.Mock<any, any> } {
|
|||
|
||||
const path = `${clonePath}/my/pk/mypkg`;
|
||||
fs.mkdirSync(dirname(path), { recursive: true });
|
||||
fs.writeFileSync(path, res3, { encoding: 'utf8' });
|
||||
fs.writeFileSync(path, Fixtures.get('mypkg'), { encoding: 'utf8' });
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -209,7 +205,10 @@ describe('datasource/crate/index', () => {
|
|||
expect(httpMock.getTrace()).toMatchSnapshot();
|
||||
});
|
||||
it('processes real data: libc', async () => {
|
||||
httpMock.scope(baseUrl).get('/li/bc/libc').reply(200, res1);
|
||||
httpMock
|
||||
.scope(baseUrl)
|
||||
.get('/li/bc/libc')
|
||||
.reply(200, Fixtures.get('libc'));
|
||||
const res = await getPkgReleases({
|
||||
datasource,
|
||||
depName: 'libc',
|
||||
|
@ -221,7 +220,10 @@ describe('datasource/crate/index', () => {
|
|||
expect(httpMock.getTrace()).toMatchSnapshot();
|
||||
});
|
||||
it('processes real data: amethyst', async () => {
|
||||
httpMock.scope(baseUrl).get('/am/et/amethyst').reply(200, res2);
|
||||
httpMock
|
||||
.scope(baseUrl)
|
||||
.get('/am/et/amethyst')
|
||||
.reply(200, Fixtures.get('amethyst'));
|
||||
const res = await getPkgReleases({
|
||||
datasource,
|
||||
depName: 'amethyst',
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
import { getPkgReleases } from '..';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import * as httpMock from '../../../test/http-mock';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
|
||||
import { GalaxyCollectionDatasource } from '.';
|
||||
|
||||
const communityKubernetesBase = loadFixture('community_kubernetes_base.json');
|
||||
const communityKubernetesVersions = loadFixture(
|
||||
const communityKubernetesBase = Fixtures.get('community_kubernetes_base.json');
|
||||
const communityKubernetesVersions = Fixtures.get(
|
||||
'community_kubernetes_versions.json'
|
||||
);
|
||||
const communityKubernetesDetails121 = loadFixture(
|
||||
const communityKubernetesDetails121 = Fixtures.get(
|
||||
'community_kubernetes_version_details_1.2.1.json'
|
||||
);
|
||||
const communityKubernetesDetails120 = loadFixture(
|
||||
const communityKubernetesDetails120 = Fixtures.get(
|
||||
'community_kubernetes_version_details_1.2.0.json'
|
||||
);
|
||||
const communityKubernetesDetails0111 = loadFixture(
|
||||
const communityKubernetesDetails0111 = Fixtures.get(
|
||||
'community_kubernetes_version_details_0.11.1.json'
|
||||
);
|
||||
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
import { getPkgReleases } from '..';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import * as httpMock from '../../../test/http-mock';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { GalaxyDatasource } from '.';
|
||||
|
||||
const res1 = loadFixture('timezone');
|
||||
const empty = loadFixture('empty');
|
||||
|
||||
const baseUrl = 'https://galaxy.ansible.com/';
|
||||
|
||||
describe('datasource/galaxy/index', () => {
|
||||
|
@ -79,7 +76,7 @@ describe('datasource/galaxy/index', () => {
|
|||
httpMock
|
||||
.scope(baseUrl)
|
||||
.get('/api/v1/roles/?owner__username=yatesr&name=timezone')
|
||||
.reply(200, res1);
|
||||
.reply(200, Fixtures.get('timezone'));
|
||||
const res = await getPkgReleases({
|
||||
datasource: GalaxyDatasource.id,
|
||||
depName: 'yatesr.timezone',
|
||||
|
@ -93,7 +90,7 @@ describe('datasource/galaxy/index', () => {
|
|||
httpMock
|
||||
.scope(baseUrl)
|
||||
.get('/api/v1/roles/?owner__username=foo&name=bar')
|
||||
.reply(200, empty);
|
||||
.reply(200, Fixtures.get('empty'));
|
||||
const res = await getPkgReleases({
|
||||
datasource: GalaxyDatasource.id,
|
||||
depName: 'foo.bar',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import _simpleGit from 'simple-git';
|
||||
import { getPkgReleases } from '..';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { GitRefsDatasource } from '.';
|
||||
|
||||
jest.mock('simple-git');
|
||||
|
@ -8,7 +8,7 @@ const simpleGit: any = _simpleGit;
|
|||
|
||||
const depName = 'https://github.com/example/example.git';
|
||||
|
||||
const lsRemote1 = loadFixture('ls-remote-1.txt');
|
||||
const lsRemote1 = Fixtures.get('ls-remote-1.txt');
|
||||
|
||||
const datasource = GitRefsDatasource.id;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import _simpleGit from 'simple-git';
|
||||
import { getPkgReleases } from '..';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { GitTagsDatasource } from '.';
|
||||
|
||||
jest.mock('simple-git');
|
||||
|
@ -8,7 +8,7 @@ const simpleGit: any = _simpleGit;
|
|||
|
||||
const depName = 'https://github.com/example/example.git';
|
||||
|
||||
const lsRemote1 = loadFixture('ls-remote-1.txt', '../git-refs');
|
||||
const lsRemote1 = Fixtures.get('ls-remote-1.txt', '../git-refs');
|
||||
|
||||
const datasource = GitTagsDatasource.id;
|
||||
const datasourceInstance = new GitTagsDatasource();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { getPkgReleases } from '..';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import * as httpMock from '../../../test/http-mock';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { HelmDatasource } from '.';
|
||||
|
||||
// Truncated index.yaml file
|
||||
const indexYaml = loadFixture('index.yaml');
|
||||
const indexYaml = Fixtures.get('index.yaml');
|
||||
|
||||
describe('datasource/helm/index', () => {
|
||||
describe('getReleases', () => {
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import { getPkgReleases } from '..';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import * as httpMock from '../../../test/http-mock';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
|
||||
import { datasource, defaultRegistryUrl } from './common';
|
||||
|
||||
const res1 = loadFixture('index.json');
|
||||
|
||||
describe('datasource/node/index', () => {
|
||||
describe('getReleases', () => {
|
||||
it('throws for 500', async () => {
|
||||
|
@ -42,7 +40,10 @@ describe('datasource/node/index', () => {
|
|||
});
|
||||
|
||||
it('processes real data', async () => {
|
||||
httpMock.scope(defaultRegistryUrl).get('/index.json').reply(200, res1);
|
||||
httpMock
|
||||
.scope(defaultRegistryUrl)
|
||||
.get('/index.json')
|
||||
.reply(200, Fixtures.get('index.json'));
|
||||
const res = await getPkgReleases({
|
||||
datasource,
|
||||
depName: 'node',
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
import { getPkgReleases } from '..';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import * as httpMock from '../../../test/http-mock';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { RubyVersionDatasource } from '.';
|
||||
|
||||
const rubyReleasesHtml = loadFixture('releases.html');
|
||||
|
||||
const datasource = RubyVersionDatasource.id;
|
||||
|
||||
describe('datasource/ruby-version/index', () => {
|
||||
|
@ -13,7 +11,7 @@ describe('datasource/ruby-version/index', () => {
|
|||
httpMock
|
||||
.scope('https://www.ruby-lang.org')
|
||||
.get('/en/downloads/releases/')
|
||||
.reply(200, rubyReleasesHtml);
|
||||
.reply(200, Fixtures.get('releases.html'));
|
||||
const res = await getPkgReleases({
|
||||
datasource,
|
||||
depName: 'ruby',
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
import { getPkgReleases } from '..';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import * as httpMock from '../../../test/http-mock';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import * as mavenVersioning from '../../versioning/maven';
|
||||
import { MAVEN_REPO } from '../maven/common';
|
||||
import { parseIndexDir } from '../sbt-plugin/util';
|
||||
import * as sbtPackage from '.';
|
||||
|
||||
const mavenIndexHtml = loadFixture(`maven-index.html`);
|
||||
const sbtPluginIndex = loadFixture(`sbt-plugins-index.html`);
|
||||
|
||||
describe('datasource/sbt-package/index', () => {
|
||||
it('parses Maven index directory', () => {
|
||||
expect(parseIndexDir(mavenIndexHtml)).toMatchSnapshot();
|
||||
expect(parseIndexDir(Fixtures.get(`maven-index.html`))).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('parses sbt index directory', () => {
|
||||
expect(parseIndexDir(sbtPluginIndex)).toMatchSnapshot();
|
||||
expect(
|
||||
parseIndexDir(Fixtures.get(`sbt-plugins-index.html`))
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
describe('getPkgReleases', () => {
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const yamlFile1 = loadFixture('main1.yaml');
|
||||
const yamlFile2 = loadFixture('main2.yaml');
|
||||
|
||||
describe('manager/ansible/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns null for empty', () => {
|
||||
expect(extractPackageFile('nothing here')).toBeNull();
|
||||
});
|
||||
it('extracts multiple image lines from docker_container', () => {
|
||||
const res = extractPackageFile(yamlFile1);
|
||||
const res = extractPackageFile(Fixtures.get('main1.yaml'));
|
||||
expect(res.deps).toMatchSnapshot();
|
||||
expect(res.deps).toHaveLength(9);
|
||||
});
|
||||
it('extracts multiple image lines from docker_service', () => {
|
||||
const res = extractPackageFile(yamlFile2);
|
||||
const res = extractPackageFile(Fixtures.get('main2.yaml'));
|
||||
expect(res.deps).toMatchSnapshot();
|
||||
expect(res.deps).toHaveLength(4);
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const validApplication = loadFixture('validApplication.yml');
|
||||
const malformedApplication = loadFixture('malformedApplications.yml');
|
||||
const randomManifest = loadFixture('randomManifest.yml');
|
||||
const validApplication = Fixtures.get('validApplication.yml');
|
||||
const malformedApplication = Fixtures.get('malformedApplications.yml');
|
||||
const randomManifest = Fixtures.get('randomManifest.yml');
|
||||
|
||||
describe('manager/argocd/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import {
|
||||
extractContainer,
|
||||
extractPackageFile,
|
||||
|
@ -6,11 +6,11 @@ import {
|
|||
parseAzurePipelines,
|
||||
} from './extract';
|
||||
|
||||
const azurePipelines = loadFixture('azure-pipelines.yaml');
|
||||
const azurePipelines = Fixtures.get('azure-pipelines.yaml');
|
||||
|
||||
const azurePipelinesInvalid = loadFixture('azure-pipelines-invalid.yaml');
|
||||
const azurePipelinesInvalid = Fixtures.get('azure-pipelines-invalid.yaml');
|
||||
|
||||
const azurePipelinesNoDependency = loadFixture(
|
||||
const azurePipelinesNoDependency = Fixtures.get(
|
||||
'azure-pipelines-no-dependency.yaml'
|
||||
);
|
||||
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { id as githubReleaseDatasource } from '../../datasource/github-releases';
|
||||
import { id as semverVersioning } from '../../versioning/semver';
|
||||
import type { PackageDependency } from '../types';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const validWrapperContent = loadFixture('valid-wrapper');
|
||||
const malformedWrapperContent = loadFixture('malformed-wrapper');
|
||||
|
||||
describe('manager/batect-wrapper/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns null for empty wrapper file', () => {
|
||||
|
@ -18,7 +15,7 @@ describe('manager/batect-wrapper/extract', () => {
|
|||
});
|
||||
|
||||
it('extracts the current version from a valid wrapper script', () => {
|
||||
const res = extractPackageFile(validWrapperContent);
|
||||
const res = extractPackageFile(Fixtures.get('valid-wrapper'));
|
||||
|
||||
const expectedDependency: PackageDependency = {
|
||||
depName: 'batect/batect',
|
||||
|
@ -32,7 +29,7 @@ describe('manager/batect-wrapper/extract', () => {
|
|||
});
|
||||
|
||||
it('returns the first version from a wrapper script with multiple versions', () => {
|
||||
const res = extractPackageFile(malformedWrapperContent);
|
||||
const res = extractPackageFile(Fixtures.get('malformed-wrapper'));
|
||||
|
||||
const expectedDependency: PackageDependency = {
|
||||
depName: 'batect/batect',
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from './../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const workspaceFile = loadFixture('WORKSPACE1');
|
||||
const workspace2File = loadFixture('WORKSPACE2');
|
||||
const workspace3File = loadFixture('WORKSPACE3');
|
||||
const fileWithBzlExtension = loadFixture('repositories.bzl');
|
||||
|
||||
describe('manager/bazel/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns empty if fails to parse', () => {
|
||||
|
@ -17,12 +12,12 @@ describe('manager/bazel/extract', () => {
|
|||
expect(res).toBeNull();
|
||||
});
|
||||
it('extracts multiple types of dependencies', () => {
|
||||
const res = extractPackageFile(workspaceFile);
|
||||
const res = extractPackageFile(Fixtures.get('WORKSPACE1'));
|
||||
expect(res.deps).toHaveLength(14);
|
||||
expect(res.deps).toMatchSnapshot();
|
||||
});
|
||||
it('extracts github tags', () => {
|
||||
const res = extractPackageFile(workspace2File);
|
||||
const res = extractPackageFile(Fixtures.get('WORKSPACE2'));
|
||||
expect(res.deps).toMatchSnapshot([
|
||||
{ lookupName: 'lmirosevic/GBDeviceInfo' },
|
||||
{ lookupName: 'nelhage/rules_boost' },
|
||||
|
@ -31,11 +26,11 @@ describe('manager/bazel/extract', () => {
|
|||
]);
|
||||
});
|
||||
it('handle comments and strings', () => {
|
||||
const res = extractPackageFile(workspace3File);
|
||||
const res = extractPackageFile(Fixtures.get('WORKSPACE3'));
|
||||
expect(res.deps).toMatchSnapshot([{ lookupName: 'nelhage/rules_boost' }]);
|
||||
});
|
||||
it('extracts dependencies from *.bzl files', () => {
|
||||
const res = extractPackageFile(fileWithBzlExtension);
|
||||
const res = extractPackageFile(Fixtures.get('repositories.bzl'));
|
||||
expect(res.deps).toMatchSnapshot([
|
||||
{
|
||||
currentDigest: '0356bef3fbbabec5f0e196ecfacdeb6db62d48c0',
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const bitbucketPipelinesYAML = loadFixture('bitbucket-pipelines.yaml');
|
||||
|
||||
describe('manager/bitbucket-pipelines/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns null for empty', () => {
|
||||
|
@ -10,7 +8,7 @@ describe('manager/bitbucket-pipelines/extract', () => {
|
|||
});
|
||||
|
||||
it('extracts dependencies', () => {
|
||||
const res = extractPackageFile(bitbucketPipelinesYAML);
|
||||
const res = extractPackageFile(Fixtures.get('bitbucket-pipelines.yaml'));
|
||||
expect(res.deps).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
|
|
|
@ -1,39 +1,33 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const pipeline1 = loadFixture('pipeline1.yml');
|
||||
const pipeline2 = loadFixture('pipeline2.yml');
|
||||
const pipeline3 = loadFixture('pipeline3.yml');
|
||||
const pipeline4 = loadFixture('pipeline4.yml');
|
||||
const pipeline5 = loadFixture('pipeline5.yml');
|
||||
|
||||
describe('manager/buildkite/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns null for empty', () => {
|
||||
expect(extractPackageFile('nothing here')).toBeNull();
|
||||
});
|
||||
it('extracts simple single plugin', () => {
|
||||
const res = extractPackageFile(pipeline1).deps;
|
||||
const res = extractPackageFile(Fixtures.get('pipeline1.yml')).deps;
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res).toHaveLength(1);
|
||||
});
|
||||
it('extracts multiple plugins in same file', () => {
|
||||
const res = extractPackageFile(pipeline2).deps;
|
||||
const res = extractPackageFile(Fixtures.get('pipeline2.yml')).deps;
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res).toHaveLength(2);
|
||||
});
|
||||
it('adds skipReason', () => {
|
||||
const res = extractPackageFile(pipeline3).deps;
|
||||
const res = extractPackageFile(Fixtures.get('pipeline3.yml')).deps;
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res).toHaveLength(2);
|
||||
});
|
||||
it('extracts arrays of plugins', () => {
|
||||
const res = extractPackageFile(pipeline4).deps;
|
||||
const res = extractPackageFile(Fixtures.get('pipeline4.yml')).deps;
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res).toHaveLength(4);
|
||||
});
|
||||
it('extracts git-based plugins', () => {
|
||||
const res = extractPackageFile(pipeline5).deps;
|
||||
const res = extractPackageFile(Fixtures.get('pipeline5.yml')).deps;
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res).toHaveLength(2);
|
||||
});
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from '.';
|
||||
|
||||
const content = loadFixture('build.cake');
|
||||
|
||||
describe('manager/cake/index', () => {
|
||||
it('extracts', () => {
|
||||
expect(extractPackageFile(content)).toMatchSnapshot({
|
||||
expect(extractPackageFile(Fixtures.get('build.cake'))).toMatchSnapshot({
|
||||
deps: [
|
||||
{ depName: 'Foo.Foo', currentValue: '1.1.1' },
|
||||
{ depName: 'Bim.Bim', currentValue: '6.6.6' },
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from '.';
|
||||
|
||||
const input = loadFixture(`sample.txt`);
|
||||
|
||||
describe('manager/cdnurl/extract', () => {
|
||||
it('extractPackageFile', () => {
|
||||
expect(extractPackageFile(input)).toMatchSnapshot({
|
||||
expect(extractPackageFile(Fixtures.get(`sample.txt`))).toMatchSnapshot({
|
||||
deps: [
|
||||
{
|
||||
depName: 'prop-types',
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const file1 = loadFixture('cloudbuild.yml');
|
||||
|
||||
describe('manager/cloudbuild/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns null for empty', () => {
|
||||
expect(extractPackageFile('nothing here')).toBeNull();
|
||||
});
|
||||
it('extracts multiple image lines', () => {
|
||||
const res = extractPackageFile(file1);
|
||||
const res = extractPackageFile(Fixtures.get('cloudbuild.yml'));
|
||||
expect(res.deps).toMatchSnapshot();
|
||||
expect(res.deps).toHaveLength(3);
|
||||
});
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const depsEdn = loadFixture('deps.edn');
|
||||
|
||||
describe('manager/deps-edn/extract', () => {
|
||||
it('extractPackageFile', () => {
|
||||
const { deps } = extractPackageFile(depsEdn);
|
||||
const { deps } = extractPackageFile(Fixtures.get('deps.edn'));
|
||||
expect(deps).toMatchSnapshot([
|
||||
{
|
||||
depName: 'persistent-sorted-set:persistent-sorted-set',
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const droneYAML = loadFixture('.drone.yml');
|
||||
|
||||
describe('manager/droneci/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns null for empty', () => {
|
||||
|
@ -11,7 +9,7 @@ describe('manager/droneci/extract', () => {
|
|||
});
|
||||
|
||||
it('extracts multiple image lines', () => {
|
||||
const res = extractPackageFile(droneYAML);
|
||||
const res = extractPackageFile(Fixtures.get('.drone.yml'));
|
||||
expect(res.deps).toMatchSnapshot();
|
||||
expect(res.deps).toHaveLength(4);
|
||||
});
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const workflow1 = loadFixture('workflow_1.yml');
|
||||
const workflow2 = loadFixture('workflow_2.yml');
|
||||
|
||||
describe('manager/github-actions/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns null for empty', () => {
|
||||
expect(extractPackageFile('nothing here')).toBeNull();
|
||||
});
|
||||
it('extracts multiple docker image lines from yaml configuration file', () => {
|
||||
const res = extractPackageFile(workflow1);
|
||||
const res = extractPackageFile(Fixtures.get('workflow_1.yml'));
|
||||
expect(res.deps).toMatchSnapshot();
|
||||
expect(res.deps.filter((d) => d.datasource === 'docker')).toHaveLength(2);
|
||||
});
|
||||
it('extracts multiple action tag lines from yaml configuration file', () => {
|
||||
const res = extractPackageFile(workflow2);
|
||||
const res = extractPackageFile(Fixtures.get('workflow_2.yml'));
|
||||
expect(res.deps).toMatchSnapshot();
|
||||
expect(
|
||||
res.deps.filter((d) => d.datasource === 'github-tags')
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const gomod1 = loadFixture('1/go.mod');
|
||||
const gomod2 = loadFixture('2/go.mod');
|
||||
const gomod3 = loadFixture('3/go.mod');
|
||||
const gomod1 = Fixtures.get('1/go.mod');
|
||||
const gomod2 = Fixtures.get('2/go.mod');
|
||||
const gomod3 = Fixtures.get('3/go.mod');
|
||||
|
||||
describe('manager/gomod/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import type { UpdateType } from '../../config/types';
|
||||
import { updateDependency } from './update';
|
||||
|
||||
const gomod1 = loadFixture('1/go.mod');
|
||||
const gomod2 = loadFixture('2/go.mod');
|
||||
const gomod1 = Fixtures.get('1/go.mod');
|
||||
const gomod2 = Fixtures.get('2/go.mod');
|
||||
|
||||
describe('manager/gomod/update', () => {
|
||||
describe('updateDependency', () => {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from '.';
|
||||
|
||||
const multidocYaml = loadFixture('multidoc.yaml');
|
||||
|
||||
describe('manager/helmfile/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
beforeEach(() => {
|
||||
|
@ -184,11 +182,15 @@ describe('manager/helmfile/extract', () => {
|
|||
|
||||
it('parses multidoc yaml', () => {
|
||||
const fileName = 'helmfile.yaml';
|
||||
const result = extractPackageFile(multidocYaml, fileName, {
|
||||
aliases: {
|
||||
stable: 'https://charts.helm.sh/stable',
|
||||
},
|
||||
});
|
||||
const result = extractPackageFile(
|
||||
Fixtures.get('multidoc.yaml'),
|
||||
fileName,
|
||||
{
|
||||
aliases: {
|
||||
stable: 'https://charts.helm.sh/stable',
|
||||
},
|
||||
}
|
||||
);
|
||||
expect(result).toMatchSnapshot({
|
||||
datasource: 'helm',
|
||||
deps: [
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { ClojureDatasource } from '../../datasource/clojure';
|
||||
import {
|
||||
extractFromVectors,
|
||||
|
@ -7,7 +7,7 @@ import {
|
|||
trimAtKey,
|
||||
} from './extract';
|
||||
|
||||
const leinProjectClj = loadFixture(`project.clj`);
|
||||
const leinProjectClj = Fixtures.get(`project.clj`);
|
||||
|
||||
describe('manager/leiningen/extract', () => {
|
||||
it('trimAtKey', () => {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackage, extractRegistries } from './extract';
|
||||
|
||||
const minimumContent = loadFixture(`minimum.pom.xml`);
|
||||
const simpleContent = loadFixture(`simple.pom.xml`);
|
||||
const minimumContent = Fixtures.get(`minimum.pom.xml`);
|
||||
const simpleContent = Fixtures.get(`simple.pom.xml`);
|
||||
|
||||
const mirrorSettingsContent = loadFixture(`mirror.settings.xml`);
|
||||
const profileSettingsContent = loadFixture(`profile.settings.xml`);
|
||||
const complexSettingsContent = loadFixture(`complex.settings.xml`);
|
||||
const mirrorSettingsContent = Fixtures.get(`mirror.settings.xml`);
|
||||
const profileSettingsContent = Fixtures.get(`profile.settings.xml`);
|
||||
const complexSettingsContent = Fixtures.get(`complex.settings.xml`);
|
||||
|
||||
describe('manager/maven/extract', () => {
|
||||
describe('extractDependencies', () => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const input01Content = loadFixture('package-1.js');
|
||||
const input01Content = Fixtures.get('package-1.js');
|
||||
|
||||
describe('manager/meteor/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { GlobalConfig } from '../../config/global';
|
||||
import { extractPackageFile } from '.';
|
||||
|
||||
const sample = loadFixture('mix.exs');
|
||||
|
||||
describe('manager/mix/extract', () => {
|
||||
beforeEach(() => {
|
||||
GlobalConfig.set({ localDir: '' });
|
||||
|
@ -15,7 +13,7 @@ describe('manager/mix/extract', () => {
|
|||
expect(deps).toBeEmpty();
|
||||
});
|
||||
it('extracts all dependencies', async () => {
|
||||
const res = await extractPackageFile(sample, 'mix.exs');
|
||||
const res = await extractPackageFile(Fixtures.get('mix.exs'), 'mix.exs');
|
||||
expect(res).toMatchSnapshot({
|
||||
deps: [
|
||||
{ depName: 'postgrex', currentValue: '~> 0.8.1' },
|
||||
|
|
|
@ -56,7 +56,7 @@ Array [
|
|||
Object {
|
||||
"cmd": "yarn install --ignore-engines --ignore-platform --network-timeout 100000 --ignore-scripts",
|
||||
"options": Object {
|
||||
"cwd": "some-dir",
|
||||
"cwd": "/some-dir",
|
||||
"encoding": "utf-8",
|
||||
"env": Object {
|
||||
"CI": "true",
|
||||
|
@ -76,7 +76,7 @@ Array [
|
|||
Object {
|
||||
"cmd": "npx yarn-deduplicate --strategy fewer",
|
||||
"options": Object {
|
||||
"cwd": "some-dir",
|
||||
"cwd": "/some-dir",
|
||||
"encoding": "utf-8",
|
||||
"env": Object {
|
||||
"CI": "true",
|
||||
|
@ -96,7 +96,7 @@ Array [
|
|||
Object {
|
||||
"cmd": "yarn install --ignore-engines --ignore-platform --network-timeout 100000 --ignore-scripts",
|
||||
"options": Object {
|
||||
"cwd": "some-dir",
|
||||
"cwd": "/some-dir",
|
||||
"encoding": "utf-8",
|
||||
"env": Object {
|
||||
"CI": "true",
|
||||
|
@ -116,7 +116,7 @@ Array [
|
|||
Object {
|
||||
"cmd": "npx yarn-deduplicate --strategy highest",
|
||||
"options": Object {
|
||||
"cwd": "some-dir",
|
||||
"cwd": "/some-dir",
|
||||
"encoding": "utf-8",
|
||||
"env": Object {
|
||||
"CI": "true",
|
||||
|
@ -136,7 +136,7 @@ Array [
|
|||
Object {
|
||||
"cmd": "yarn install --ignore-engines --ignore-platform --network-timeout 100000 --ignore-scripts",
|
||||
"options": Object {
|
||||
"cwd": "some-dir",
|
||||
"cwd": "/some-dir",
|
||||
"encoding": "utf-8",
|
||||
"env": Object {
|
||||
"CI": "true",
|
||||
|
@ -161,7 +161,7 @@ Array [
|
|||
Object {
|
||||
"cmd": "yarn install",
|
||||
"options": Object {
|
||||
"cwd": "some-dir",
|
||||
"cwd": "/some-dir",
|
||||
"encoding": "utf-8",
|
||||
"env": Object {
|
||||
"CI": "true",
|
||||
|
@ -190,7 +190,7 @@ Array [
|
|||
Object {
|
||||
"cmd": "yarn install",
|
||||
"options": Object {
|
||||
"cwd": "some-dir",
|
||||
"cwd": "/some-dir",
|
||||
"encoding": "utf-8",
|
||||
"env": Object {
|
||||
"CI": "true",
|
||||
|
@ -214,7 +214,7 @@ Array [
|
|||
Object {
|
||||
"cmd": "yarn dedupe --strategy highest",
|
||||
"options": Object {
|
||||
"cwd": "some-dir",
|
||||
"cwd": "/some-dir",
|
||||
"encoding": "utf-8",
|
||||
"env": Object {
|
||||
"CI": "true",
|
||||
|
@ -243,7 +243,7 @@ Array [
|
|||
Object {
|
||||
"cmd": "yarn install --mode=update-lockfile",
|
||||
"options": Object {
|
||||
"cwd": "some-dir",
|
||||
"cwd": "/some-dir",
|
||||
"encoding": "utf-8",
|
||||
"env": Object {
|
||||
"CI": "true",
|
||||
|
@ -266,7 +266,7 @@ Array [
|
|||
Object {
|
||||
"cmd": "yarn dedupe --strategy highest --mode=update-lockfile",
|
||||
"options": Object {
|
||||
"cwd": "some-dir",
|
||||
"cwd": "/some-dir",
|
||||
"encoding": "utf-8",
|
||||
"env": Object {
|
||||
"CI": "true",
|
||||
|
|
|
@ -1,21 +1,24 @@
|
|||
import { exec as _exec } from 'child_process';
|
||||
import fs from 'fs-extra';
|
||||
import {
|
||||
ExecSnapshots,
|
||||
envMock,
|
||||
mockExecAll,
|
||||
} from '../../../../test/exec-util';
|
||||
import { fs, mocked } from '../../../../test/util';
|
||||
import { Fixtures } from '../../../../test/fixtures';
|
||||
import { mocked } from '../../../../test/util';
|
||||
import * as _env from '../../../util/exec/env';
|
||||
import * as _yarnHelper from './yarn';
|
||||
import * as yarnHelper from './yarn';
|
||||
|
||||
jest.mock('fs-extra', () =>
|
||||
require('../../../../test/fixtures').Fixtures.fsExtra()
|
||||
);
|
||||
jest.mock('child_process');
|
||||
jest.mock('../../../util/exec/env');
|
||||
jest.mock('../../../util/fs');
|
||||
jest.mock('./node-version');
|
||||
|
||||
const exec: jest.Mock<typeof _exec> = _exec as any;
|
||||
const env = mocked(_env);
|
||||
const yarnHelper = mocked(_yarnHelper);
|
||||
|
||||
delete process.env.NPM_CONFIG_CACHE;
|
||||
|
||||
|
@ -28,7 +31,8 @@ const fixSnapshots = (snapshots: ExecSnapshots): ExecSnapshots =>
|
|||
|
||||
describe('manager/npm/post-update/yarn', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
Fixtures.reset();
|
||||
jest.clearAllMocks();
|
||||
jest.resetModules();
|
||||
env.getChildProcessEnv.mockReturnValue(envMock.basic);
|
||||
});
|
||||
|
@ -41,20 +45,17 @@ describe('manager/npm/post-update/yarn', () => {
|
|||
])(
|
||||
'generates lock files using yarn v%s',
|
||||
async (yarnVersion, yarnCompatibility, expectedFsCalls) => {
|
||||
Fixtures.mock(
|
||||
{
|
||||
'.yarnrc': 'yarn-path ./.yarn/cli.js\n',
|
||||
'yarn.lock': 'package-lock-contents',
|
||||
},
|
||||
'/some-dir'
|
||||
);
|
||||
const execSnapshots = mockExecAll(exec, {
|
||||
stdout: yarnVersion,
|
||||
stderr: '',
|
||||
});
|
||||
fs.readFile.mockImplementation((filename, encoding) => {
|
||||
if (filename.endsWith('.yarnrc')) {
|
||||
return new Promise<string>((resolve) =>
|
||||
resolve('yarn-path ./.yarn/cli.js\n')
|
||||
);
|
||||
}
|
||||
return new Promise<string>((resolve) =>
|
||||
resolve('package-lock-contents')
|
||||
);
|
||||
});
|
||||
const config = {
|
||||
constraints: {
|
||||
yarn: yarnCompatibility,
|
||||
|
@ -62,7 +63,7 @@ describe('manager/npm/post-update/yarn', () => {
|
|||
postUpdateOptions: ['yarnDedupeFewer', 'yarnDedupeHighest'],
|
||||
};
|
||||
const res = await yarnHelper.generateLockFile(
|
||||
'some-dir',
|
||||
'/some-dir',
|
||||
{
|
||||
YARN_CACHE_FOLDER: '/tmp/renovate/cache/yarn',
|
||||
YARN_GLOBAL_FOLDER: '/tmp/renovate/cache/berry',
|
||||
|
@ -77,11 +78,16 @@ describe('manager/npm/post-update/yarn', () => {
|
|||
);
|
||||
|
||||
it('only skips build if skipInstalls is false', async () => {
|
||||
Fixtures.mock(
|
||||
{
|
||||
'yarn.lock': 'package-lock-contents',
|
||||
},
|
||||
'some-dir'
|
||||
);
|
||||
const execSnapshots = mockExecAll(exec, {
|
||||
stdout: '3.0.0',
|
||||
stderr: '',
|
||||
});
|
||||
fs.readFile.mockResolvedValueOnce('package-lock-contents');
|
||||
const config = {
|
||||
constraints: {
|
||||
yarn: '3.0.0',
|
||||
|
@ -95,11 +101,16 @@ describe('manager/npm/post-update/yarn', () => {
|
|||
});
|
||||
|
||||
it('does not use global cache if zero install is detected', async () => {
|
||||
Fixtures.mock(
|
||||
{
|
||||
'yarn.lock': 'package-lock-contents',
|
||||
},
|
||||
'some-dir'
|
||||
);
|
||||
const execSnapshots = mockExecAll(exec, {
|
||||
stdout: '2.1.0',
|
||||
stderr: '',
|
||||
});
|
||||
fs.readFile.mockResolvedValueOnce('package-lock-contents');
|
||||
const config = {
|
||||
constraints: {
|
||||
yarn: '>= 2.0.0',
|
||||
|
@ -119,18 +130,16 @@ describe('manager/npm/post-update/yarn', () => {
|
|||
])(
|
||||
'performs lock file updates using yarn v%s',
|
||||
async (yarnVersion, yarnCompatibility) => {
|
||||
Fixtures.mock(
|
||||
{
|
||||
'yarn.lock': 'package-lock-contents',
|
||||
},
|
||||
'some-dir'
|
||||
);
|
||||
const execSnapshots = mockExecAll(exec, {
|
||||
stdout: yarnVersion,
|
||||
stderr: '',
|
||||
});
|
||||
fs.readFile.mockImplementation((filename, encoding) => {
|
||||
if (filename.endsWith('.yarnrc')) {
|
||||
return new Promise<string>((resolve) => resolve(null));
|
||||
}
|
||||
return new Promise<string>((resolve) =>
|
||||
resolve('package-lock-contents')
|
||||
);
|
||||
});
|
||||
const config = {
|
||||
constraints: {
|
||||
yarn: yarnCompatibility,
|
||||
|
@ -151,15 +160,16 @@ describe('manager/npm/post-update/yarn', () => {
|
|||
it.each([['1.22.0']])(
|
||||
'performs lock file updates and full install using yarn v%s',
|
||||
async (yarnVersion) => {
|
||||
Fixtures.mock(
|
||||
{
|
||||
'yarn.lock': 'package-lock-contents',
|
||||
},
|
||||
'some-dir'
|
||||
);
|
||||
const execSnapshots = mockExecAll(exec, {
|
||||
stdout: yarnVersion,
|
||||
stderr: '',
|
||||
});
|
||||
fs.readFile
|
||||
.mockResolvedValueOnce(
|
||||
'yarn-offline-mirror ./npm-packages-offline-cache'
|
||||
)
|
||||
.mockResolvedValueOnce('package-lock-contents');
|
||||
const res = await yarnHelper.generateLockFile('some-dir', {}, {}, [
|
||||
{
|
||||
depName: 'some-dep',
|
||||
|
@ -178,18 +188,17 @@ describe('manager/npm/post-update/yarn', () => {
|
|||
])(
|
||||
'performs lock file maintenance using yarn v%s',
|
||||
async (yarnVersion, yarnCompatibility, expectedFsCalls) => {
|
||||
Fixtures.mock(
|
||||
{
|
||||
'.yarnrc': null,
|
||||
'yarn.lock': 'package-lock-contents',
|
||||
},
|
||||
'some-dir'
|
||||
);
|
||||
const execSnapshots = mockExecAll(exec, {
|
||||
stdout: yarnVersion,
|
||||
stderr: '',
|
||||
});
|
||||
fs.readFile.mockImplementation((filename, encoding) => {
|
||||
if (filename.endsWith('.yarnrc')) {
|
||||
return new Promise<string>((resolve) => resolve(null));
|
||||
}
|
||||
return new Promise<string>((resolve) =>
|
||||
resolve('package-lock-contents')
|
||||
);
|
||||
});
|
||||
const config = {
|
||||
constraints: {
|
||||
yarn: yarnCompatibility,
|
||||
|
@ -201,7 +210,7 @@ describe('manager/npm/post-update/yarn', () => {
|
|||
]);
|
||||
expect(fs.readFile).toHaveBeenCalledTimes(expectedFsCalls);
|
||||
expect(fs.remove).toHaveBeenCalledTimes(1);
|
||||
expect(res.lockFile).toBe('package-lock-contents');
|
||||
expect(res.lockFile).toBeUndefined();
|
||||
expect(fixSnapshots(execSnapshots)).toMatchSnapshot();
|
||||
}
|
||||
);
|
||||
|
@ -212,18 +221,16 @@ describe('manager/npm/post-update/yarn', () => {
|
|||
])(
|
||||
'performs yarn binary update using yarn v%s',
|
||||
async (yarnVersion, yarnCompatibility) => {
|
||||
Fixtures.mock(
|
||||
{
|
||||
'yarn.lock': 'package-lock-contents',
|
||||
},
|
||||
'some-dir'
|
||||
);
|
||||
const execSnapshots = mockExecAll(exec, {
|
||||
stdout: yarnVersion,
|
||||
stderr: '',
|
||||
});
|
||||
fs.readFile.mockImplementation((filename, encoding) => {
|
||||
if (filename.endsWith('.yarnrc')) {
|
||||
return new Promise<string>((resolve) => resolve(null));
|
||||
}
|
||||
return new Promise<string>((resolve) =>
|
||||
resolve('package-lock-contents')
|
||||
);
|
||||
});
|
||||
const config = {
|
||||
constraints: {
|
||||
yarn: yarnCompatibility,
|
||||
|
@ -242,13 +249,11 @@ describe('manager/npm/post-update/yarn', () => {
|
|||
);
|
||||
|
||||
it('catches errors', async () => {
|
||||
Fixtures.mock({});
|
||||
const execSnapshots = mockExecAll(exec, {
|
||||
stdout: '1.9.4',
|
||||
stderr: 'some-error',
|
||||
});
|
||||
fs.readFile.mockResolvedValueOnce(null).mockRejectedValueOnce(() => {
|
||||
throw new Error('not-found');
|
||||
});
|
||||
const res = await yarnHelper.generateLockFile('some-dir', {});
|
||||
expect(fs.readFile).toHaveBeenCalledTimes(2);
|
||||
expect(res.error).toBeTrue();
|
||||
|
@ -258,69 +263,47 @@ describe('manager/npm/post-update/yarn', () => {
|
|||
|
||||
describe('checkYarnrc()', () => {
|
||||
it('returns offline mirror and yarn path', async () => {
|
||||
fs.exists.mockImplementation((path) => {
|
||||
if (path === './.yarn/cli.js') {
|
||||
return new Promise<boolean>((resolve) => resolve(true));
|
||||
}
|
||||
return new Promise<boolean>((resolve) => resolve(false));
|
||||
});
|
||||
fs.readFile.mockImplementation((filename, encoding) => {
|
||||
if (filename.endsWith('.yarnrc')) {
|
||||
return new Promise<string>((resolve) =>
|
||||
resolve(
|
||||
'yarn-offline-mirror "./packages-cache"\nyarn-path "./.yarn/cli.js"\n'
|
||||
)
|
||||
);
|
||||
}
|
||||
return new Promise<string>((resolve) => resolve(''));
|
||||
});
|
||||
expect(await _yarnHelper.checkYarnrc('/tmp/renovate')).toEqual({
|
||||
Fixtures.mock(
|
||||
{
|
||||
'.yarn/cli.js': '',
|
||||
'/tmp/renovate/.yarnrc':
|
||||
'yarn-offline-mirror "./packages-cache"\nyarn-path "/.yarn/cli.js"\n',
|
||||
},
|
||||
'/'
|
||||
);
|
||||
expect(await yarnHelper.checkYarnrc('/tmp/renovate')).toEqual({
|
||||
offlineMirror: true,
|
||||
yarnPath: './.yarn/cli.js',
|
||||
yarnPath: '/.yarn/cli.js',
|
||||
});
|
||||
});
|
||||
|
||||
it('returns no offline mirror and unquoted yarn path', async () => {
|
||||
fs.exists.mockImplementation((path) => {
|
||||
if (path === './.yarn/cli.js') {
|
||||
return new Promise<boolean>((resolve) => resolve(true));
|
||||
}
|
||||
return new Promise<boolean>((resolve) => resolve(false));
|
||||
});
|
||||
fs.readFile.mockImplementation((filename, encoding) => {
|
||||
if (filename.endsWith('.yarnrc')) {
|
||||
return new Promise<string>((resolve) =>
|
||||
resolve('yarn-path ./.yarn/cli.js\n')
|
||||
);
|
||||
}
|
||||
return new Promise<string>((resolve) => resolve(''));
|
||||
});
|
||||
expect(await _yarnHelper.checkYarnrc('/tmp/renovate')).toEqual({
|
||||
Fixtures.mock(
|
||||
{
|
||||
'.yarn/cli.js': '',
|
||||
'/tmp/renovate/.yarnrc': 'yarn-path /.yarn/cli.js\n',
|
||||
},
|
||||
'/'
|
||||
);
|
||||
expect(await yarnHelper.checkYarnrc('/tmp/renovate')).toEqual({
|
||||
offlineMirror: false,
|
||||
yarnPath: './.yarn/cli.js',
|
||||
yarnPath: '/.yarn/cli.js',
|
||||
});
|
||||
});
|
||||
|
||||
it('returns offline mirror and no yarn path for non-existant yarn-path binary', async () => {
|
||||
let yarnrcContents = 'yarn-path ./.yarn/cli.js\n';
|
||||
fs.writeFile.mockImplementation((filename, fileContents) => {
|
||||
if (filename.endsWith('.yarnrc')) {
|
||||
yarnrcContents = fileContents;
|
||||
}
|
||||
return new Promise<void>((resolve) => resolve());
|
||||
});
|
||||
fs.readFile.mockImplementation((filename, encoding) => {
|
||||
if (filename.endsWith('.yarnrc')) {
|
||||
return new Promise<string>((resolve) => resolve(yarnrcContents));
|
||||
}
|
||||
return new Promise<string>((resolve) => resolve(''));
|
||||
});
|
||||
const { offlineMirror, yarnPath } = await _yarnHelper.checkYarnrc(
|
||||
Fixtures.mock(
|
||||
{
|
||||
'.yarnrc': 'yarn-path ./.yarn/cli.js\n',
|
||||
},
|
||||
'/tmp/renovate'
|
||||
);
|
||||
const { offlineMirror, yarnPath } = await yarnHelper.checkYarnrc(
|
||||
'/tmp/renovate'
|
||||
);
|
||||
expect(offlineMirror).toBeFalse();
|
||||
expect(yarnPath).toBeNull();
|
||||
expect(yarnrcContents).not.toContain('yarn-path');
|
||||
expect(Fixtures.toJSON()['/tmp/renovate/.yarnrc']).toBe('\n');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { loadFixture } from '../../../../../test/util';
|
||||
import { Fixtures } from '../../../../../test/fixtures';
|
||||
import * as npmUpdater from '.';
|
||||
|
||||
const readFixture = (x: string): string => loadFixture(x, '../..');
|
||||
const readFixture = (x: string): string => Fixtures.get(x, '../..');
|
||||
|
||||
const input01Content = readFixture('inputs/01.json');
|
||||
const input01GlobContent = readFixture('inputs/01-glob.json');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import type { ExtractConfig } from '../types';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
|
@ -9,7 +9,7 @@ const config: ExtractConfig = {};
|
|||
describe('manager/pip_setup/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns found deps', () => {
|
||||
const content = loadFixture(packageFile);
|
||||
const content = Fixtures.get(packageFile);
|
||||
|
||||
expect(extractPackageFile(content, packageFile, config)).toMatchSnapshot({
|
||||
deps: [
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from '.';
|
||||
|
||||
const brokenYaml = loadFixture('update.yaml');
|
||||
const packageFile = loadFixture('extract.yaml');
|
||||
|
||||
describe('manager/pub/extract', () => {
|
||||
describe('extractPackageFile', () => {
|
||||
it('should return null if package does not contain any deps', () => {
|
||||
|
@ -11,11 +8,17 @@ describe('manager/pub/extract', () => {
|
|||
expect(res).toBeNull();
|
||||
});
|
||||
it('should return null if package is invalid', () => {
|
||||
const res = extractPackageFile(brokenYaml, 'pubspec.yaml');
|
||||
const res = extractPackageFile(
|
||||
Fixtures.get('update.yaml'),
|
||||
'pubspec.yaml'
|
||||
);
|
||||
expect(res).toBeNull();
|
||||
});
|
||||
it('should return valid dependencies', () => {
|
||||
const res = extractPackageFile(packageFile, 'pubspec.yaml');
|
||||
const res = extractPackageFile(
|
||||
Fixtures.get('extract.yaml'),
|
||||
'pubspec.yaml'
|
||||
);
|
||||
expect(res).toEqual({
|
||||
datasource: 'dart',
|
||||
deps: [
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from './../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const sbt = loadFixture(`sample.sbt`);
|
||||
const sbtScalaVersionVariable = loadFixture(`scala-version-variable.sbt`);
|
||||
const sbtMissingScalaVersion = loadFixture(`missing-scala-version.sbt`);
|
||||
const sbtDependencyFile = loadFixture(`dependency-file.scala`);
|
||||
const sbtPrivateVariableDependencyFile = loadFixture(
|
||||
const sbt = Fixtures.get(`sample.sbt`);
|
||||
const sbtScalaVersionVariable = Fixtures.get(`scala-version-variable.sbt`);
|
||||
const sbtMissingScalaVersion = Fixtures.get(`missing-scala-version.sbt`);
|
||||
const sbtDependencyFile = Fixtures.get(`dependency-file.scala`);
|
||||
const sbtPrivateVariableDependencyFile = Fixtures.get(
|
||||
`private-variable-dependency-file.scala`
|
||||
);
|
||||
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const content = loadFixture('setup-cfg-1.txt');
|
||||
|
||||
describe('manager/setup-cfg/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns null for empty', () => {
|
||||
expect(extractPackageFile('nothing here')).toBeNull();
|
||||
});
|
||||
it('extracts dependencies', () => {
|
||||
const res = extractPackageFile(content);
|
||||
const res = extractPackageFile(Fixtures.get('setup-cfg-1.txt'));
|
||||
expect(res).toMatchSnapshot({
|
||||
deps: [
|
||||
{ depName: 'qux', currentValue: '>=4.4.4' },
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const pkgContent = loadFixture(`SamplePackage.swift`);
|
||||
|
||||
describe('manager/swift/index', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns null for empty content', () => {
|
||||
|
@ -129,7 +127,9 @@ describe('manager/swift/index', () => {
|
|||
).toMatchSnapshot({ deps: [{ currentValue: '..<"1.2.3"' }] });
|
||||
});
|
||||
it('parses multiple packages', () => {
|
||||
expect(extractPackageFile(pkgContent)).toMatchSnapshot();
|
||||
expect(
|
||||
extractPackageFile(Fixtures.get(`SamplePackage.swift`))
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import { createReadStream } from 'fs';
|
||||
import { DirectoryResult, dir } from 'tmp-promise';
|
||||
import { Fixtures } from '../../../../test/fixtures';
|
||||
import * as httpMock from '../../../../test/http-mock';
|
||||
import { getFixturePath, loadFixture, logger } from '../../../../test/util';
|
||||
import { getFixturePath, logger } from '../../../../test/util';
|
||||
import { GlobalConfig } from '../../../config/global';
|
||||
import { TerraformProviderDatasource } from '../../../datasource/terraform-provider';
|
||||
import { Logger } from '../../../logger/types';
|
||||
import { TerraformProviderHash } from './hash';
|
||||
|
||||
const releaseBackendUrl = TerraformProviderDatasource.defaultRegistryUrls[1];
|
||||
const releaseBackendAzurerm = loadFixture('releaseBackendAzurerm_2_56_0.json');
|
||||
const releaseBackendAzurerm = Fixtures.get('releaseBackendAzurerm_2_56_0.json');
|
||||
|
||||
const log = logger.logger as jest.Mocked<Logger>;
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import { loadFixture } from '../../../../test/util';
|
||||
import { Fixtures } from '../../../../test/fixtures';
|
||||
import { extractLocks } from './util';
|
||||
|
||||
const validLockfile = loadFixture('validLockfile.hcl');
|
||||
|
||||
describe('manager/terraform/lockfile/util', () => {
|
||||
describe('extractLocks()', () => {
|
||||
it('returns null for empty', () => {
|
||||
|
@ -11,7 +9,7 @@ describe('manager/terraform/lockfile/util', () => {
|
|||
});
|
||||
|
||||
it('extracts', () => {
|
||||
const res = extractLocks(validLockfile);
|
||||
const res = extractLocks(Fixtures.get('validLockfile.hcl'));
|
||||
expect(res).toHaveLength(3);
|
||||
expect(res).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -1,25 +1,24 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { extractPackageFile } from './extract';
|
||||
|
||||
const tg1 = loadFixture('2.hcl');
|
||||
const tg2 = `terragrunt {
|
||||
source = "../../modules/fe"
|
||||
}
|
||||
`;
|
||||
|
||||
describe('manager/terragrunt/extract', () => {
|
||||
describe('extractPackageFile()', () => {
|
||||
it('returns null for empty', () => {
|
||||
expect(extractPackageFile('nothing here')).toBeNull();
|
||||
});
|
||||
it('extracts terragrunt sources', () => {
|
||||
const res = extractPackageFile(tg1);
|
||||
const res = extractPackageFile(Fixtures.get('2.hcl'));
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res.deps).toHaveLength(30);
|
||||
expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(5);
|
||||
});
|
||||
it('returns null if only local terragrunt deps', () => {
|
||||
expect(extractPackageFile(tg2)).toBeNull();
|
||||
expect(
|
||||
extractPackageFile(`terragrunt {
|
||||
source = "../../modules/fe"
|
||||
}
|
||||
`)
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { smartTruncate } from './pr-body';
|
||||
|
||||
const prBody = loadFixture('pr-body.txt');
|
||||
const prBody = Fixtures.get('pr-body.txt');
|
||||
|
||||
describe('platform/utils/pr-body', () => {
|
||||
describe('.smartTruncate', () => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { readOnlyIssueBody } from './read-only-issue-body';
|
||||
|
||||
const issueBody = loadFixture('issue-body.txt');
|
||||
const issueBody = Fixtures.get('issue-body.txt');
|
||||
|
||||
describe('platform/utils/read-only-issue-body', () => {
|
||||
describe('.readOnlyIssueBody', () => {
|
||||
|
|
|
@ -1,15 +1,24 @@
|
|||
import fs from 'fs-extra';
|
||||
import { remove } from './proxies';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { exists, readFile, remove } from './proxies';
|
||||
|
||||
jest.mock('fs-extra');
|
||||
jest.mock('fs-extra', () => Fixtures.fsExtra());
|
||||
|
||||
describe('util/fs/proxies', () => {
|
||||
beforeEach(() => {
|
||||
Fixtures.reset();
|
||||
});
|
||||
|
||||
describe('remove', () => {
|
||||
it('should call remove in fs-extra', async () => {
|
||||
(fs.remove as jest.Mock).mockResolvedValue(undefined);
|
||||
const path = 'path mock';
|
||||
expect(await remove(path)).toBeUndefined();
|
||||
expect(fs.remove).toHaveBeenNthCalledWith(1, path);
|
||||
Fixtures.mock(
|
||||
{
|
||||
test: 'test',
|
||||
},
|
||||
'/'
|
||||
);
|
||||
expect(await readFile('/test', 'utf8')).toBe('test');
|
||||
await remove('/test');
|
||||
expect(await exists('/test')).toBeFalse();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
import mockFs from 'mock-fs';
|
||||
import { loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { configFileNames } from '../../config/app-strings';
|
||||
import { GlobalConfig } from '../../config/global';
|
||||
import { EditorConfig } from './editor-config';
|
||||
import { IndentationType } from './indentation-type';
|
||||
|
||||
jest.mock('fs');
|
||||
const defaultConfigFile = configFileNames[0];
|
||||
|
||||
const GLOBAL_EDITOR_CONFIG = loadFixture('.global_editorconfig', '.');
|
||||
const JSON_FILES_EDITOR_CONFIG = loadFixture('.json_editorconfig', '.');
|
||||
const NON_JSON_FILES_EDITOR_CONFIG = loadFixture('.non_json_editorconfig', '.');
|
||||
|
||||
describe('util/json-writer/editor-config', () => {
|
||||
beforeAll(() => {
|
||||
GlobalConfig.set({
|
||||
|
@ -18,13 +14,13 @@ describe('util/json-writer/editor-config', () => {
|
|||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
beforeEach(() => {
|
||||
Fixtures.reset();
|
||||
});
|
||||
|
||||
it('should handle empty .editorconfig file', async () => {
|
||||
expect.assertions(2);
|
||||
mockFs({
|
||||
Fixtures.mock({
|
||||
'.editorconfig': '',
|
||||
});
|
||||
const format = await EditorConfig.getCodeFormat(defaultConfigFile);
|
||||
|
@ -35,8 +31,8 @@ describe('util/json-writer/editor-config', () => {
|
|||
|
||||
it('should handle global config from .editorconfig', async () => {
|
||||
expect.assertions(2);
|
||||
mockFs({
|
||||
'.editorconfig': GLOBAL_EDITOR_CONFIG,
|
||||
Fixtures.mock({
|
||||
'.editorconfig': Fixtures.get('.global_editorconfig'),
|
||||
});
|
||||
const format = await EditorConfig.getCodeFormat(defaultConfigFile);
|
||||
expect(format.indentationSize).toBe(6);
|
||||
|
@ -45,8 +41,8 @@ describe('util/json-writer/editor-config', () => {
|
|||
|
||||
it('should not handle non json config from .editorconfig', async () => {
|
||||
expect.assertions(2);
|
||||
mockFs({
|
||||
'.editorconfig': NON_JSON_FILES_EDITOR_CONFIG,
|
||||
Fixtures.mock({
|
||||
'.editorconfig': Fixtures.get('.non_json_editorconfig'),
|
||||
});
|
||||
const format = await EditorConfig.getCodeFormat(defaultConfigFile);
|
||||
|
||||
|
@ -56,8 +52,8 @@ describe('util/json-writer/editor-config', () => {
|
|||
|
||||
it('should handle json config from .editorconfig', async () => {
|
||||
expect.assertions(1);
|
||||
mockFs({
|
||||
'.editorconfig': JSON_FILES_EDITOR_CONFIG,
|
||||
Fixtures.mock({
|
||||
'.editorconfig': Fixtures.get('.json_editorconfig'),
|
||||
});
|
||||
const format = await EditorConfig.getCodeFormat(defaultConfigFile);
|
||||
|
||||
|
|
|
@ -1,24 +1,33 @@
|
|||
import { defaultConfig, loadFixture } from '../../../test/util';
|
||||
import { Fixtures } from '../../../test/fixtures';
|
||||
import { defaultConfig } from '../../../test/util';
|
||||
import { GlobalConfig } from '../../config/global';
|
||||
import { WORKER_FILE_UPDATE_FAILED } from '../../constants/error-messages';
|
||||
import { extractPackageFile } from '../../manager/html';
|
||||
import type { BranchUpgradeConfig } from '../types';
|
||||
import { doAutoReplace } from './auto-replace';
|
||||
|
||||
const sampleHtml = loadFixture('sample.html', `../../manager/html`);
|
||||
const sampleHtml = Fixtures.get('sample.html', `../../manager/html`);
|
||||
|
||||
jest.mock('../../util/fs');
|
||||
jest.mock('fs-extra', () => Fixtures.fsExtra());
|
||||
|
||||
describe('workers/branch/auto-replace', () => {
|
||||
describe('doAutoReplace', () => {
|
||||
let reuseExistingBranch: boolean;
|
||||
let upgrade: BranchUpgradeConfig;
|
||||
beforeAll(() => {
|
||||
GlobalConfig.set({
|
||||
localDir: '/temp',
|
||||
});
|
||||
});
|
||||
beforeEach(() => {
|
||||
upgrade = {
|
||||
...JSON.parse(JSON.stringify(defaultConfig)),
|
||||
manager: 'html',
|
||||
packageFile: 'test',
|
||||
};
|
||||
reuseExistingBranch = false;
|
||||
});
|
||||
|
||||
it('rebases if the deps list has changed', async () => {
|
||||
upgrade.baseDeps = extractPackageFile(sampleHtml).deps;
|
||||
reuseExistingBranch = true;
|
||||
|
|
|
@ -187,6 +187,7 @@ export async function doAutoReplace(
|
|||
newString
|
||||
);
|
||||
await writeLocalFile(upgrade.packageFile, testContent);
|
||||
|
||||
if (await confirmIfDepUpdated(upgrade, testContent)) {
|
||||
return testContent;
|
||||
}
|
||||
|
|
|
@ -221,6 +221,7 @@
|
|||
"@types/auth-header": "1.0.2",
|
||||
"@types/bunyan": "1.8.8",
|
||||
"@types/cacache": "15.0.1",
|
||||
"@types/callsite": "1.0.31",
|
||||
"@types/changelog-filename-regex": "2.0.0",
|
||||
"@types/clean-git-ref": "2.0.0",
|
||||
"@types/conventional-commits-detector": "1.0.0",
|
||||
|
@ -253,6 +254,7 @@
|
|||
"@typescript-eslint/eslint-plugin": "5.9.1",
|
||||
"@typescript-eslint/parser": "5.9.1",
|
||||
"aws-sdk-client-mock": "0.5.6",
|
||||
"callsite": "1.0.0",
|
||||
"conventional-changelog-conventionalcommits": "4.6.3",
|
||||
"cross-env": "7.0.3",
|
||||
"diff": "5.0.0",
|
||||
|
@ -275,6 +277,7 @@
|
|||
"jest-mock-extended": "2.0.4",
|
||||
"jest-silent-reporter": "0.5.0",
|
||||
"markdownlint-cli2": "0.4.0",
|
||||
"memfs": "3.3.0",
|
||||
"mock-fs": "5.1.2",
|
||||
"mockdate": "3.0.5",
|
||||
"nock": "13.2.2",
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
import type fs from 'fs';
|
||||
import type { PathLike } from 'fs';
|
||||
import callsite from 'callsite';
|
||||
import { DirectoryJSON, fs as memfs, vol } from 'memfs';
|
||||
import upath from 'upath';
|
||||
|
||||
const realFs = jest.requireActual<typeof fs>('fs');
|
||||
|
||||
/**
|
||||
* Class to work with in-memory file-system
|
||||
*/
|
||||
export class Fixtures {
|
||||
/**
|
||||
* Returns content from fixture file from __fixtures__ folder
|
||||
* @param name name of the fixture file
|
||||
* @param [fixturesRoot] - Where to find the fixtures, uses the current test folder by default
|
||||
* @returns
|
||||
*/
|
||||
static get(name: string, fixturesRoot = '.'): string {
|
||||
return realFs.readFileSync(
|
||||
upath.resolve(Fixtures.getPathToFixtures(fixturesRoot), name),
|
||||
{
|
||||
encoding: 'utf-8',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds files from a flat json object to the file-system
|
||||
* @param json flat object
|
||||
* @param cwd is an optional string used to compute absolute file paths, if a file path is given in a relative form
|
||||
*/
|
||||
static mock(json: DirectoryJSON, cwd?: string): void {
|
||||
vol.fromJSON(json, cwd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the whole contents of the volume recursively to a flat JSON object
|
||||
* @param paths is an optional argument that specifies one or more paths to be exported. If this argument is omitted, the whole volume is exported. paths can be an array of paths. A path can be a string, Buffer or an URL object.
|
||||
* @param json is an optional object parameter which will be populated with the exported files
|
||||
* @param isRelative is boolean that specifies if returned paths should be relative
|
||||
* @returns
|
||||
*/
|
||||
static toJSON(
|
||||
paths?: PathLike | PathLike[],
|
||||
json?: Record<string, unknown>,
|
||||
isRelative?: boolean
|
||||
): DirectoryJSON {
|
||||
return vol.toJSON(paths, json, isRelative);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all files from the volume.
|
||||
*/
|
||||
static reset(): void {
|
||||
vol.reset();
|
||||
}
|
||||
|
||||
// Temporary solution, when all tests will be rewritten to Fixtures mocks can be moved into __mocks__ folder
|
||||
static fsExtra(): any {
|
||||
return {
|
||||
...memfs,
|
||||
pathExists: jest.fn().mockImplementation(pathExists),
|
||||
remove: jest.fn().mockImplementation(memfs.promises.rm),
|
||||
readFile: jest.fn().mockImplementation(memfs.promises.readFile),
|
||||
writeFile: jest.fn().mockImplementation(memfs.promises.writeFile),
|
||||
outputFile: jest.fn().mockImplementation(outputFile),
|
||||
};
|
||||
}
|
||||
|
||||
private static getPathToFixtures(fixturesRoot = '.'): string {
|
||||
const stack = callsite();
|
||||
const callerDir = upath.dirname(stack[2].getFileName());
|
||||
return upath.resolve(callerDir, fixturesRoot, '__fixtures__');
|
||||
}
|
||||
}
|
||||
|
||||
export async function outputFile(
|
||||
file: string,
|
||||
data: string | Buffer | Uint8Array
|
||||
): Promise<void> {
|
||||
const dir = upath.dirname(file);
|
||||
|
||||
if (await pathExists(dir)) {
|
||||
await memfs.promises.writeFile(file, data);
|
||||
} else {
|
||||
await memfs.promises.mkdir(dir, {
|
||||
recursive: true,
|
||||
});
|
||||
await memfs.promises.writeFile(file, data);
|
||||
}
|
||||
}
|
||||
|
||||
async function pathExists(path: string): Promise<boolean> {
|
||||
try {
|
||||
await memfs.promises.access(path);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
22
yarn.lock
22
yarn.lock
|
@ -2204,6 +2204,11 @@
|
|||
"@types/node" "*"
|
||||
"@types/responselike" "*"
|
||||
|
||||
"@types/callsite@1.0.31":
|
||||
version "1.0.31"
|
||||
resolved "https://registry.yarnpkg.com/@types/callsite/-/callsite-1.0.31.tgz#55cfc887088d67f0310fcb20bd9100bb7146d2fc"
|
||||
integrity sha512-jrKmIHhuZVGUpOR1s4TgY9BTt/Eh9CFCjHVZ2FsrKmHSo3J/vpl6EpK08SfMLrX2IY1ZEFA+BPRTJQGg4xIHsA==
|
||||
|
||||
"@types/changelog-filename-regex@2.0.0":
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/changelog-filename-regex/-/changelog-filename-regex-2.0.0.tgz#b5af0ee9b36106f593dfd6ac6b6514ec166c4ef2"
|
||||
|
@ -3300,6 +3305,11 @@ call-bind@^1.0.0, call-bind@^1.0.2:
|
|||
function-bind "^1.1.1"
|
||||
get-intrinsic "^1.0.2"
|
||||
|
||||
callsite@1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/callsite/-/callsite-1.0.0.tgz#280398e5d664bd74038b6f0905153e6e8af1bc20"
|
||||
integrity sha1-KAOY5dZkvXQDi28JBRU+borxvCA=
|
||||
|
||||
callsites@^3.0.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
|
||||
|
@ -4704,6 +4714,11 @@ fs-minipass@^2.0.0, fs-minipass@^2.1.0:
|
|||
dependencies:
|
||||
minipass "^3.0.0"
|
||||
|
||||
fs-monkey@1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/fs-monkey/-/fs-monkey-1.0.3.tgz#ae3ac92d53bb328efe0e9a1d9541f6ad8d48e2d3"
|
||||
integrity sha512-cybjIfiiE+pTWicSCLFHSrXZ6EilF30oh91FDP9S2B051prEa7QWfrVTQm10/dDpswBDXZugPa1Ogu8Yh+HV0Q==
|
||||
|
||||
fs.realpath@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
|
||||
|
@ -6701,6 +6716,13 @@ mdurl@^1.0.1:
|
|||
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
|
||||
integrity sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=
|
||||
|
||||
memfs@3.3.0:
|
||||
version "3.3.0"
|
||||
resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.3.0.tgz#4da2d1fc40a04b170a56622c7164c6be2c4cbef2"
|
||||
integrity sha512-BEE62uMfKOavX3iG7GYX43QJ+hAeeWnwIAuJ/R6q96jaMtiLzhsxHJC8B1L7fK7Pt/vXDRwb3SG/yBpNGDPqzg==
|
||||
dependencies:
|
||||
fs-monkey "1.0.3"
|
||||
|
||||
memorystream@^0.3.1:
|
||||
version "0.3.1"
|
||||
resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2"
|
||||
|
|
Загрузка…
Ссылка в новой задаче