diff --git a/core/index.js b/core/index.js index 9cdc22f..683f46c 100644 --- a/core/index.js +++ b/core/index.js @@ -18,7 +18,7 @@ async function core(options) { // instantiate our data object, to be expanded upon const data = {}; - Object.keys(versions).map(async (version) => { + for (const version of Object.keys(versions)) { // keep the pre-release identifiers, otherwise every Alpha release (like // `v27.0.0-alpha.0.0.0`) would be coerced into `v27.0.0` const versionSemver = semver.coerce(versions[version].version, { @@ -133,10 +133,8 @@ async function core(options) { data[name].support.phases.dates.end = schedule[name]?.end ?? undefined; } data[name].support.phases.current = - (await determineCurrentReleasePhase( - now, - data[name].support.phases.dates, - )) ?? {}; + determineCurrentReleasePhase(now, data[name].support.phases.dates) ?? + {}; } // this is a slightly inefficient way to do this but it's also easy @@ -194,12 +192,12 @@ async function core(options) { data[name].releases[`v${versionSemver.version}`].security.isSecurity = versions[version].security ?? false; - }); + } return data; } -async function determineCurrentReleasePhase(now, dates = {}) { +function determineCurrentReleasePhase(now, dates = {}) { // we set set this up to enable custom `now` passing, since passing an ISO // const usableNow = DateTime.fromISO(now) diff --git a/core/test/errors.js b/core/test/errors.js new file mode 100644 index 0000000..fca5c0a --- /dev/null +++ b/core/test/errors.js @@ -0,0 +1,13 @@ +const { rejects } = require('node:assert'); +const nodevu = require('../index'); +const { describe, it } = require('node:test'); + +describe('errors while building the data', async () => { + it('should reject when index.json has a version that cannot be parsed', async () => { + const index = [{ version: 'not-a-version', files: [] }]; + const fetch = async (url) => + Response.json(url.endsWith('schedule.json') ? {} : index); + + await rejects(nodevu({ fetch, now: '2024-01-01T00:00:00.000Z' })); + }); +});