Files
pplus-web/tests/spdx.test.mjs
T
alexm e092cb029c
Build, test, deploy / site (push) Failing after 15m13s
Initial commit
2026-11-12 22:24:02 -05:00

39 lines
1.9 KiB
JavaScript

// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
// SPDX-License-Identifier: Apache-2.0
// Every source file written here says who holds its copyright and under which license, in two SPDX lines at its
// top, so a file copied out of the repository still says where it came from. Left without them, on purpose:
// the vendored editor's type declarations (src/vendor/), which are other people's files with their own
// notices (THIRD_PARTY.md). A new file fails here until
// it has the lines; this test goes with them if the owner drops the headers.
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
const ROOT = new URL('..', import.meta.url).pathname;
const LEFT_OUT = [/^src\/vendor\//];
const HOLDER = 'SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC';
const LICENSE = 'SPDX-License-Identifier: Apache-2.0';
test('every hand-written source, script and test starts with its SPDX lines', () => {
const files = [];
const walk = (dir) => {
for (const e of fs.readdirSync(path.join(ROOT, dir), { withFileTypes: true })) {
const f = `${dir}/${e.name}`;
if (e.isDirectory()) { if (!['node_modules', '__pycache__'].includes(e.name)) walk(f); }
else if (/\.(ts|js|mjs|py|sh)$/.test(e.name) && !LEFT_OUT.some((r) => r.test(f))) files.push(f);
}
};
for (const d of ['src', 'scripts', 'tests']) walk(d);
assert.ok(files.length > 85, `${files.length} files read`);
const missing = [];
for (const f of files) {
const lines = fs.readFileSync(path.join(ROOT, f), 'utf8').split('\n');
const at = lines[0].startsWith('#!') ? 1 : 0;
const mark = /\.(py|sh)$/.test(f) ? '# ' : '// ';
if (lines[at] !== mark + HOLDER || lines[at + 1] !== mark + LICENSE) missing.push(f);
}
assert.deepEqual(missing, []);
assert.match(fs.readFileSync(path.join(ROOT, 'LICENSE.md'), 'utf8'), /Apache License/);
});