Skip to content

Commit

Permalink
feat(install-browsers): automatically detect out of sync playwright d…
Browse files Browse the repository at this point in the history
…eps and attempt to install

Sometimes when playwright releases a new version the system deps
required also change. This change attempts to catch the out of sync deps
from a playwright warning, and then install the deps playwright needs to
prevent hard to debug issues with playwright not working.
  • Loading branch information
barbados-clemens committed Dec 3, 2024
1 parent 7018127 commit bc09276
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions workflow-steps/install-browsers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,41 @@ if (existsSync('package.json')) {
(json.devDependencies || {}).hasOwnProperty('@playwright/test');
if (hasPlaywright) {
console.log('Installing browsers required by Playwright');
execSync('npx playwright install', { stdio: 'inherit' });
const output = execSync('npx playwright install', {
stdio: 'inherit',
}).toString();

if (output.includes('missing dependencies')) {
console.log(
'Playwright detected missing dependencies. Attempting to install...',
);
try {
// playwright has detected out of sync dependencies on the host machine, we we'll try to manually install them to prevent hard to debug failures
const installDryRun = execSync(
'npx playwright install --with-deps --dry-run',
{ stdio: 'pipe' },
).toString();

const [installCommand] = installDryRun.match(
/apt-get install .+(?=")/gi,
);
if (installCommand) {
console.log('Installing Playwright dependencies');
execSync(installCommand, { stdio: 'inherit' });
}
} catch (installError) {
console.error(
'There was an issue installing dependencies for Playwright.',
);
console.error(installError);
console.log(
'You can create a custom launch template and add a step to manually install the missing dependencies (desribed above from Playwright) in order to get around this error.',
);
console.log(
'See docs here: https://nx.dev/ci/reference/launch-templates',
);
}
}
}

const hasCypress =
Expand All @@ -19,7 +53,6 @@ if (existsSync('package.json')) {
console.log('Installing browsers required by Cypress');
execSync('npx cypress install', { stdio: 'inherit' });
}

} catch (e) {
console.error(e);
}
Expand Down

0 comments on commit bc09276

Please sign in to comment.