From b45288b1cfc2e66dd63f1e708fd96dd549962ffc Mon Sep 17 00:00:00 2001 From: ochafik Date: Wed, 25 Dec 2024 12:00:39 +0000 Subject: [PATCH] Normalize CRLF to \n and test customizer in e2e test --- src/utils.ts | 2 +- tests/e2e.test.js | 48 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 9d99090..d587153 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -157,7 +157,7 @@ export async function fetchSource({content, path, url}: Source) { } else if (url) { if (path.endsWith('.scad') || path.endsWith('.json')) { content = await (await fetch(url)).text(); - return content; + return content.replace(/\r\n/g, '\n'); } else { // Fetch bytes const response = await fetch(url); diff --git a/tests/e2e.test.js b/tests/e2e.test.js index ec9707c..160612b 100644 --- a/tests/e2e.test.js +++ b/tests/e2e.test.js @@ -45,18 +45,43 @@ function expectMessage(messages, line) { const successMessage = messages.filter(msg => msg.type === 'debug' && msg.text === line); expect(successMessage).toHaveLength(1); } +function expectObjectList() { + expectMessage(messages, 'stderr: Top level object is a list of objects:'); +} +function expect3DPolySet() { + expectMessage(messages, 'stderr: Top level object is a 3D object (PolySet):'); +} +function expect3DManifold() { + expectMessage(messages, 'stderr: Top level object is a 3D object (manifold):'); +} +function waitForCustomizeButton() { + return page.waitForFunction(() => { + const buttons = document.querySelectorAll('input[role=switch]'); + for (const button of buttons) { + if (button.parentElement.innerText === 'Customize') { + return button; + } + } + }); +} +function waitForLabel(text) { + return page.waitForFunction((text) => { + return Array.from(document.querySelectorAll('label')).find(el => el.textContent === 'myVar'); + // return Array.from(document.querySelectorAll('label')).find(el => el.textContent === text); + }, {}, text); +} describe('e2e', () => { test('load the default page', async () => { await page.goto(url); await waitForViewer(); - expectMessage(messages, 'stderr: Top level object is a list of objects:'); + expectOjbectList(); }, longTimeout); test('can render cube', async () => { await loadSrc('cube([10, 10, 10]);'); await waitForViewer(); - expectMessage(messages, 'stderr: Top level object is a 3D object (PolySet):'); + expect3DPolySet(); }, longTimeout); test('use BOSL2', async () => { @@ -65,7 +90,7 @@ describe('e2e', () => { prismoid([40,40], [0,0], h=20); `); await waitForViewer(); - expectMessage(messages, 'stderr: Top level object is a 3D object (PolySet):'); + expect3DManifold(); }, longTimeout); test('use NopSCADlib', async () => { @@ -74,6 +99,21 @@ describe('e2e', () => { meter(led_meter); `); await waitForViewer(); - expectMessage(messages, 'stderr: Top level object is a 3D object (manifold):'); + expect3DManifold(); + }, longTimeout); + + test('customizer & windows line endings work', async () => { + await loadSrc([ + 'myVar = 10;', + 'cube(myVar);', + ].join('\r\n')); + await waitForViewer(); + expect3DPolySet(); + + await (await waitForCustomizeButton()).click(); + + await page.waitForSelector('fieldset'); + + await waitForLabel('myVar'); }, longTimeout); });