Skip to content

Commit

Permalink
Normalize CRLF to \n and test customizer in e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
ochafik committed Dec 25, 2024
1 parent 657ccb9 commit b45288b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 44 additions & 4 deletions tests/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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);
});

0 comments on commit b45288b

Please sign in to comment.