-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tierney Cyren <[email protected]>
- Loading branch information
Showing
8 changed files
with
115 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,65 @@ | ||
const { deepStrictEqual } = require('node:assert'); | ||
const { describe, it, beforeEach } = require('test'); | ||
const { fetch: undiciFetch } = require('undici') | ||
const { DateTime } = require('luxon') | ||
const { fetch: undiciFetch } = require('undici'); | ||
const { DateTime } = require('luxon'); | ||
const nodevu = require('../index'); | ||
const parseOptions = require('../util/prod/optionsParser') | ||
const parseOptions = require('../util/prod/optionsParser'); | ||
|
||
describe('the parseOptions module should return all correct defaults', async () => { | ||
it('should return the default date', async () => { | ||
const now = DateTime.now() | ||
const now = DateTime.now(); | ||
const defaultParsedOptions = parseOptions({}); | ||
deepStrictEqual(defaultParsedOptions.now.day, now.day) | ||
deepStrictEqual(defaultParsedOptions.now.hour, now.hour) | ||
deepStrictEqual(defaultParsedOptions.now.minute, now.minute) | ||
deepStrictEqual(defaultParsedOptions.now.month, now.month) | ||
}) | ||
deepStrictEqual(defaultParsedOptions.now.day, now.day); | ||
deepStrictEqual(defaultParsedOptions.now.hour, now.hour); | ||
deepStrictEqual(defaultParsedOptions.now.minute, now.minute); | ||
deepStrictEqual(defaultParsedOptions.now.month, now.month); | ||
}); | ||
|
||
it('defaultParsedOptions.fetch should be globalThis.fetch when no options are passed', async () => { | ||
const defaultParsedOptions = parseOptions({}); | ||
deepStrictEqual(defaultParsedOptions.fetch, globalThis.fetch) | ||
}) | ||
deepStrictEqual(defaultParsedOptions.fetch, globalThis.fetch); | ||
}); | ||
|
||
it('should return the origin index.json for url.index', async () => { | ||
const defaultParsedOptions = parseOptions({}); | ||
deepStrictEqual(defaultParsedOptions.urls.index, 'https://nodejs.org/dist/index.json') | ||
}) | ||
deepStrictEqual( | ||
defaultParsedOptions.urls.index, | ||
'https://nodejs.org/dist/index.json', | ||
); | ||
}); | ||
|
||
it('should return the origin schedule.json for url.schedule', async () => { | ||
const defaultParsedOptions = parseOptions({}); | ||
deepStrictEqual(defaultParsedOptions.urls.schedule, 'https://raw.githubusercontent.com/nodejs/Release/master/schedule.json') | ||
}) | ||
}) | ||
deepStrictEqual( | ||
defaultParsedOptions.urls.schedule, | ||
'https://raw.githubusercontent.com/nodejs/Release/master/schedule.json', | ||
); | ||
}); | ||
}); | ||
|
||
describe('the parseOptions module should still work when defaults are changed', async () => { | ||
it('should still work when a custom date is passed', async () => { | ||
const currentNow = DateTime.now() | ||
const currentNow = DateTime.now(); | ||
const defaultParsedOptions = parseOptions({ now: currentNow }); | ||
deepStrictEqual(defaultParsedOptions.now, currentNow) | ||
}) | ||
deepStrictEqual(defaultParsedOptions.now, currentNow); | ||
}); | ||
|
||
it('defaultParsedOptions.fetch should be globalThis.fetch when no options are passed', async () => { | ||
const defaultParsedOptions = parseOptions({ fetch: undiciFetch }); | ||
deepStrictEqual(defaultParsedOptions.fetch, undiciFetch) | ||
}) | ||
deepStrictEqual(defaultParsedOptions.fetch, undiciFetch); | ||
}); | ||
|
||
it('should return the origin index.json for url.index', async () => { | ||
const defaultParsedOptions = parseOptions({ urls: { index: 'https://example.com'}}); | ||
deepStrictEqual(defaultParsedOptions.urls.index, 'https://example.com') | ||
}) | ||
const defaultParsedOptions = parseOptions({ | ||
urls: { index: 'https://example.com' }, | ||
}); | ||
deepStrictEqual(defaultParsedOptions.urls.index, 'https://example.com'); | ||
}); | ||
|
||
it('should return the origin schedule.json for url.schedule', async () => { | ||
const defaultParsedOptions = parseOptions({ urls: { schedule: 'https://example.com'}}); | ||
deepStrictEqual(defaultParsedOptions.urls.schedule, 'https://example.com') | ||
}) | ||
}) | ||
const defaultParsedOptions = parseOptions({ | ||
urls: { schedule: 'https://example.com' }, | ||
}); | ||
deepStrictEqual(defaultParsedOptions.urls.schedule, 'https://example.com'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
const { deepStrictEqual } = require('node:assert'); | ||
const { describe, it } = require('test'); | ||
const { fetch: undiciFetch } = require('undici') | ||
const { fetch: undiciFetch } = require('undici'); | ||
const { DateTime } = require('luxon'); | ||
const nodevu = require('../index'); | ||
const versions = require('../util/prod/versions') | ||
const optionsParser = require('../util/prod/optionsParser') | ||
const versions = require('../util/prod/versions'); | ||
const optionsParser = require('../util/prod/optionsParser'); | ||
|
||
// checks that verify the result of data returned | ||
function check (data) { | ||
deepStrictEqual(typeof data[0].version, 'string') | ||
deepStrictEqual(typeof data[0].date, 'string') | ||
deepStrictEqual(Array.isArray(data[0].files), true) | ||
deepStrictEqual(typeof data[0].npm, 'string') | ||
deepStrictEqual(typeof data[0].v8, 'string') | ||
deepStrictEqual(typeof data[0].uv, 'string') | ||
deepStrictEqual(typeof data[0].zlib, 'string') | ||
deepStrictEqual(typeof data[0].openssl, 'string') | ||
deepStrictEqual(typeof data[0].modules, 'string') | ||
deepStrictEqual(typeof data[0].lts, 'boolean') | ||
deepStrictEqual(typeof data[0].security, 'boolean') | ||
function check(data) { | ||
deepStrictEqual(typeof data[0].version, 'string'); | ||
deepStrictEqual(typeof data[0].date, 'string'); | ||
deepStrictEqual(Array.isArray(data[0].files), true); | ||
deepStrictEqual(typeof data[0].npm, 'string'); | ||
deepStrictEqual(typeof data[0].v8, 'string'); | ||
deepStrictEqual(typeof data[0].uv, 'string'); | ||
deepStrictEqual(typeof data[0].zlib, 'string'); | ||
deepStrictEqual(typeof data[0].openssl, 'string'); | ||
deepStrictEqual(typeof data[0].modules, 'string'); | ||
deepStrictEqual(typeof data[0].lts, 'boolean'); | ||
deepStrictEqual(typeof data[0].security, 'boolean'); | ||
} | ||
|
||
// set up options object that would normally be passed to the module | ||
const options = { | ||
fetch: globalThis.fetch, | ||
urls: { | ||
index: 'https://nodejs.org/dist/index.json' | ||
} | ||
} | ||
index: 'https://nodejs.org/dist/index.json', | ||
}, | ||
}; | ||
|
||
describe('under normal condiditons, versions should work', async () => { | ||
it('should work with default options', async () => { | ||
const data = await versions(options) | ||
check (data) | ||
}) | ||
const data = await versions(options); | ||
check(data); | ||
}); | ||
|
||
it('should work with Undici fetch', async () => { | ||
options.fetch = undiciFetch | ||
const data = await versions(options) | ||
check(data) | ||
}) | ||
}) | ||
options.fetch = undiciFetch; | ||
const data = await versions(options); | ||
check(data); | ||
}); | ||
}); | ||
|
||
describe('versions should work with optionsParser', async () => { | ||
it('should work with the default output of optionsParser', async () => { | ||
const parsedOptions = optionsParser({}) | ||
const data = await versions(parsedOptions) | ||
check(data) | ||
}) | ||
const parsedOptions = optionsParser({}); | ||
const data = await versions(parsedOptions); | ||
check(data); | ||
}); | ||
|
||
it('should work with a different fetch pased to optionsParser', async () => { | ||
const parsedOptions = optionsParser({ | ||
fetch: undiciFetch | ||
}) | ||
const data = await versions(parsedOptions) | ||
check(data) | ||
}) | ||
}) | ||
fetch: undiciFetch, | ||
}); | ||
const data = await versions(parsedOptions); | ||
check(data); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
async function schedule (options) { | ||
async function schedule(options) { | ||
// parse our options and set up fetch if a custom fetch is passed | ||
const fetch = options.fetch; | ||
const url = options.urls.schedule; | ||
|
||
// fetch the url, get the json from the fetched URL that we're going to use | ||
const raw = await fetch(url); | ||
const schedule = await raw.json(); | ||
return schedule | ||
|
||
return schedule; | ||
} | ||
|
||
module.exports = schedule | ||
module.exports = schedule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters