Skip to content

fix(e2e): replace __dirname with import.meta.url in ESM context#664

Merged
hotlong merged 2 commits intomainfrom
copilot/update-coding-agent-job-data
Feb 21, 2026
Merged

fix(e2e): replace __dirname with import.meta.url in ESM context#664
hotlong merged 2 commits intomainfrom
copilot/update-coding-agent-job-data

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 21, 2026

E2E CI fails immediately with ReferenceError: __dirname is not defined in ES module scope because the root package.json sets "type": "module" but mobile-visual-regression.spec.ts uses the CJS-only __dirname global.

  • Replace __dirname with the ESM equivalent dirname(fileURLToPath(import.meta.url))
-import { join } from 'path';
+import { dirname, join } from 'path';
+import { fileURLToPath } from 'url';

-const snapshotsDir = join(__dirname, 'mobile-visual-regression.spec.ts-snapshots');
+const snapshotsDir = join(dirname(fileURLToPath(import.meta.url)), 'mobile-visual-regression.spec.ts-snapshots');
Original prompt

引用: https://github.com/objectstack-ai/objectui/actions/runs/22246780952/job/64362623763#step:8:1


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectui Ready Ready Preview, Comment Feb 21, 2026 1:17am
objectui-demo Ready Ready Preview, Comment Feb 21, 2026 1:17am
objectui-storybook Ready Ready Preview, Comment Feb 21, 2026 1:17am

Request Review

__dirname is not available in ES module scope. Use fileURLToPath(import.meta.url)
and dirname() as the ESM-compatible replacement.

Fixes CI failure: ReferenceError: __dirname is not defined in ES module scope
at mobile-visual-regression.spec.ts:25

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Update coding agent job data fix(e2e): replace __dirname with import.meta.url in ESM context Feb 21, 2026
Copilot AI requested a review from hotlong February 21, 2026 01:13
@hotlong hotlong marked this pull request as ready for review February 21, 2026 01:23
Copilot AI review requested due to automatic review settings February 21, 2026 01:23
@hotlong hotlong merged commit d8c2e10 into main Feb 21, 2026
4 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical E2E test failure caused by using the CommonJS-only __dirname global in an ES module context. The root package.json sets "type": "module", which makes all .ts/.js files use ESM semantics where __dirname is not defined, causing a ReferenceError during test execution.

Changes:

  • Replace __dirname with ESM-compatible dirname(fileURLToPath(import.meta.url)) pattern
  • Add required imports (dirname from path, fileURLToPath from url)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants