From d49492f1ef8cfba105d17be6a5552682b4540155 Mon Sep 17 00:00:00 2001 From: Sachin Raja Date: Wed, 19 Jan 2022 09:23:32 -0800 Subject: [PATCH] switch from uvu to mocha (#7071) * switch from uvu to mocha * remove unused import * custom min reporter * use constants --- package.json | 6 +-- tests/icons-cjs.test.js | 3 -- tests/icons-esm.test.js | 3 -- tests/index.test.js | 16 +++---- tests/min-reporter.cjs | 12 +++++ tests/readme-icons.test.js | 6 +-- tests/test-icon.js | 91 +++++++++++++++++++------------------- 7 files changed, 68 insertions(+), 69 deletions(-) create mode 100644 tests/min-reporter.cjs diff --git a/package.json b/package.json index 79c4aaaa..1015b666 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "husky": "7.0.4", "is-ci": "3.0.1", "jsonschema": "1.4.0", + "mocha": "9.1.4", "named-html-entities-json": "1.0.0", "npm-run-all": "4.1.5", "prettier": "2.5.1", @@ -45,8 +46,7 @@ "svg-path-segments": "1.0.0", "svglint": "2.0.0", "svgo": "2.8.0", - "svgpath": "2.4.0", - "uvu": "0.5.2" + "svgpath": "2.4.0" }, "scripts": { "build": "node scripts/build/package.js", @@ -61,7 +61,7 @@ "prepare": "is-ci || husky install", "prepublishOnly": "npm run build", "postpublish": "npm run clean", - "test": "uvu", + "test": "mocha tests --reporter tests/min-reporter.cjs --inline-diffs", "pretest": "npm run prepublishOnly", "posttest": "npm run postpublish", "svgo": "svgo --config svgo.config.js", diff --git a/tests/icons-cjs.test.js b/tests/icons-cjs.test.js index 622247d8..7bc2f8fd 100644 --- a/tests/icons-cjs.test.js +++ b/tests/icons-cjs.test.js @@ -1,4 +1,3 @@ -import { exec } from 'uvu'; import { testIcon } from './test-icon.js'; import { getIconSlug, getIconsData } from '../scripts/utils.js'; (async () => { @@ -14,6 +13,4 @@ import { getIconSlug, getIconsData } from '../scripts/utils.js'; }); await Promise.all(tests); - - exec(); })(); diff --git a/tests/icons-esm.test.js b/tests/icons-esm.test.js index 9b914d69..ae2b940c 100644 --- a/tests/icons-esm.test.js +++ b/tests/icons-esm.test.js @@ -5,7 +5,6 @@ import { } from '../scripts/utils.js'; import * as simpleIcons from '../icons.mjs'; import { testIcon } from './test-icon.js'; -import { exec } from 'uvu'; (async () => { const icons = await getIconsData(); @@ -17,6 +16,4 @@ import { exec } from 'uvu'; testIcon(icon, subject, slug); }); - - exec(); })(); diff --git a/tests/index.test.js b/tests/index.test.js index d4ef45cd..c8cc475d 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -1,7 +1,7 @@ import simpleIcons from '../index.js'; import { getIconSlug, getIconsData } from '../scripts/utils.js'; -import { test, exec } from 'uvu'; -import * as assert from 'uvu/assert'; +import { test } from 'mocha'; +import { strict as assert } from 'node:assert'; (async () => { const icons = await getIconsData(); @@ -12,9 +12,9 @@ import * as assert from 'uvu/assert'; test(`'Get' ${icon.title} by its slug`, () => { const found = simpleIcons.Get(slug); assert.ok(found); - assert.is(found.title, icon.title); - assert.is(found.hex, icon.hex); - assert.is(found.source, icon.source); + assert.equal(found.title, icon.title); + assert.equal(found.hex, icon.hex); + assert.equal(found.source, icon.source); }); }); @@ -22,11 +22,7 @@ import * as assert from 'uvu/assert'; const iconArray = Object.values(simpleIcons); for (let icon of iconArray) { assert.ok(icon); - assert.type(icon, 'object'); + assert.equal(typeof icon, 'object'); } }); - - test.run(); - - exec(); })(); diff --git a/tests/min-reporter.cjs b/tests/min-reporter.cjs new file mode 100644 index 00000000..72b840f8 --- /dev/null +++ b/tests/min-reporter.cjs @@ -0,0 +1,12 @@ +const { reporters, Runner } = require('mocha'); + +const { EVENT_RUN_END } = Runner.constants; + +class EvenMoreMin extends reporters.Base { + constructor(runner) { + super(runner); + runner.once(EVENT_RUN_END, () => this.epilogue()); + } +} + +module.exports = EvenMoreMin; diff --git a/tests/readme-icons.test.js b/tests/readme-icons.test.js index 19fcece6..76e8d9ec 100644 --- a/tests/readme-icons.test.js +++ b/tests/readme-icons.test.js @@ -1,8 +1,8 @@ import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; -import { test } from 'uvu'; -import * as assert from 'uvu/assert'; +import { test } from 'mocha'; +import { strict as assert } from 'node:assert'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const root = path.dirname(__dirname); @@ -39,6 +39,4 @@ for (let whiteIconFileName of whiteIconsFileNames) { blackIconContent.replace(' { - const test = suite(icon.title); const svgPath = path.resolve(iconsDir, `${slug}.svg`); - test('has the correct "title"', () => { - assert.is(subject.title, icon.title); - }); + describe(icon.title, () => { + it('has the correct "title"', () => { + assert.equal(subject.title, icon.title); + }); - test('has the correct "slug"', () => { - assert.is(subject.slug, slug); - }); + it('has the correct "slug"', () => { + assert.equal(subject.slug, slug); + }); - test('has the correct "hex" value', () => { - assert.is(subject.hex, icon.hex); - }); + it('has the correct "hex" value', () => { + assert.equal(subject.hex, icon.hex); + }); - test('has the correct "source"', () => { - assert.is(subject.source, icon.source); - }); + it('has the correct "source"', () => { + assert.equal(subject.source, icon.source); + }); - test('has an "svg" value', () => { - assert.type(subject.svg, 'string'); - }); + it('has an "svg" value', () => { + assert.equal(typeof subject.svg, 'string'); + }); - test('has a valid "path" value', () => { - assert.match(subject.path, /^[MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]+$/g); - }); + it('has a valid "path" value', () => { + assert.match(subject.path, /^[MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]+$/g); + }); - test(`has ${icon.guidelines ? 'the correct' : 'no'} "guidelines"`, () => { - if (icon.guidelines) { - assert.is(subject.guidelines, icon.guidelines); - } else { - assert.is(subject.guidelines, undefined); - } - }); - - test(`has ${icon.license ? 'the correct' : 'no'} "license"`, () => { - if (icon.license) { - assert.is(subject.license.type, icon.license.type); - if (icon.license.type === 'custom') { - assert.is(subject.license.url, icon.license.url); + it(`has ${icon.guidelines ? 'the correct' : 'no'} "guidelines"`, () => { + if (icon.guidelines) { + assert.equal(subject.guidelines, icon.guidelines); } else { - assert.match(subject.license.url, /^https?:\/\/[^\s]+$/); + assert.equal(subject.guidelines, undefined); } - } else { - assert.is(subject.license, undefined); - } - }); + }); - test('has a valid svg value', () => { - const svgFileContents = fs - .readFileSync(svgPath, 'utf8') - .replace(/\r?\n/, ''); - assert.is(subject.svg, svgFileContents); - }); + it(`has ${icon.license ? 'the correct' : 'no'} "license"`, () => { + if (icon.license) { + assert.equal(subject.license.type, icon.license.type); + if (icon.license.type === 'custom') { + assert.equal(subject.license.url, icon.license.url); + } else { + assert.match(subject.license.url, /^https?:\/\/[^\s]+$/); + } + } else { + assert.equal(subject.license, undefined); + } + }); - test.run(); + it('has a valid svg value', () => { + const svgFileContents = fs + .readFileSync(svgPath, 'utf8') + .replace(/\r?\n/, ''); + assert.equal(subject.svg, svgFileContents); + }); + }); };