Skip to content

Commit 93058ed

Browse files
authored
Fix regression with loadJS always throwing (#217)
1 parent 27c7069 commit 93058ed

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

.changeset/rich-dancers-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pleasantest': patch
3+
---
4+
5+
Fix regression with loadJS always throwing

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ const createTab = async ({
383383
const res = await safeEvaluate(
384384
loadJS,
385385
`import(${JSON.stringify(url)})
386+
.then(mod => {})
386387
.catch(e => e instanceof Error
387388
? { message: e.message, stack: e.stack }
388389
: e)`,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface Window {
2+
foo: string;
3+
}
4+
5+
window.foo = 'hi';

tests/utils/loadJS.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { withBrowser } from 'pleasantest';
22
import { formatErrorWithCodeFrame, printErrorFrames } from '../test-utils';
33

4-
test.todo('loads from .ts file with transpiling');
4+
test(
5+
'loads and executes .ts file with transpiling',
6+
withBrowser(async ({ utils, page }) => {
7+
expect(await page.evaluate(() => window.foo)).toBeUndefined();
8+
await utils.loadJS('./external-with-side-effect.ts');
9+
expect(await page.evaluate(() => window.foo)).toEqual('hi');
10+
}),
11+
);
512

613
test(
714
'if the file throws an error the error is source mapped',

0 commit comments

Comments
 (0)