Skip to content

Commit bc33c15

Browse files
Merge pull request #34 from DeDuckProject/fix/playwright-resolve-from-cwd
fix: resolve @playwright/test from project cwd, not action dist direc…
2 parents 64366e7 + ffaa7e6 commit bc33c15

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

packages/action/dist/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65511,12 +65511,13 @@ async function generateDemoScript(client, analysis, rawDiff, baseUrl, config, ge
6551165511
// ../core/dist/recorder/playwright-runner.js
6551265512
var import_node_fs2 = require("node:fs");
6551365513
var import_node_path = require("node:path");
65514+
var import_node_module = require("node:module");
6551465515
async function runScriptAndRecord(options) {
6551565516
const { script, baseUrl, recording, outputDir } = options;
6551665517
if (!(0, import_node_fs2.existsSync)(outputDir)) {
6551765518
(0, import_node_fs2.mkdirSync)(outputDir, { recursive: true });
6551865519
}
65519-
const { chromium } = await import("@playwright/test");
65520+
const { chromium } = (0, import_node_module.createRequire)((0, import_node_path.join)(process.cwd(), "package.json"))("@playwright/test");
6552065521
const browser = await chromium.launch({ headless: true });
6552165522
const startTime = Date.now();
6552265523
try {
@@ -65767,11 +65768,12 @@ function scanForFfmpeg(cacheDir) {
6576765768
// ../core/dist/recorder/fallback.js
6576865769
var import_node_fs4 = require("node:fs");
6576965770
var import_node_path3 = require("node:path");
65771+
var import_node_module2 = require("node:module");
6577065772
async function takeScreenshots(baseUrl, routes, recording, outputDir) {
6577165773
if (!(0, import_node_fs4.existsSync)(outputDir)) {
6577265774
(0, import_node_fs4.mkdirSync)(outputDir, { recursive: true });
6577365775
}
65774-
const { chromium } = await import("@playwright/test");
65776+
const { chromium } = (0, import_node_module2.createRequire)((0, import_node_path3.join)(process.cwd(), "package.json"))("@playwright/test");
6577565777
const browser = await chromium.launch({ headless: true });
6577665778
const screenshots = [];
6577765779
try {

packages/action/dist/index.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/recorder/fallback.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mkdirSync, existsSync } from 'node:fs';
22
import { join } from 'node:path';
3+
import { createRequire } from 'node:module';
34
import type { RecordingConfig } from '../config/schema.js';
45
import type { RouteMapping } from '../analyzer/route-detector.js';
56

@@ -17,7 +18,7 @@ export async function takeScreenshots(
1718
mkdirSync(outputDir, { recursive: true });
1819
}
1920

20-
const { chromium } = await import('@playwright/test');
21+
const { chromium } = createRequire(join(process.cwd(), 'package.json'))('@playwright/test') as typeof import('@playwright/test');
2122
const browser = await chromium.launch({ headless: true });
2223
const screenshots: string[] = [];
2324

packages/core/src/recorder/playwright-runner.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Browser, BrowserContext, Page } from '@playwright/test';
22
import { existsSync, mkdirSync } from 'node:fs';
33
import { join } from 'node:path';
4+
import { createRequire } from 'node:module';
45
import type { RecordingConfig } from '../config/schema.js';
56

67
export interface RecordingResult {
@@ -22,7 +23,10 @@ export async function runScriptAndRecord(options: RunScriptOptions): Promise<Rec
2223
mkdirSync(outputDir, { recursive: true });
2324
}
2425

25-
const { chromium } = await import('@playwright/test');
26+
// Resolve @playwright/test from the user's project (process.cwd()), not from the
27+
// action's own dist directory. This is necessary when running as a GitHub Action,
28+
// where the action bundle lives in a separate directory from the user's node_modules.
29+
const { chromium } = createRequire(join(process.cwd(), 'package.json'))('@playwright/test') as typeof import('@playwright/test');
2630
const browser = await chromium.launch({ headless: true });
2731
const startTime = Date.now();
2832

0 commit comments

Comments
 (0)