Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(loader): experimentalLoader with node@18 #21106

Merged
merged 2 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/playwright-test/src/experimentalLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ async function resolve(specifier: string, context: { parentURL?: string }, defau
specifier = url.pathToFileURL(resolved).toString();
}
const result = await defaultResolve(specifier, context, defaultResolve);
if (result?.url)
if (result?.url && result.url.startsWith('file://'))
currentFileDepsCollector()?.add(url.fileURLToPath(result.url));

return result;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/playwright-test/loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,29 @@ test('should import export assignment from ts', async ({ runInlineTest }) => {
expect(result.passed).toBe(1);
expect(result.exitCode).toBe(0);
});

test('should support node imports', async ({ runInlineTest }) => {
const result = await runInlineTest({
nowells marked this conversation as resolved.
Show resolved Hide resolved
'package.json': JSON.stringify({
type: 'module'
}),
'test.json': 'test data',
'utils.mjs': `
import fs from "node:fs/promises";

export async function utilityModuleThatImportsNodeModule() {
return await fs.readFile('test.json', 'utf8');
}
`,
'a.test.ts': `
import { test, expect } from '@playwright/test';
import { utilityModuleThatImportsNodeModule } from './utils.mjs';

test('pass', async () => {
expect(await utilityModuleThatImportsNodeModule()).toBe('test data');
});
`
});
expect(result.passed).toBe(1);
expect(result.exitCode).toBe(0);
});