Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/routes/stats/npm/-utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import * as v from 'valibot'
import { MAX_NPM_STATS_GROUPS } from '~/utils/npm-stats-limits'

// Re-export shared types from chart utils
export {
binTypeSchema,
type BinType,
binningOptions,
getBinFunction,
} from '~/utils/chart'
// Re-export shared types and schema without importing chart utilities.
export { binTypeSchema, type BinType } from '~/components/npm-stats/shared'
export {
chartTypeSchema,
type ChartType,
Expand Down
27 changes: 27 additions & 0 deletions tests/chart-route-validation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// <reference types="node" />

import assert from 'node:assert/strict'
import test from 'node:test'
import { Route } from '../src/routes/stats/npm/$packages'

const schema = Route.options.validateSearch
assert.ok(schema && typeof schema === 'object' && '~standard' in schema)
const standardSchema = schema['~standard']

test('npm comparison route preserves binType search validation', async () => {
const defaultResult = await standardSchema.validate({})
assert.equal(defaultResult.issues, undefined)
assert.equal(defaultResult.value.binType, 'weekly')

for (const binType of ['yearly', 'monthly', 'weekly', 'daily']) {
const result = await standardSchema.validate({ binType })
assert.equal(result.issues, undefined)
assert.equal(result.value.binType, binType)
}
})

test('npm comparison route defaults invalid binType search values', async () => {
const result = await standardSchema.validate({ binType: 'hourly' })
assert.equal(result.issues, undefined)
assert.equal(result.value.binType, 'weekly')
})
Loading