mirror of
https://github.com/Mibew/simple-icons.git
synced 2025-04-07 21:30:16 +03: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:
parent
31b590019f
commit
8faa5b63bb
@ -1,34 +1,44 @@
|
|||||||
import { promises as fs } from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { test, exec } from 'uvu';
|
import { test } from 'uvu';
|
||||||
import * as assert from 'uvu/assert';
|
import * as assert from 'uvu/assert';
|
||||||
|
|
||||||
(async () => {
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url)),
|
const root = path.dirname(__dirname);
|
||||||
root = path.dirname(__dirname),
|
const blackIconsPath = path.join(root, 'icons');
|
||||||
darkIconsPath = path.join(root, 'icons'),
|
const whiteIconsPath = path.join(root, 'assets', 'readme');
|
||||||
lightIconsPath = path.join(root, 'assets', 'readme'),
|
const whiteIconsFileNames = fs.readdirSync(whiteIconsPath);
|
||||||
lightIconsFileNames = await fs.readdir(lightIconsPath);
|
|
||||||
|
|
||||||
for (let lightIconFileName of lightIconsFileNames) {
|
for (let whiteIconFileName of whiteIconsFileNames) {
|
||||||
const lightIconPath = path.join(lightIconsPath, lightIconFileName),
|
const whiteIconPath = path.join(whiteIconsPath, whiteIconFileName);
|
||||||
darkIconPath = path.join(
|
const blackIconPath = path.join(
|
||||||
darkIconsPath,
|
blackIconsPath,
|
||||||
lightIconFileName.replace(/-white\.svg$/, '.svg'),
|
whiteIconFileName.replace(/-white\.svg$/, '.svg'),
|
||||||
),
|
);
|
||||||
lightIconRelPath = path.relative(root, lightIconPath),
|
const whiteIconRelPath = path.relative(root, whiteIconPath);
|
||||||
darkIconRelPath = path.relative(root, darkIconPath),
|
const blackIconRelPath = path.relative(root, blackIconPath);
|
||||||
lightIconContent = await fs.readFile(lightIconPath, 'utf8'),
|
|
||||||
darkIconContent = await fs.readFile(darkIconPath, 'utf8');
|
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();
|
test.run();
|
||||||
exec();
|
}
|
||||||
})();
|
|
||||||
|
Loading…
Reference in New Issue
Block a user