2022-01-31 01:09:44 +03:00
|
|
|
import fs from 'node:fs';
|
|
|
|
import path from 'node:path';
|
|
|
|
import { describe, test } from 'mocha';
|
|
|
|
import { strict as assert } from 'node:assert';
|
2023-04-19 16:23:13 +03:00
|
|
|
import { getThirdPartyExtensions, getDirnameFromImportMeta } from '../sdk.mjs';
|
2022-01-31 01:09:44 +03:00
|
|
|
|
|
|
|
const __dirname = getDirnameFromImportMeta(import.meta.url);
|
|
|
|
const root = path.dirname(__dirname);
|
|
|
|
|
|
|
|
test('README third party extensions must be alphabetically sorted', async () => {
|
2022-04-30 17:04:46 +03:00
|
|
|
const readmePath = path.join(root, 'README.md');
|
|
|
|
const thirdPartyExtensions = await getThirdPartyExtensions(readmePath);
|
2022-01-31 01:09:44 +03:00
|
|
|
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.',
|
|
|
|
);
|
|
|
|
});
|
2022-09-24 18:37:03 +03:00
|
|
|
|
|
|
|
test('Only allow HTTPS links in documentation pages', async () => {
|
|
|
|
const ignoreHttpLinks = ['http://www.w3.org/2000/svg'];
|
|
|
|
|
|
|
|
const docsFiles = fs
|
|
|
|
.readdirSync(root)
|
|
|
|
.filter((fname) => fname.endsWith('.md'));
|
|
|
|
|
|
|
|
const linksGetter = new RegExp('http://[^\\s"\']+', 'g');
|
|
|
|
for (let docsFile of docsFiles) {
|
|
|
|
const docsFilePath = path.join(root, docsFile);
|
|
|
|
const docsFileContent = fs.readFileSync(docsFilePath, 'utf8');
|
|
|
|
|
|
|
|
Array.from(docsFileContent.matchAll(linksGetter)).forEach((match) => {
|
|
|
|
const link = match[0];
|
|
|
|
assert.ok(
|
|
|
|
ignoreHttpLinks.includes(link) || link.startsWith('https://'),
|
|
|
|
`Link '${link}' in '${docsFile}' (at index ${match.index})` +
|
|
|
|
` must use the HTTPS protocol.`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|