Skip to content

Commit

Permalink
refactor(datasource): Enforce getName usage (#9524)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Apr 14, 2021
1 parent 44c8508 commit 82fa5ce
Show file tree
Hide file tree
Showing 49 changed files with 310 additions and 286 deletions.
24 changes: 12 additions & 12 deletions lib/datasource/cdnjs/__snapshots__/index.spec.ts.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`datasource/cdnjs getReleases filters releases by asset presence 1`] = `
exports[`datasource/cdnjs/index getReleases filters releases by asset presence 1`] = `
Object {
"homepage": "http://bulma.io",
"registryUrl": "https://api.cdnjs.com/",
Expand All @@ -13,7 +13,7 @@ Object {
}
`;

exports[`datasource/cdnjs getReleases filters releases by asset presence 2`] = `
exports[`datasource/cdnjs/index getReleases filters releases by asset presence 2`] = `
Array [
Object {
"headers": Object {
Expand All @@ -28,7 +28,7 @@ Array [
]
`;

exports[`datasource/cdnjs getReleases processes real data 1`] = `
exports[`datasource/cdnjs/index getReleases processes real data 1`] = `
Object {
"homepage": "https://d3js.org/d3-force/",
"registryUrl": "https://api.cdnjs.com/",
Expand Down Expand Up @@ -142,7 +142,7 @@ Object {
}
`;

exports[`datasource/cdnjs getReleases processes real data 2`] = `
exports[`datasource/cdnjs/index getReleases processes real data 2`] = `
Array [
Object {
"headers": Object {
Expand All @@ -157,7 +157,7 @@ Array [
]
`;

exports[`datasource/cdnjs getReleases returns null for 404 1`] = `
exports[`datasource/cdnjs/index getReleases returns null for 404 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -172,7 +172,7 @@ Array [
]
`;

exports[`datasource/cdnjs getReleases returns null for empty 200 OK 1`] = `
exports[`datasource/cdnjs/index getReleases returns null for empty 200 OK 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -187,7 +187,7 @@ Array [
]
`;

exports[`datasource/cdnjs getReleases returns null for unknown error 1`] = `
exports[`datasource/cdnjs/index getReleases returns null for unknown error 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -202,7 +202,7 @@ Array [
]
`;

exports[`datasource/cdnjs getReleases throws for 5xx 1`] = `
exports[`datasource/cdnjs/index getReleases throws for 5xx 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -217,7 +217,7 @@ Array [
]
`;

exports[`datasource/cdnjs getReleases throws for 401 1`] = `
exports[`datasource/cdnjs/index getReleases throws for 401 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -232,7 +232,7 @@ Array [
]
`;

exports[`datasource/cdnjs getReleases throws for 429 1`] = `
exports[`datasource/cdnjs/index getReleases throws for 429 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -247,7 +247,7 @@ Array [
]
`;

exports[`datasource/cdnjs getReleases throws for empty result 1`] = `
exports[`datasource/cdnjs/index getReleases throws for empty result 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -262,7 +262,7 @@ Array [
]
`;

exports[`datasource/cdnjs getReleases throws for error 1`] = `
exports[`datasource/cdnjs/index getReleases throws for error 1`] = `
Array [
Object {
"headers": Object {
Expand Down
3 changes: 2 additions & 1 deletion lib/datasource/cdnjs/index.spec.ts
@@ -1,6 +1,7 @@
import fs from 'fs';
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { getName } from '../../../test/util';
import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
import { id as datasource } from '.';

Expand All @@ -21,7 +22,7 @@ const baseUrl = 'https://api.cdnjs.com/';
const pathFor = (s: string): string =>
`/libraries/${s.split('/').shift()}?fields=homepage,repository,assets`;

describe('datasource/cdnjs', () => {
describe(getName(__filename), () => {
describe('getReleases', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down
28 changes: 14 additions & 14 deletions lib/datasource/crate/__snapshots__/index.spec.ts.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`datasource/crate getReleases clones cloudsmith private registry 1`] = `
exports[`datasource/crate/index getReleases clones cloudsmith private registry 1`] = `
Object {
"dependencyUrl": "https://cloudsmith.io/~myorg/repos/myrepo/packages/detail/cargo/mypkg",
"registryUrl": "https://dl.cloudsmith.io/basic/myorg/myrepo/cargo/index.git",
Expand All @@ -15,7 +15,7 @@ Object {
}
`;

exports[`datasource/crate getReleases clones other private registry 1`] = `
exports[`datasource/crate/index getReleases clones other private registry 1`] = `
Object {
"dependencyUrl": "https://github.com/mcorbin/testregistry/mypkg",
"registryUrl": "https://github.com/mcorbin/testregistry",
Expand All @@ -30,7 +30,7 @@ Object {
}
`;

exports[`datasource/crate getReleases processes real data: amethyst 1`] = `
exports[`datasource/crate/index getReleases processes real data: amethyst 1`] = `
Object {
"dependencyUrl": "https://crates.io/crates/amethyst",
"registryUrl": "https://crates.io",
Expand Down Expand Up @@ -97,7 +97,7 @@ Object {
}
`;

exports[`datasource/crate getReleases processes real data: amethyst 2`] = `
exports[`datasource/crate/index getReleases processes real data: amethyst 2`] = `
Array [
Object {
"headers": Object {
Expand All @@ -111,7 +111,7 @@ Array [
]
`;

exports[`datasource/crate getReleases processes real data: libc 1`] = `
exports[`datasource/crate/index getReleases processes real data: libc 1`] = `
Object {
"dependencyUrl": "https://crates.io/crates/libc",
"registryUrl": "https://crates.io",
Expand Down Expand Up @@ -317,7 +317,7 @@ Object {
}
`;

exports[`datasource/crate getReleases processes real data: libc 2`] = `
exports[`datasource/crate/index getReleases processes real data: libc 2`] = `
Array [
Object {
"headers": Object {
Expand All @@ -331,9 +331,9 @@ Array [
]
`;

exports[`datasource/crate getReleases refuses to clone if trustLevel is not high 1`] = `null`;
exports[`datasource/crate/index getReleases refuses to clone if trustLevel is not high 1`] = `null`;

exports[`datasource/crate getReleases returns null for 404 1`] = `
exports[`datasource/crate/index getReleases returns null for 404 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -347,7 +347,7 @@ Array [
]
`;

exports[`datasource/crate getReleases returns null for empty list 1`] = `
exports[`datasource/crate/index getReleases returns null for empty list 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -361,7 +361,7 @@ Array [
]
`;

exports[`datasource/crate getReleases returns null for empty result 1`] = `
exports[`datasource/crate/index getReleases returns null for empty result 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -375,7 +375,7 @@ Array [
]
`;

exports[`datasource/crate getReleases returns null for missing fields 1`] = `
exports[`datasource/crate/index getReleases returns null for missing fields 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -389,7 +389,7 @@ Array [
]
`;

exports[`datasource/crate getReleases returns null for unknown error 1`] = `
exports[`datasource/crate/index getReleases returns null for unknown error 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -403,9 +403,9 @@ Array [
]
`;

exports[`datasource/crate getReleases throws for 5xx 1`] = `[Error: external-host-error]`;
exports[`datasource/crate/index getReleases throws for 5xx 1`] = `[Error: external-host-error]`;

exports[`datasource/crate getReleases throws for 5xx 2`] = `
exports[`datasource/crate/index getReleases throws for 5xx 2`] = `
Array [
Object {
"headers": Object {
Expand Down
3 changes: 2 additions & 1 deletion lib/datasource/crate/index.spec.ts
Expand Up @@ -5,6 +5,7 @@ import { DirectoryResult, dir } from 'tmp-promise';
import { dirname, join } from 'upath';
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { getName } from '../../../test/util';
import { setAdminConfig } from '../../config/admin';
import * as memCache from '../../util/cache/memory';
import { setFsConfig } from '../../util/fs';
Expand Down Expand Up @@ -67,7 +68,7 @@ function setupErrorGitMock(): { mockClone: jest.Mock<any, any> } {
return { mockClone };
}

describe('datasource/crate', () => {
describe(getName(__filename), () => {
describe('getIndexSuffix', () => {
it('returns correct suffixes', () => {
expect(getIndexSuffix('a')).toStrictEqual(['1', 'a']);
Expand Down
16 changes: 8 additions & 8 deletions lib/datasource/dart/__snapshots__/index.spec.ts.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`datasource/dart getReleases processes real data 1`] = `
exports[`datasource/dart/index getReleases processes real data 1`] = `
Object {
"registryUrl": "https://pub.dartlang.org/",
"releases": Array [
Expand Down Expand Up @@ -185,7 +185,7 @@ Object {
}
`;

exports[`datasource/dart getReleases processes real data 2`] = `
exports[`datasource/dart/index getReleases processes real data 2`] = `
Array [
Object {
"headers": Object {
Expand All @@ -200,7 +200,7 @@ Array [
]
`;

exports[`datasource/dart getReleases returns null for 404 1`] = `
exports[`datasource/dart/index getReleases returns null for 404 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -215,7 +215,7 @@ Array [
]
`;

exports[`datasource/dart getReleases returns null for empty fields 1`] = `
exports[`datasource/dart/index getReleases returns null for empty fields 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -240,7 +240,7 @@ Array [
]
`;

exports[`datasource/dart getReleases returns null for empty result 1`] = `
exports[`datasource/dart/index getReleases returns null for empty result 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -255,7 +255,7 @@ Array [
]
`;

exports[`datasource/dart getReleases returns null for unknown error 1`] = `
exports[`datasource/dart/index getReleases returns null for unknown error 1`] = `
Array [
Object {
"headers": Object {
Expand All @@ -270,9 +270,9 @@ Array [
]
`;

exports[`datasource/dart getReleases throws for 5xx 1`] = `[Error: external-host-error]`;
exports[`datasource/dart/index getReleases throws for 5xx 1`] = `[Error: external-host-error]`;

exports[`datasource/dart getReleases throws for 5xx 2`] = `
exports[`datasource/dart/index getReleases throws for 5xx 2`] = `
Array [
Object {
"headers": Object {
Expand Down
3 changes: 2 additions & 1 deletion lib/datasource/dart/index.spec.ts
@@ -1,6 +1,7 @@
import fs from 'fs';
import { getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { getName } from '../../../test/util';
import { id as datasource } from '.';

const body: any = JSON.parse(
Expand All @@ -12,7 +13,7 @@ const body: any = JSON.parse(

const baseUrl = 'https://pub.dartlang.org/api/packages/';

describe('datasource/dart', () => {
describe(getName(__filename), () => {
beforeEach(() => {
httpMock.setup();
});
Expand Down

0 comments on commit 82fa5ce

Please sign in to comment.