seconf
This commit is contained in:
1 parent
ae2c99d71a
commit
846054b7b9
25 files changed
+2513
-148
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { compileContent, validateProjects } from '../scripts/content.mjs';
|
||||
import { projects, processes } from '../content.js';
|
||||
import { profile, source } from '../content.js';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
|
||||
test('content compiler preserves source data', async () => {
|
||||
const result = await import(`data:text/javascript;base64,${Buffer.from(await compileContent()).toString('base64')}`);
|
||||
assert.deepEqual(result.projects, projects);
|
||||
});
|
||||
test('deleting all projects or evidence is supported', () => {
|
||||
assert.doesNotThrow(() => validateProjects([], processes));
|
||||
assert.doesNotThrow(() => validateProjects(projects.map(p => ({ ...p, evidence: [] })), processes));
|
||||
});
|
||||
test('invalid routes, translations and mappings are rejected', () => {
|
||||
for (const change of [{ id: '../invalid' }, { name: ['Only one language'] }, { codes: ['unknown'] }, { nodes: [] }]) {
|
||||
assert.throws(() => validateProjects([{ ...projects[0], ...change }], processes));
|
||||
}
|
||||
assert.throws(() => validateProjects([projects[0], projects[0]], processes));
|
||||
});
|
||||
|
||||
test('homepage renders after removing the featured project or all projects', async () => {
|
||||
const code = (await readFile(new URL('../app.js', import.meta.url), 'utf8')).replace(/^import .*;\r?\n/, '');
|
||||
for (const remaining of [projects.slice(1), []]) {
|
||||
const elements = new Map();
|
||||
const document = {
|
||||
documentElement: {},
|
||||
querySelector(selector) {
|
||||
if (!elements.has(selector)) elements.set(selector, { innerHTML: '', addEventListener() {} });
|
||||
return elements.get(selector);
|
||||
},
|
||||
querySelectorAll() { return []; },
|
||||
};
|
||||
runInNewContext(code, { profile, source, projects: remaining, processes, document, URLSearchParams, location: { search: '?lang=en', hash: '#home' }, window: { addEventListener() {} } });
|
||||
const html = elements.get('main').innerHTML;
|
||||
assert.ok(!html.includes('undefined'));
|
||||
assert.ok(!html.includes('href="#project/warehouse"'));
|
||||
if (remaining.length) assert.ok(html.includes(`href="#project/${remaining[0].id}"`));
|
||||
else assert.ok(html.includes('No projects added yet.'));
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user