mirror of
https://github.com/simple-icons/simple-icons.git
synced 2024-11-16 00:59:07 +02:00
Switch testing framework from jest to uvu (#6915)
* switch from jest to uvu * remove jest config * convert index.test.js to uvu * use assert.type * Get rid of jest-diff * Remove uneeded splits * remove out.txt * switch to fake-diff
This commit is contained in:
parent
1cbffee407
commit
a14e03cf7a
@ -1,4 +0,0 @@
|
||||
module.exports = {
|
||||
testMatch: ['**/tests/**/*.test.?(m)js'],
|
||||
moduleFileExtensions: ['js', 'mjs', 'json'],
|
||||
};
|
@ -33,10 +33,9 @@
|
||||
"devDependencies": {
|
||||
"editorconfig-checker": "4.0.2",
|
||||
"esbuild": "0.13.15",
|
||||
"fake-diff": "1.0.0",
|
||||
"husky": "7.0.2",
|
||||
"is-ci": "3.0.0",
|
||||
"jest": "27.2.5",
|
||||
"jest-diff": "27.2.5",
|
||||
"jsonschema": "1.4.0",
|
||||
"named-html-entities-json": "1.0.0",
|
||||
"npm-run-all": "4.1.5",
|
||||
@ -46,7 +45,8 @@
|
||||
"svg-path-segments": "1.0.0",
|
||||
"svglint": "1.0.9",
|
||||
"svgo": "2.7.0",
|
||||
"svgpath": "2.3.1"
|
||||
"svgpath": "2.3.1",
|
||||
"uvu": "0.5.2"
|
||||
},
|
||||
"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": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
||||
"test": "node --experimental-specifier-resolution=node node_modules/uvu/bin.js",
|
||||
"pretest": "npm run prepublishOnly",
|
||||
"posttest": "npm run postpublish",
|
||||
"svgo": "svgo --config svgo.config.js",
|
||||
|
@ -8,7 +8,7 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const { diffLinesUnified } = require('jest-diff');
|
||||
const fakeDiff = require('fake-diff');
|
||||
|
||||
const UTF8 = 'utf8';
|
||||
|
||||
@ -58,15 +58,7 @@ const TESTS = {
|
||||
const dataString = fs.readFileSync(dataFile, UTF8).replace(/\r\n/g, '\n');
|
||||
const dataPretty = `${JSON.stringify(data, null, ' ')}\n`;
|
||||
if (dataString !== dataPretty) {
|
||||
const dataDiff = diffLinesUnified(
|
||||
dataString.split('\n'),
|
||||
dataPretty.split('\n'),
|
||||
{
|
||||
expand: false,
|
||||
omitAnnotationLines: true,
|
||||
},
|
||||
);
|
||||
|
||||
const dataDiff = fakeDiff(dataString, dataPretty);
|
||||
return `Data file is formatted incorrectly:\n\n${dataDiff}`;
|
||||
}
|
||||
},
|
||||
|
@ -1,23 +1,27 @@
|
||||
const { icons } = require('../_data/simple-icons.json');
|
||||
const simpleIcons = require('../index.js');
|
||||
const { getIconSlug } = require('../scripts/utils');
|
||||
const { test } = require('uvu');
|
||||
const assert = require('uvu/assert');
|
||||
|
||||
icons.forEach((icon) => {
|
||||
const slug = getIconSlug(icon);
|
||||
|
||||
test(`'Get' ${icon.title} by its slug`, () => {
|
||||
const found = simpleIcons.Get(slug);
|
||||
expect(found).toBeDefined();
|
||||
expect(found.title).toEqual(icon.title);
|
||||
expect(found.hex).toEqual(icon.hex);
|
||||
expect(found.source).toEqual(icon.source);
|
||||
assert.ok(found);
|
||||
assert.is(found.title, icon.title);
|
||||
assert.is(found.hex, icon.hex);
|
||||
assert.is(found.source, icon.source);
|
||||
});
|
||||
});
|
||||
|
||||
test(`Iterating over simpleIcons only exposes icons`, () => {
|
||||
const iconArray = Object.values(simpleIcons);
|
||||
for (let icon of iconArray) {
|
||||
expect(icon).toBeDefined();
|
||||
expect(typeof icon).toBe('object');
|
||||
assert.ok(icon);
|
||||
assert.type(icon, 'object');
|
||||
}
|
||||
});
|
||||
|
||||
test.run();
|
||||
|
@ -2,6 +2,8 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const iconsDir = path.resolve(process.cwd(), 'icons');
|
||||
const { suite } = require('uvu');
|
||||
const assert = require('uvu/assert');
|
||||
|
||||
/**
|
||||
* Checks if icon data matches a subject icon.
|
||||
@ -10,64 +12,66 @@ const iconsDir = path.resolve(process.cwd(), 'icons');
|
||||
* @param {String} slug Icon data slug
|
||||
*/
|
||||
const testIcon = (icon, subject, slug) => {
|
||||
describe(icon.title, () => {
|
||||
const svgPath = path.resolve(iconsDir, `${slug}.svg`);
|
||||
const test = suite(icon.title);
|
||||
const svgPath = path.resolve(iconsDir, `${slug}.svg`);
|
||||
|
||||
it('has the correct "title"', () => {
|
||||
expect(subject.title).toStrictEqual(icon.title);
|
||||
});
|
||||
|
||||
it('has the correct "slug"', () => {
|
||||
expect(subject.slug).toStrictEqual(slug);
|
||||
});
|
||||
|
||||
it('has the correct "hex" value', () => {
|
||||
expect(subject.hex).toStrictEqual(icon.hex);
|
||||
});
|
||||
|
||||
it('has the correct "source"', () => {
|
||||
expect(subject.source).toStrictEqual(icon.source);
|
||||
});
|
||||
|
||||
it('has an "svg" value', () => {
|
||||
expect(typeof subject.svg).toBe('string');
|
||||
});
|
||||
|
||||
it('has a valid "path" value', () => {
|
||||
expect(subject.path).toMatch(/^[MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]+$/g);
|
||||
});
|
||||
|
||||
it(`has ${icon.guidelines ? 'the correct' : 'no'} "guidelines"`, () => {
|
||||
if (icon.guidelines) {
|
||||
expect(subject.guidelines).toStrictEqual(icon.guidelines);
|
||||
} else {
|
||||
expect(subject.guidelines).toBeUndefined();
|
||||
}
|
||||
});
|
||||
|
||||
it(`has ${icon.license ? 'the correct' : 'no'} "license"`, () => {
|
||||
if (icon.license) {
|
||||
expect(subject.license).toHaveProperty('type', icon.license.type);
|
||||
if (icon.license.type === 'custom') {
|
||||
expect(subject.license).toHaveProperty('url', icon.license.url);
|
||||
} else {
|
||||
expect(subject.license.url).toMatch(/^https?:\/\/[^\s]+$/);
|
||||
}
|
||||
} else {
|
||||
expect(subject.license).toBeUndefined();
|
||||
}
|
||||
});
|
||||
|
||||
it('has a valid svg value', () => {
|
||||
const svgFileContents = fs
|
||||
.readFileSync(svgPath, 'utf8')
|
||||
.replace(/\r?\n/, '');
|
||||
|
||||
expect(subject.svg.substring(subject.svg.indexOf('<title>'))).toEqual(
|
||||
svgFileContents.substring(svgFileContents.indexOf('<title>')),
|
||||
);
|
||||
});
|
||||
test('has the correct "title"', () => {
|
||||
assert.is(subject.title, icon.title);
|
||||
});
|
||||
|
||||
test('has the correct "slug"', () => {
|
||||
assert.is(subject.slug, slug);
|
||||
});
|
||||
|
||||
test('has the correct "hex" value', () => {
|
||||
assert.is(subject.hex, icon.hex);
|
||||
});
|
||||
|
||||
test('has the correct "source"', () => {
|
||||
assert.is(subject.source, icon.source);
|
||||
});
|
||||
|
||||
test('has an "svg" value', () => {
|
||||
assert.type(subject.svg, 'string');
|
||||
});
|
||||
|
||||
test('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);
|
||||
} else {
|
||||
assert.match(subject.license.url, /^https?:\/\/[^\s]+$/);
|
||||
}
|
||||
} 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.substring(subject.svg.indexOf('<title>')),
|
||||
svgFileContents.substring(svgFileContents.indexOf('<title>')),
|
||||
);
|
||||
});
|
||||
|
||||
test.run();
|
||||
};
|
||||
|
||||
module.exports = testIcon;
|
||||
|
Loading…
Reference in New Issue
Block a user