Skip to content

Commit

Permalink
Bump reqired node to 18, swap tap for node:test
Browse files Browse the repository at this point in the history
Node's built-in test runner works great!
  • Loading branch information
bhousel committed Dec 21, 2023
1 parent 594fdef commit 9042fe0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [16.14, 18, 20]
node-version: [18, 20]

steps:
- uses: actions/checkout@v3
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"dist:files": "node scripts/dist_files.js",
"icons": "node scripts/build_icons.js",
"lint": "eslint scripts/*.js lib/*.js tests/*.js",
"tap": "c8 tap --reporter terse --no-cov tests/*.js",
"test": "run-s build tap",
"test": "run-s build test:node",
"test:node": "c8 node --test tests/*.js",
"stats": "node scripts/stats.js",
"txpull": "tx pull -a",
"txpush": "tx push -s",
Expand Down Expand Up @@ -77,13 +77,12 @@
"jsonschema": "^1.4.1",
"locale-compare": "^2.0.0",
"npm-run-all": "^4.1.5",
"shelljs": "^0.8.5",
"tap": "^16.3.10"
"shelljs": "^0.8.5"
},
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=16.14.0"
"node": ">=18"
}
}
83 changes: 39 additions & 44 deletions tests/resolve_strings.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test } from 'tap';
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { resolveStrings } from '../index.mjs';

const item = {
Expand All @@ -25,28 +26,27 @@ const defaults = {
};


test('resolveStrings', t => {
test('resolveStrings', async t => {

t.test('basic', t => {
await t.test('basic', t => {
const resolved = resolveStrings(item, defaults);
t.type(resolved, 'object');

t.equal(resolved.name, 'Override Name');
t.equal(resolved.url, 'https://lists.openstreetmap.org/listinfo/talk-ru');
t.equal(resolved.signupUrl, undefined);
t.equal(resolved.description, 'The official mailing list for OpenStreetMap Russia');
t.equal(resolved.extendedDescription, 'Fun times for all at https://lists.openstreetmap.org/listinfo/talk-ru');

t.equal(resolved.nameHTML, '<a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">Override Name</a>');
t.equal(resolved.urlHTML, '<a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">https://lists.openstreetmap.org/listinfo/talk-ru</a>');
t.equal(resolved.signupUrlHTML, undefined);
t.equal(resolved.descriptionHTML, 'The official mailing list for OpenStreetMap Russia');
t.equal(resolved.extendedDescriptionHTML, 'Fun times for all at <a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">https://lists.openstreetmap.org/listinfo/talk-ru</a>');
t.end();
assert.equal(typeof resolved, 'object');

assert.equal(resolved.name, 'Override Name');
assert.equal(resolved.url, 'https://lists.openstreetmap.org/listinfo/talk-ru');
assert.equal(resolved.signupUrl, undefined);
assert.equal(resolved.description, 'The official mailing list for OpenStreetMap Russia');
assert.equal(resolved.extendedDescription, 'Fun times for all at https://lists.openstreetmap.org/listinfo/talk-ru');

assert.equal(resolved.nameHTML, '<a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">Override Name</a>');
assert.equal(resolved.urlHTML, '<a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">https://lists.openstreetmap.org/listinfo/talk-ru</a>');
assert.equal(resolved.signupUrlHTML, undefined);
assert.equal(resolved.descriptionHTML, 'The official mailing list for OpenStreetMap Russia');
assert.equal(resolved.extendedDescriptionHTML, 'Fun times for all at <a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">https://lists.openstreetmap.org/listinfo/talk-ru</a>');
});


t.test('localized', t => {
await t.test('localized', t => {
const stringids = {
'talk-ru.name': 'переопределить имя',
'_communities.openstreetmaprussia': 'OpenStreetMap Россия',
Expand All @@ -57,37 +57,35 @@ test('resolveStrings', t => {
const localizer = (id) => stringids[id];

const resolved = resolveStrings(item, defaults, localizer);
t.type(resolved, 'object');

t.equal(resolved.name, 'переопределить имя');
t.equal(resolved.url, 'https://lists.openstreetmap.org/listinfo/talk-ru');
t.equal(resolved.signupUrl, undefined);
t.equal(resolved.description, 'Официальный список рассылки для OpenStreetMap Россия');
t.equal(resolved.extendedDescription, 'Время развлечений для всех на https://lists.openstreetmap.org/listinfo/talk-ru');

t.equal(resolved.nameHTML, '<a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">переопределить имя</a>');
t.equal(resolved.urlHTML, '<a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">https://lists.openstreetmap.org/listinfo/talk-ru</a>');
t.equal(resolved.signupUrlHTML, undefined);
t.equal(resolved.descriptionHTML, 'Официальный список рассылки для OpenStreetMap Россия');
t.equal(resolved.extendedDescriptionHTML, 'Время развлечений для всех на <a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">https://lists.openstreetmap.org/listinfo/talk-ru</a>');
t.end();
assert.equal(typeof resolved, 'object');

assert.equal(resolved.name, 'переопределить имя');
assert.equal(resolved.url, 'https://lists.openstreetmap.org/listinfo/talk-ru');
assert.equal(resolved.signupUrl, undefined);
assert.equal(resolved.description, 'Официальный список рассылки для OpenStreetMap Россия');
assert.equal(resolved.extendedDescription, 'Время развлечений для всех на https://lists.openstreetmap.org/listinfo/talk-ru');

assert.equal(resolved.nameHTML, '<a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">переопределить имя</a>');
assert.equal(resolved.urlHTML, '<a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">https://lists.openstreetmap.org/listinfo/talk-ru</a>');
assert.equal(resolved.signupUrlHTML, undefined);
assert.equal(resolved.descriptionHTML, 'Официальный список рассылки для OpenStreetMap Россия');
assert.equal(resolved.extendedDescriptionHTML, 'Время развлечений для всех на <a target="_blank" href="https://lists.openstreetmap.org/listinfo/talk-ru">https://lists.openstreetmap.org/listinfo/talk-ru</a>');
});


t.test('Throws if an expected replacement token cannot be resolved', t => {
await t.test('Throws if an expected replacement token cannot be resolved', t => {
const missing = {
id: 'talk-ru',
type: 'mailinglist',
// account: 'talk-ru', // missing account!
strings: { community: 'OpenStreetMap Russia' }
};

t.throws(() => resolveStrings(missing, defaults), /cannot resolve token:/i);
t.end();
assert.throws(() => resolveStrings(missing, defaults), /cannot resolve token:/i);
});


t.test('Throws if any extra replacement tokens remain unresolved', t => {
await t.test('Throws if any extra replacement tokens remain unresolved', t => {
const extra = {
id: 'talk-ru',
type: 'mailinglist',
Expand All @@ -98,12 +96,11 @@ test('resolveStrings', t => {
}
};

t.throws(() => resolveStrings(extra, defaults), /cannot resolve tokens:/i);
t.end();
assert.throws(() => resolveStrings(extra, defaults), /cannot resolve tokens:/i);
});


t.test('Linkify subreddits in description, extendedDescription', t => {
await t.test('Linkify subreddits in description, extendedDescription', t => {
const subreddit = {
id: 'OSM-Reddit',
type: 'reddit',
Expand All @@ -116,11 +113,9 @@ test('resolveStrings', t => {
};

const resolved = resolveStrings(subreddit, defaults);
t.type(resolved, 'object');
t.equal(resolved.descriptionHTML, '<a target="_blank" href="https://www.reddit.com/r/openstreetmap">/r/openstreetmap</a> is a great place to learn more about OpenStreetMap.');
t.equal(resolved.extendedDescriptionHTML, 'Fun times for all at <a target="_blank" href="https://www.reddit.com/r/openstreetmap">/r/openstreetmap</a>');
t.end();
assert.equal(typeof resolved, 'object');
assert.equal(resolved.descriptionHTML, '<a target="_blank" href="https://www.reddit.com/r/openstreetmap">/r/openstreetmap</a> is a great place to learn more about OpenStreetMap.');
assert.equal(resolved.extendedDescriptionHTML, 'Fun times for all at <a target="_blank" href="https://www.reddit.com/r/openstreetmap">/r/openstreetmap</a>');
});

t.end();
});
68 changes: 29 additions & 39 deletions tests/simplify.test.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,53 @@
import { test } from 'tap';
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { simplify } from '../index.mjs';

test('simplify', t => {
test('simplify', async t => {

t.test('lowercases', t => {
t.equal(simplify('Aldo'), 'aldo');
t.end();
await t.test('lowercases', t => {
assert.equal(simplify('Aldo'), 'aldo');
});

t.test('replaces diacritics', t => {
t.equal(simplify('André'), 'andre');
t.end();
await t.test('replaces diacritics', t => {
assert.equal(simplify('André'), 'andre');
});

t.test('removes spaces', t => {
t.equal(simplify('Jimmy Choo'), 'jimmychoo');
t.end();
await t.test('removes spaces', t => {
assert.equal(simplify('Jimmy Choo'), 'jimmychoo');
});

t.test('removes various dashes', t => {
t.equal(simplify('PTV - Metropolitan'), 'ptvmetropolitan'); // hypen
t.equal(simplify('PTV – Metropolitan'), 'ptvmetropolitan'); // en dash (U+2013)
t.equal(simplify('PTV — Metropolitan'), 'ptvmetropolitan'); // em dash (U+2014)
t.equal(simplify('PTV ― Metropolitan'), 'ptvmetropolitan'); // horizontal bar (U+2015)
t.end();
await t.test('removes various dashes', t => {
assert.equal(simplify('PTV - Metropolitan'), 'ptvmetropolitan'); // hypen
assert.equal(simplify('PTV – Metropolitan'), 'ptvmetropolitan'); // en dash (U+2013)
assert.equal(simplify('PTV — Metropolitan'), 'ptvmetropolitan'); // em dash (U+2014)
assert.equal(simplify('PTV ― Metropolitan'), 'ptvmetropolitan'); // horizontal bar (U+2015)
});

t.test('removes unprintable unicode (like RTL/LTR marks, zero width space, zero width nonjoiner)', t => {
t.equal(simplify('\u200FJim\u200Bmy\u200CChoo\u200E'), 'jimmychoo');
t.end();
await t.test('removes unprintable unicode (like RTL/LTR marks, zero width space, zero width nonjoiner)', t => {
assert.equal(simplify('\u200FJim\u200Bmy\u200CChoo\u200E'), 'jimmychoo');
});

t.test('removes punctuation', t => {
t.equal(simplify('K+K Schuh-Center'), 'kkschuhcenter');
t.end();
await t.test('removes punctuation', t => {
assert.equal(simplify('K+K Schuh-Center'), 'kkschuhcenter');
});

t.test('replaces & with and', t => {
t.equal(simplify('Johnston & Murphy'), 'johnstonandmurphy');
t.end();
await t.test('replaces & with and', t => {
assert.equal(simplify('Johnston & Murphy'), 'johnstonandmurphy');
});

t.test('replaces ß (eszett) with ss', t => {
t.equal(simplify('Beßon'), 'besson');
t.end();
await t.test('replaces ß (eszett) with ss', t => {
assert.equal(simplify('Beßon'), 'besson');
});

t.test('replaces İ (0130) or i̇ (0069 0307) with i', t => { // #5017, #8261 for examples
t.equal(simplify('İnşaat'), 'insaat');
t.equal(simplify('i̇nşaat'), 'insaat');
t.end();
await t.test('replaces İ (0130) or i̇ (0069 0307) with i', t => { // #5017, #8261 for examples
assert.equal(simplify('İnşaat'), 'insaat');
assert.equal(simplify('i̇nşaat'), 'insaat');
});

t.test('returns empty string if no input', t => {
t.equal(simplify(), '');
t.equal(simplify(null), '');
t.equal(simplify({}), '');
t.end();
await t.test('returns empty string if no input', t => {
assert.equal(simplify(), '');
assert.equal(simplify(null), '');
assert.equal(simplify({}), '');
});

t.end();
});

0 comments on commit 9042fe0

Please sign in to comment.