Skip to content

Commit

Permalink
Fix unicode normalization test, work around bigint logging issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bitjson committed Jan 26, 2024
1 parent 9047128 commit d4ed1ed
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 96 deletions.
14 changes: 13 additions & 1 deletion src/editor/evaluation-viewer/EvaluationViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ import {
} from '@blueprintjs/icons';
import { useState } from 'react';

// TODO: remove this workaround when https://github.com/PostHog/posthog-js/issues/968 lands
declare global {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface BigInt {
toJSON: () => string;
}
}
BigInt.prototype.toJSON = function () {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
return this.toString();
};

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
(window as any).libauth = libauth;

Expand Down Expand Up @@ -262,7 +274,7 @@ const EvaluationLine = ({
}`}
onClick={() => {
console.log(`ProgramState after line #${lineNumber}:`);
console.log(stringify(line.state));
console.log(line.state);
}}
>
{line.spacers?.slice(0, sliceSpacersAtIndex).map((type, index) => (
Expand Down
49 changes: 15 additions & 34 deletions tests/editor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, loadTemplate, scrollUntil, test } from './test-utils';
import { expect, loadTemplate, test } from './test-utils';

test('renders spacers as expected', async ({ page }) => {
await loadTemplate(page, 'tests/fixtures/spacers.json');
Expand Down Expand Up @@ -29,7 +29,7 @@ test('renders error as expected for a non-push opcode in unlocking script', asyn
await expect(page).toHaveScreenshot();
});

test('Displays evaluation of tested scripts', async ({ page }) => {
test('displays evaluation of tested scripts', async ({ page }) => {
await loadTemplate(page, 'tests/fixtures/state-merkle-trees.json');
await page.getByRole('button', { name: 'Empty Leaf', exact: true }).click();
await expect(page).toHaveScreenshot();
Expand All @@ -51,7 +51,7 @@ test('Displays evaluation of tested scripts', async ({ page }) => {
await expect(page.locator('.state.highlight.success')).toContainText('1');
});

test('Displays evaluation of tested scripts with custom scenarios', async ({
test('displays evaluation of tested scripts with custom scenarios', async ({
page,
}) => {
await loadTemplate(
Expand All @@ -61,34 +61,15 @@ test('Displays evaluation of tested scripts with custom scenarios', async ({
await page.getByRole('button', { name: 'Is 2 Bytes' }).click();
});

test.fixme(
'scrolls, renders success highlighting on valid unlock',
async ({ page, isMobile }) => {
test.skip(isMobile, '`scrollUntil` is not supported by mobile WebKit');
await loadTemplate(page, 'tests/fixtures/state-merkle-trees.json');
await page.getByRole('button', { name: 'Replace Empty Leaf' }).click();

await scrollUntil(
page,
page.locator('.ScriptEditor-locking .editor'),
page.getByText('OP_OUTPUTVALUE OP_EQUAL'),
);
await page.locator('.state.highlight.success').isVisible();
await expect(page).toHaveScreenshot();
},
);

test.fixme(
'ignores misleading unicode characters, shows compilation on hover',
async ({ page }) => {
await loadTemplate(page, 'tests/fixtures/empty.json');
await page.getByRole('button', { name: 'Unlock' }).click();
await page.locator('.ScriptEditor-locking .monaco-editor').click();
await page
.locator('.editor textarea')
.last()
.fill("<'fit'> <'fit'>\nOP_EQUAL\n");
await page.getByText('<').first().hover();
await expect(page).toHaveScreenshot();
},
);
test('ignores misleading unicode characters, shows compilation on hover', async ({
page,
}) => {
await loadTemplate(page, 'tests/fixtures/empty.json');
await page.getByRole('button', { name: 'Unlock' }).click();
await page.locator('.ScriptEditor-locking .monaco-editor').click();
await page.locator('.editor .view-line').last().click();
await page.keyboard.type(`<'fit'> <'fit'>\nOP_EQUAL\n`);
await page.getByText('<').first().hover();
await expect(page.getByText('Compiled: 0x03666974')).toBeVisible();
await expect(page).toHaveScreenshot();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/fixtures/empty.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"unlocks": "lock"
},
"lock": {
"lockingType": "standard",
"lockingType": "p2sh20",
"name": "Lock",
"script": ""
}
Expand Down
60 changes: 0 additions & 60 deletions tests/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,63 +101,3 @@ export const fixFontFlakiness = async (page: Page, enable = true) => {
);
await page.evaluate(() => document.fonts.ready);
};

const timeout = (ms: number) => {
const state = {
done: false,
promise: new Promise((res) => setTimeout(res, ms)).then(() => {
state.done = true;
}),
};
return state;
};

/**
* A utility to scroll within a container until another element becomes visible.
*
* Note, scrolling with Playwright's `mouse.wheel` is not supported in
* mobile WebKit.
*/
export const scrollUntil = async (
/**
* A Playwright {@link Page}
*/
page: Page,
/**
* A locator for the element in which to scroll
*/
scrollContainer: Locator,
/**
* A locator for the element to which the container should scroll
*/
scrollUntilVisible: Locator,
options: {
/**
* Pixels to scroll horizontally for each `wheel` event
*/
deltaX: number;
/**
* Pixels to scroll vertically for each `wheel` event
*/
deltaY: number;
/**
* The delay in milliseconds after which the operation will abort
*/
timeout: number;
} = {
deltaX: 0,
deltaY: 100,
timeout: 5_000,
},
) => {
const indefinite = options.timeout === 0;
const timer = timeout(options.timeout);
await scrollContainer.hover();
while (
(indefinite || !timer.done) &&
!(await scrollUntilVisible.isVisible())
) {
await page.mouse.wheel(options.deltaX, options.deltaY);
}
await page.mouse.wheel(options.deltaX, options.deltaY);
};

0 comments on commit d4ed1ed

Please sign in to comment.