playwright-test icon indicating copy to clipboard operation
playwright-test copied to clipboard

Support for `import.meta.url`

Open Gozala opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe.

I'd like to conditionally load things relative to the test module, which can be achieved as

new URL('./asset.txt', import.meta.url)

However that does not seem to work because import.meta.url is undefined.

Describe the solution you'd like

Have import.meta.url be a module URL as loaded by test runner.

Describe alternatives you've considered

Use of fs.readFile which also does not work

Additional context Would like test new unixfs importer code across node / browser against a ready dataset

Gozala avatar Feb 28 '22 21:02 Gozala

This might be a relevant plugin https://www.npmjs.com/package/@chialab/esbuild-plugin-meta-url

Gozala avatar Mar 03 '22 23:03 Gozala

Can't really support import.meta.url since tests are all bundled. But you can just fetch any file in cwd or pass --assets and change it another folder

hugomrdias avatar Mar 18 '22 19:03 hugomrdias

Humm maybe I can define import.meta.url using the file path from esbuild metadata.

hugomrdias avatar Mar 18 '22 19:03 hugomrdias

This works now https://github.com/hugomrdias/playwright-test/commit/e7bde86b161f950d9fc1587ad2feb50683df790f will be on npm as v9

hugomrdias avatar Apr 28 '23 18:04 hugomrdias