Skip to content

Commit

Permalink
Merge branch 'master' into 9816-docusaurus
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s authored Mar 23, 2024
2 parents 8e854b4 + df8049a commit e4f7224
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
11 changes: 11 additions & 0 deletions services/npm/npm-downloads-redirect.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { redirector } from '../index.js'

export default redirector({
category: 'downloads',
route: {
base: 'npm/dt',
pattern: ':packageName+',
},
transformPath: ({ packageName }) => `/npm/d18m/${packageName}`,
dateAdded: new Date('2024-03-19'),
})
7 changes: 4 additions & 3 deletions services/npm/npm-downloads.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const intervalMap = {
transform: json => json.downloads,
interval: 'year',
},
dt: {
d18m: {
query: 'range/1000-01-01:3000-01-01',
// https://github.com/npm/registry/blob/master/docs/download-counts.md#output-1
schema: Joi.object({
Expand All @@ -48,7 +48,7 @@ export default class NpmDownloads extends BaseJsonService {

static route = {
base: 'npm',
pattern: ':interval(dw|dm|dy|dt)/:scope(@.+)?/:packageName',
pattern: ':interval(dw|dm|dy|d18m)/:scope(@.+)?/:packageName',
}

static openApi = {
Expand All @@ -59,7 +59,8 @@ export default class NpmDownloads extends BaseJsonService {
{
name: 'interval',
example: 'dw',
description: 'Weekly, Monthly, Yearly, or Total downloads',
description:
'Downloads in the last Week, Month, Year, or 18 Months',
schema: { type: 'string', enum: this.getEnum('interval') },
},
{
Expand Down
4 changes: 2 additions & 2 deletions services/npm/npm-downloads.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test, given } from 'sazerac'
import NpmDownloads from './npm-downloads.service.js'

describe('NpmDownloads', function () {
test(NpmDownloads._intervalMap.dt.transform, () => {
test(NpmDownloads._intervalMap.d18m.transform, () => {
given({
downloads: [
{ downloads: 2, day: '2018-01-01' },
Expand All @@ -13,7 +13,7 @@ describe('NpmDownloads', function () {

test(NpmDownloads.render, () => {
given({
interval: 'dt',
interval: 'd18m',
downloadCount: 0,
}).expect({
color: 'red',
Expand Down
26 changes: 18 additions & 8 deletions services/npm/npm-downloads.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,30 @@ t.create('weekly downloads of @cycle/core')
.get('/dw/@cycle/core.json')
.expectBadge({ label: 'downloads', message: isMetricOverTimePeriod })

t.create('total downloads of left-pad').get('/dt/left-pad.json').expectBadge({
label: 'downloads',
message: isMetric,
color: 'brightgreen',
})
t.create('downloads in last 18 months of left-pad')
.get('/d18m/left-pad.json')
.expectBadge({
label: 'downloads',
message: isMetric,
color: 'brightgreen',
})

t.create('total downloads of @cycle/core')
.get('/dt/@cycle/core.json')
t.create('downloads in last 18 months of @cycle/core')
.get('/d18m/@cycle/core.json')
.expectBadge({ label: 'downloads', message: isMetric })

t.create('downloads of unknown package')
.get('/dt/npm-api-does-not-have-this-package.json')
.get('/dy/npm-api-does-not-have-this-package.json')
.expectBadge({
label: 'downloads',
message: 'package not found or too new',
color: 'red',
})

t.create('Total downloads redirect: unscoped package')
.get('/dt/left-pad.svg')
.expectRedirect('/npm/d18m/left-pad.svg')

t.create('Total downloads redirect: scoped package')
.get('/dt/@cycle/core.svg')
.expectRedirect('/npm/d18m/@cycle/core.svg')

0 comments on commit e4f7224

Please sign in to comment.