wip tests
This commit is contained in:
parent
fe405cb393
commit
0758105e92
|
|
@ -26,6 +26,10 @@ const PORT = (() => {
|
||||||
const portArg = process.argv.find(arg => arg.startsWith('--port='));
|
const portArg = process.argv.find(arg => arg.startsWith('--port='));
|
||||||
return portArg ? parseInt(portArg.split('=')[1]) : 5023;
|
return portArg ? parseInt(portArg.split('=')[1]) : 5023;
|
||||||
})();
|
})();
|
||||||
|
const FILTER = (() => {
|
||||||
|
const filterArg = process.argv.find(arg => arg.startsWith('--filter='));
|
||||||
|
return filterArg ? filterArg.split('=')[1] : null;
|
||||||
|
})();
|
||||||
const DELAY = 20; // ms between keystrokes
|
const DELAY = 20; // ms between keystrokes
|
||||||
|
|
||||||
// ── State ─────────────────────────────────────────────────────────────────────
|
// ── State ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
@ -169,6 +173,9 @@ function assert(condition, message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function test(name, fn) {
|
async function test(name, fn) {
|
||||||
|
if (FILTER && !name.toLowerCase().includes(FILTER.toLowerCase())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await fn();
|
await fn();
|
||||||
passed++;
|
passed++;
|
||||||
|
|
@ -286,6 +293,60 @@ async function runTests() {
|
||||||
assert(markdown === '***both***', `Expected "***both***", got: "${markdown}"`);
|
assert(markdown === '***both***', `Expected "***both***", got: "${markdown}"`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await test('nested bold and italic are handled correctly', async() => {
|
||||||
|
const NESTED_CASES = [
|
||||||
|
{
|
||||||
|
name: 'close-side ambiguity, outer=bold (bold *italic***)',
|
||||||
|
markdown: '**bold *italic***',
|
||||||
|
outerClass: 'md-bold',
|
||||||
|
innerClass: 'md-italic',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'close-side ambiguity, outer=italic (*italic **bold***)',
|
||||||
|
markdown: '*italic **bold***',
|
||||||
|
outerClass: 'md-italic',
|
||||||
|
innerClass: 'md-bold',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'open-side ambiguity, outer=bold (***italic* bold**)',
|
||||||
|
markdown: '***italic* bold**',
|
||||||
|
outerClass: 'md-bold',
|
||||||
|
innerClass: 'md-italic',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'open-side ambiguity, outer=italic (***bold** italic*)',
|
||||||
|
markdown: '***bold** italic*',
|
||||||
|
outerClass: 'md-italic',
|
||||||
|
innerClass: 'md-bold',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const testCase of NESTED_CASES) {
|
||||||
|
await test(testCase.name, async () => {
|
||||||
|
await resetEditor();
|
||||||
|
await typeString(testCase.markdown);
|
||||||
|
|
||||||
|
const markdown = await getMarkdown();
|
||||||
|
assert(
|
||||||
|
markdown === testCase.markdown,
|
||||||
|
`Round-trip failed.\nExpected: "${testCase.markdown}"\nGot: "${markdown}"`
|
||||||
|
);
|
||||||
|
|
||||||
|
const html = await getHTML();
|
||||||
|
const outerIndex = html.indexOf(testCase.outerClass);
|
||||||
|
const innerIndex = html.indexOf(testCase.innerClass);
|
||||||
|
assert(
|
||||||
|
outerIndex !== -1 && innerIndex !== -1,
|
||||||
|
`Missing expected classes (${testCase.outerClass}, ${testCase.innerClass}) in: ${html}`
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
outerIndex < innerIndex,
|
||||||
|
`Expected ${testCase.outerClass} to wrap (appear before) ${testCase.innerClass} in: ${html}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
await test('`code` produces md-code span', async () => {
|
await test('`code` produces md-code span', async () => {
|
||||||
await resetEditor();
|
await resetEditor();
|
||||||
await typeString('`code`');
|
await typeString('`code`');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user