Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .github/workflows/tests-translate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
paths:
- 'translate/**'
- 'ranges/**'
- 'core/**'
- 'aliases/**'
branches:
- main
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion translate/examples/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const translate = require('../index'); // would normally be "const translate = r

async function getTranslatedData() {
// translation for the 'current' Package Support term
const translatedCurrent = await ranges('current');
const translatedCurrent = await ranges(await translate('current'));

// translation for the 'lts_latest' Package Support term
const translatedLtsLatest = await ranges(await translate('lts_latest'));
Expand Down
2 changes: 1 addition & 1 deletion translate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@nodevu/ranges": "^0.1.0",
"@nodevu/ranges": "^1.0.0",
"c8": "^10.1.2"
},
"engines": {
Expand Down
43 changes: 24 additions & 19 deletions translate/test/ranges.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,53 @@ const assert = require('node:assert');
const translate = require('../index');
const ranges = require('@nodevu/ranges');
const { describe, it } = require('node:test');
const { at } = require('../../ranges/test/fixtures');

// serve core's snapshot data at a fixed date so results don't depend on
// nodejs.org or today's date
const options = at();

describe('test that each alias works with @nodevu/ranges', async () => {
it('should return the same result when both the translated and untranslated "current" are passed to @nodevu/ranges', async () => {
const untranslated = await ranges('current');
const translated = await ranges(await translate('current'));
const untranslated = await ranges('current', options);
const translated = await ranges(await translate('current'), options);

assert.deepStrictEqual(untranslated, translated);
});

it('should return the same result when "lts/latest" and the translated "lts_latest" are passed to @nodevu/ranges', async () => {
const untranslated = await ranges('lts/latest');
const translated = await ranges(await translate('lts_latest'));
const untranslated = await ranges('lts/latest', options);
const translated = await ranges(await translate('lts_latest'), options);

assert.deepStrictEqual(untranslated, translated);
});

it('should return the same result when "lts/active" and "lts/maintenance" and the translated "lts" are passed to @nodevu/ranges', async () => {
const untranslated = await ranges(['lts/active', 'lts/maintenance']);
const translated = await ranges(await translate('lts'));
const untranslated = await ranges(
['lts/active', 'lts/maintenance'],
options,
);
const translated = await ranges(await translate('lts'), options);

assert.deepStrictEqual(untranslated, translated);
});

it('should return the same result when "current", "lts/active", and "lts/maintenance" and the translated "supported" are passed to @nodevu/ranges', async () => {
const untranslated = await ranges([
'current',
'lts/active',
'lts/maintenance',
]);
const translated = await ranges(await translate('supported'));
const untranslated = await ranges(
['current', 'lts/active', 'lts/maintenance'],
options,
);
const translated = await ranges(await translate('supported'), options);

assert.deepStrictEqual(untranslated, translated);
});

it('should return the same result when "current", "lts/active", "lts/maintenance", and "eol" and the translated "all" are passed to @nodevu/ranges', async () => {
const untranslated = await ranges([
'current',
'lts/active',
'lts/maintenance',
'eol',
]);
const translated = await ranges(await translate('all'));
const untranslated = await ranges(
['current', 'lts/active', 'lts/maintenance', 'eol'],
options,
);
const translated = await ranges(await translate('all'), options);

assert.deepStrictEqual(untranslated, translated);
});
Expand Down
11 changes: 11 additions & 0 deletions translate/test/unknown.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const assert = require('node:assert');
const translate = require('../index');
const { describe, it } = require('node:test');

describe('test that translating an unknown value fails', async () => {
it('should throw when passed a value that is not a Package Support term', async () => {
await assert.rejects(translate('lts/latest'), {
message: 'Unknown value: lts/latest',
});
});
});
Loading