1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-11-26 01:00:27 +02:00

Fix some cases in README icons tests (#7056)

* Fix some cases in README icons tests

* Improve error message

* Declarate with `const` all variables
This commit is contained in:
Álvaro Mondéjar 2022-01-15 23:27:42 +01:00 committed by GitHub
parent 31b590019f
commit 8faa5b63bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,34 +1,44 @@
import { promises as fs } from 'node:fs';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { test, exec } from 'uvu';
import { test } from 'uvu';
import * as assert from 'uvu/assert';
(async () => {
const __dirname = path.dirname(fileURLToPath(import.meta.url)),
root = path.dirname(__dirname),
darkIconsPath = path.join(root, 'icons'),
lightIconsPath = path.join(root, 'assets', 'readme'),
lightIconsFileNames = await fs.readdir(lightIconsPath);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const root = path.dirname(__dirname);
const blackIconsPath = path.join(root, 'icons');
const whiteIconsPath = path.join(root, 'assets', 'readme');
const whiteIconsFileNames = fs.readdirSync(whiteIconsPath);
for (let lightIconFileName of lightIconsFileNames) {
const lightIconPath = path.join(lightIconsPath, lightIconFileName),
darkIconPath = path.join(
darkIconsPath,
lightIconFileName.replace(/-white\.svg$/, '.svg'),
),
lightIconRelPath = path.relative(root, lightIconPath),
darkIconRelPath = path.relative(root, darkIconPath),
lightIconContent = await fs.readFile(lightIconPath, 'utf8'),
darkIconContent = await fs.readFile(darkIconPath, 'utf8');
for (let whiteIconFileName of whiteIconsFileNames) {
const whiteIconPath = path.join(whiteIconsPath, whiteIconFileName);
const blackIconPath = path.join(
blackIconsPath,
whiteIconFileName.replace(/-white\.svg$/, '.svg'),
);
const whiteIconRelPath = path.relative(root, whiteIconPath);
const blackIconRelPath = path.relative(root, blackIconPath);
test(`'${whiteIconRelPath}' content must be equivalent to '${blackIconRelPath}' content`, () => {
assert.ok(
whiteIconFileName.endsWith('-white.svg'),
`README icon assets file name '${whiteIconFileName}'` +
" must ends with '-white.svg'.",
);
assert.ok(
fs.existsSync(blackIconPath),
`Corresponding icon '${blackIconRelPath}' for README asset '${whiteIconRelPath}'` +
` not found in '${path.dirname(blackIconRelPath)}' directory.`,
);
const whiteIconContent = fs.readFileSync(whiteIconPath, 'utf8');
const blackIconContent = fs.readFileSync(blackIconPath, 'utf8');
assert.equal(
whiteIconContent,
blackIconContent.replace('<svg', '<svg fill="white"'),
);
});
test(`'${lightIconRelPath}' content must be equivalent to '${darkIconRelPath}' content`, () => {
assert.equal(
lightIconContent.replace(' fill="white"', ''),
darkIconContent,
);
});
}
test.run();
exec();
})();
}