1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-11-16 00:59:07 +02:00
simple-icons/tests
Sachin Raja 665b82590d
remove icons/* entrypoints (#6788)
* remove icons/* entrypoints

* remove icons/* tests

* remove icons/* references from the README

* reference actual variable in README console.log

* merge develop

* fix conflicts

* fix

* fix tests

* Update scripts/build/package.js

* Update README.md

* fix ignore files
2022-05-26 14:29:37 +02:00
..
icons.test.js remove icons/* entrypoints (#6788) 2022-05-26 14:29:37 +02:00
index.test.js Avoid certain cases for data consistency (#7222) 2022-03-14 21:04:50 +01:00
min-reporter.cjs switch from uvu to mocha (#7071) 2022-01-19 18:23:32 +01:00
package.json convert scripts to esm (#6946) 2021-12-25 06:22:56 -08:00
readme.test.js Allow to use the function getThirdPartyExtensions at other locations (#7361) 2022-04-30 07:04:46 -07:00
test-icon.js switch from uvu to mocha (#7071) 2022-01-19 18:23:32 +01:00

import fs from 'node:fs';
import path from 'node:path';
import { describe, test } from 'mocha';
import { strict as assert } from 'node:assert';
import {
  getThirdPartyExtensions,
  getDirnameFromImportMeta,
} from '../scripts/utils.js';

const __dirname = getDirnameFromImportMeta(import.meta.url);
const root = path.dirname(__dirname);

describe('README icons assets must be consistent with Github themes', () => {
  const blackIconsPath = path.join(root, 'icons');
  const whiteIconsPath = path.join(root, 'assets', 'readme');
  const whiteIconsFileNames = fs.readdirSync(whiteIconsPath);

  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('README third party extensions must be alphabetically sorted', async () => {
  const readmePath = path.join(root, 'README.md');
  const thirdPartyExtensions = await getThirdPartyExtensions(readmePath);
  assert.ok(thirdPartyExtensions.length > 0);

  const thirdPartyExtensionsNames = thirdPartyExtensions.map(
    (ext) => ext.module.name,
  );

  const expectedOrder = thirdPartyExtensionsNames.slice().sort();
  assert.deepEqual(
    thirdPartyExtensionsNames,
    expectedOrder,
    'Wrong alphabetical order of third party extensions in README.',
  );
});