Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions tests/playwright-test/babel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,82 @@ for (const type of ['module', undefined]) {
expect(result.stdout).toContain('imported value: bar');
});
}

test('should allow overwriting exports of a transpiled module', async ({ runInlineTest }) => {
const result = await runInlineTest({
'util.ts': `
export function greet() { return 'real'; }
`,
'greeter.ts': `
import { greet } from './util';
export function run() { return greet(); }
`,
'example.spec.ts': `
import { test, expect } from '@playwright/test';
import * as util from './util';
import { run } from './greeter';

test('works', () => {
(util as any).greet = () => 'stub';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we want to support that. IIUC, this is impossible with ESM anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these will fail when moving to esbuild, but we need to be mindful about it.

expect(run()).toBe('stub');
});
`,
});
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
});

test('should read undefined from an uninitialized import in a cycle', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.ts': `
import './b';
export const value = 'a';
`,
'b.ts': `
import { value } from './a';
export const valueSeenByB = value;
`,
'example.spec.ts': `
import { test, expect } from '@playwright/test';
import { value } from './a';
import { valueSeenByB } from './b';

test('works', () => {
expect(value).toBe('a');
expect(valueSeenByB).toBe(undefined);
});
`,
});
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
});

test('should parse generic arrow functions in tsx', async ({ runInlineTest }) => {
const result = await runInlineTest({
'example.spec.tsx': `
import { test, expect } from '@playwright/test';

const identity = <T>(value: T) => value;

test('works', () => {
expect(identity('value')).toBe('value');
});
`,
});
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
});

test('should reject import.meta in commonjs', async ({ runInlineTest }) => {
const result = await runInlineTest({
'example.spec.ts': `
import { test, expect } from '@playwright/test';

test('works', () => {
expect(import.meta.dirname).toBeTruthy();
});
`,
});
expect(result.exitCode).toBe(1);
expect(result.output).toMatch(/(SyntaxError: Cannot use 'import.meta' outside a module)|(ReferenceError: require is not defined in ES module scope)/);
});