From 2a0984b264143b9aac88206f1ec954c676cb9025 Mon Sep 17 00:00:00 2001 From: Caleb Ukle Date: Tue, 3 Dec 2024 08:28:21 -0600 Subject: [PATCH] feat(install-browsers): automatically detect out of sync playwright deps 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. --- workflow-steps/install-browsers/main.js | 39 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/workflow-steps/install-browsers/main.js b/workflow-steps/install-browsers/main.js index 4acf01b..90c01a4 100644 --- a/workflow-steps/install-browsers/main.js +++ b/workflow-steps/install-browsers/main.js @@ -9,7 +9,43 @@ 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:\n${installCommand}`, + ); + 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 Playwright dependencies in order to get around this error.', + ); + console.log( + 'See docs here: https://nx.dev/ci/reference/launch-templates', + ); + } + } } const hasCypress = @@ -19,7 +55,6 @@ if (existsSync('package.json')) { console.log('Installing browsers required by Cypress'); execSync('npx cypress install', { stdio: 'inherit' }); } - } catch (e) { console.error(e); }