Skip to content
Snippets Groups Projects
Unverified Commit 71de9dc6 authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

refactor(datasource): More explicit snapshot tests (#11199)

parent 159fed42
No related branches found
No related tags found
No related merge requests found
......@@ -22,20 +22,3 @@ Object {
"sourceUrl": "https://github.com/nodejs/node",
}
`;
exports[`datasource/index merges registries and returns success 1`] = `
Object {
"releases": Array [
Object {
"registryUrl": "https://reg1.com",
"version": "1.0.0",
},
Object {
"registryUrl": "https://reg1.com",
"version": "1.1.0",
},
],
}
`;
exports[`datasource/index warns if multiple registryUrls for registryStrategy=first 1`] = `null`;
......@@ -116,10 +116,10 @@ describe(getName(), () => {
datasource: datasourceNpm.id,
depName: 'react-native',
});
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res.changelogUrl).toBeDefined();
expect(res.sourceUrl).toBeDefined();
expect(res).toMatchSnapshot({
changelogUrl:
'https://github.com/react-native-community/react-native-releases/blob/master/CHANGELOG.md',
});
});
it('applies extractVersion', async () => {
npmDatasource.getReleases.mockResolvedValue({
......@@ -146,9 +146,9 @@ describe(getName(), () => {
datasource: datasourceNpm.id,
depName: 'node',
});
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBeDefined();
expect(res).toMatchSnapshot({
sourceUrl: 'https://github.com/nodejs/node',
});
});
it('ignores and warns for registryUrls', async () => {
await datasource.getPkgReleases({
......@@ -165,8 +165,7 @@ describe(getName(), () => {
depName: 'something',
registryUrls: ['https://docker.com', 'https://docker.io'],
});
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toBeNull();
});
it('hunts registries and returns success', async () => {
packagistDatasource.getReleases.mockResolvedValueOnce(null);
......@@ -231,9 +230,18 @@ describe(getName(), () => {
depName: 'something',
registryUrls: ['https://reg1.com', 'https://reg2.io'],
});
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(2);
expect(res).toEqual({
releases: [
{
registryUrl: 'https://reg1.com',
version: '1.0.0',
},
{
registryUrl: 'https://reg1.com',
version: '1.1.0',
},
],
});
});
it('merges registries and aborts on ExternalHostError', async () => {
mavenDatasource.getReleases.mockImplementationOnce(() => {
......
......@@ -3,6 +3,7 @@ import * as datasourceMaven from './maven';
import { addMetaData } from './metadata';
import * as datasourceNpm from './npm';
import { PypiDatasource } from './pypi';
import type { ReleaseResult } from './types';
describe(getName(), () => {
it('Should do nothing if dep is not specified', () => {
......@@ -10,7 +11,7 @@ describe(getName(), () => {
});
it('Should handle manualChangelogUrls', () => {
const dep = {
const dep: ReleaseResult = {
releases: [
{ version: '2.0.0', releaseTimestamp: '2018-07-13T10:14:17.000Z' },
{
......@@ -26,12 +27,14 @@ describe(getName(), () => {
const lookupName = 'django';
addMetaData(dep, datasource, lookupName);
// FIXME: explicit assert condition
expect(dep).toMatchSnapshot();
expect(dep).toMatchSnapshot({
changelogUrl:
'https://github.com/django/django/tree/master/docs/releases',
});
});
it('Should handle manualSourceUrls', () => {
const dep = {
const dep: ReleaseResult = {
releases: [
{ version: '2.0.0', releaseTimestamp: '2018-07-13T10:14:17.000Z' },
{
......@@ -47,12 +50,13 @@ describe(getName(), () => {
const lookupName = 'mkdocs';
addMetaData(dep, datasource, lookupName);
// FIXME: explicit assert condition
expect(dep).toMatchSnapshot();
expect(dep).toMatchSnapshot({
sourceUrl: 'https://github.com/mkdocs/mkdocs',
});
});
it('Should handle parsing of sourceUrls correctly', () => {
const dep = {
const dep: ReleaseResult = {
sourceUrl: 'https://github.com/carltongibson/django-filter/tree/master',
releases: [
{ version: '2.0.0', releaseTimestamp: '2018-07-13T10:14:17.000Z' },
......@@ -68,12 +72,13 @@ describe(getName(), () => {
const lookupName = 'django-filter';
addMetaData(dep, datasource, lookupName);
// FIXME: explicit assert condition
expect(dep).toMatchSnapshot();
expect(dep).toMatchSnapshot({
sourceUrl: 'https://github.com/carltongibson/django-filter',
});
});
it('Should handle parsing of sourceUrls correctly for GitLab also', () => {
const dep = {
const dep: ReleaseResult = {
sourceUrl: 'https://gitlab.com/meno/dropzone/tree/master',
releases: [
{ version: '5.7.0', releaseTimestamp: '2020-02-14T13:12:00.000Z' },
......@@ -87,8 +92,9 @@ describe(getName(), () => {
const lookupName = 'dropzone';
addMetaData(dep, datasource, lookupName);
// FIXME: explicit assert condition
expect(dep).toMatchSnapshot();
expect(dep).toMatchSnapshot({
sourceUrl: 'https://gitlab.com/meno/dropzone',
});
});
it('Should handle failed parsing of sourceUrls for GitLab', () => {
const dep = {
......@@ -105,8 +111,9 @@ describe(getName(), () => {
const lookupName = 'dropzone';
addMetaData(dep, datasource, lookupName);
// FIXME: explicit assert condition
expect(dep).toMatchSnapshot();
expect(dep).toMatchSnapshot({
sourceUrl: 'https://gitlab-nope',
});
});
it('Should handle failed parsing of sourceUrls for other', () => {
const dep = {
......@@ -123,8 +130,9 @@ describe(getName(), () => {
const lookupName = 'dropzone';
addMetaData(dep, datasource, lookupName);
// FIXME: explicit assert condition
expect(dep).toMatchSnapshot();
expect(dep).toMatchSnapshot({
sourceUrl: 'https://nope-nope-nope',
});
});
it('Should handle non-url', () => {
const dep = {
......@@ -141,7 +149,7 @@ describe(getName(), () => {
const lookupName = 'dropzone';
addMetaData(dep, datasource, lookupName);
// FIXME: explicit assert condition
expect(dep).not.toContainKey('sourceUrl');
expect(dep).toMatchSnapshot();
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment