Skip to content
Snippets Groups Projects
Commit 79de1b1e authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

Use npm Registry Filter Header (#249)

Closes #245
parent f5a92e80
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,9 @@ async function getDependency(name) {
const authInfo = registryAuthToken(regUrl);
const headers = {};
// Reduce metadata https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md
headers.accept = 'application/vnd.npm.install-v1+json';
if (authInfo) {
headers.authorization = `${authInfo.type} ${authInfo.token}`;
}
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`api/npm should fetch package info from npm 1`] = `
Array [
"https://npm.mycustomregistry.com/foobar",
Object {
"headers": Object {
"accept": "application/vnd.npm.install-v1+json",
},
"json": true,
},
]
`;
exports[`api/npm should send an authorization header if provided 1`] = `
Array [
"https://npm.mycustomregistry.com/foobar",
Object {
"headers": Object {
"accept": "application/vnd.npm.install-v1+json",
"authorization": "Basic 1234",
},
"json": true,
},
]
`;
......@@ -17,10 +17,7 @@ describe('api/npm', () => {
const res = await npm.getDependency('foobar');
expect(res).toMatchObject({ some: 'data' });
const call = got.mock.calls[0];
expect(call).toMatchObject([
'https://npm.mycustomregistry.com/foobar',
{ json: true, headers: {} },
]);
expect(call).toMatchSnapshot();
});
it('should send an authorization header if provided', async () => {
registryUrl.mockImplementation(() => 'https://npm.mycustomregistry.com/');
......@@ -32,14 +29,6 @@ describe('api/npm', () => {
const res = await npm.getDependency('foobar');
expect(res).toMatchObject({ some: 'data' });
const call = got.mock.calls[0];
expect(call).toMatchObject([
'https://npm.mycustomregistry.com/foobar',
{
json: true,
headers: {
authorization: 'Basic 1234',
},
},
]);
expect(call).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