Skip to content

Commit

Permalink
playwright-test: Add PLAYWRIGHT_BROWSERS_PATH to build environment
Browse files Browse the repository at this point in the history
This allows writing self-contained node scripts (using a nix-shell
shebang), without requiring a separate shell.nix which sets
PLAYWRIGHT_BROWSERS_PATH to pkgs.playwright-driver.browsers.
  • Loading branch information
the-sun-will-rise-tomorrow committed Dec 26, 2024
1 parent 1557114 commit ca60ebe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkgs/development/web/playwright/driver.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
makeFontsConf,
makeWrapper,
runCommand,
writeText,
cacert,
}:
let
Expand Down Expand Up @@ -191,9 +192,25 @@ let
runHook postInstall
'';

setupHook = writeText "setupHook.sh" ''
addBrowsersPath () {
export PLAYWRIGHT_BROWSERS_PATH="${playwright-core.passthru.browsers}"
}
addEnvHooks "$targetOffset" addBrowsersPath
'';

meta = playwright.meta // {
mainProgram = "playwright";
};

passthru.tests.env = runCommand "playwright-core-env-test" {
buildInputs = [
nodejs
playwright-core
playwright-test
];
} "node ${./test.js}";
});

browsers-mac = stdenv.mkDerivation {
Expand Down
8 changes: 8 additions & 0 deletions pkgs/development/web/playwright/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const playwright = require('playwright');
const fs = require('fs');
playwright.chromium.launch()
.then((browser) => {
console.log('OK');
fs.writeFileSync(process.env.out, '');
process.exit(0);
});

0 comments on commit ca60ebe

Please sign in to comment.