Skip to content

Commit

Permalink
Merge pull request #193 from stellarwp/playwright-support
Browse files Browse the repository at this point in the history
Playwright support
  • Loading branch information
borkweb committed May 14, 2024
2 parents ad0c18d + cb40ae1 commit 4ae378b
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 5 deletions.
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [1.6.3] - 2024-05-10
* Added - The `playwright` command to Playwright commands in the stack.
* Added - The `less` binary to the `slic` container (to correctly format wp-cli output).
* Added - The `p` alias to the `slic` container to allow running Playwright commands with `p <command>`, similar to `c <command>` to run Codeception commands.

# [1.6.2] - 2024-05-10
* Added - The `slic` command now loads the `.env.slic.local` file from the target directory if it exists. (thanks @cliffordp)
* Added - The `chrome` container shm size is now set to `256m` by default, and is controllable via the `SLIC_CHROME_CONTAINER_SHM_SIZE` env var. (thanks @maurisrx)

# [1.6.1] - 2024-04-19
* Change - the `airplane-mode` command now installs the plugin in the must-use plugins directory instead of the plugins directory.
* Fixed - `.bat` file now uses the correct path to the `slic` executable on Windows.
Expand Down
2 changes: 1 addition & 1 deletion containers/slic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN apt-get update && apt-get upgrade -yqq && apt-get install -yqq --no-install-
libnss3 libnspr4 libdbus-1-3 libatk1.0-0 libatk-bridge2.0-0 \
libcups2 libdrm2 libxkbcommon0 libatspi2.0-0 libxcomposite1 \
libxdamage1 libxext6 libxfixes3 libxrandr2 libgbm1 \
libpango-1.0-0 libcairo2 libasound2 \
libpango-1.0-0 libcairo2 libasound2 less \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Configure the uopz extension.
Expand Down
4 changes: 3 additions & 1 deletion containers/slic/bashrc_scripts.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Some aliases to save some typing.
alias c="vendor/bin/codecept -c $(if [ -f 'codeception.slic.yml' ]; then echo 'codeception.slic.yml'; else echo 'codeception.tric.yml'; fi)"
alias cr="vendor/bin/codecept -c $(if [ -f 'codeception.slic.yml' ]; then echo 'codeception.slic.yml'; else echo 'codeception.tric.yml'; fi) run"
alias p="node_modules/.bin/playwright"

# Returns the path to the PHP version configuration file.
function xdebug_config_file(){
Expand Down Expand Up @@ -32,6 +33,7 @@ fi

echo " c = codecept"
echo " cr = codecept run"
echo " p = playwright"
echo " xon = turn xdebug on"
echo " xoff = turn xdebug off"
echo ""
echo ""
3 changes: 2 additions & 1 deletion slic.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
] );

$cli_name = 'slic';
const CLI_VERSION = '1.6.1';
const CLI_VERSION = '1.6.3';

// If the run-time option `-q`, for "quiet", is specified, then do not print the header.
if ( in_array( '-q', $argv, true ) || ( in_array( 'exec', $argv, true ) && ! in_array( 'help', $argv, true ) ) ) {
Expand Down Expand Up @@ -80,6 +80,7 @@
<light_cyan>using</light_cyan> Returns the current <light_cyan>use</light_cyan> target.
<light_cyan>wp</light_cyan> Runs a wp-cli command or opens a `wp-cli shell` in the stack.
<light_cyan>xdebug</light_cyan> Activates and deactivates XDebug in the stack, returns the current XDebug status or sets its values.
<light_cyan>playwright</light_cyan> Runs Playwright commands in the stack.
Type <light_cyan>{$cli_name} <command> help</light_cyan> for info about each command.
HELP;
Expand Down
2 changes: 0 additions & 2 deletions src/commands/npm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
$help = <<< HELP
SUMMARY:
Runs an npm command in the stack. If an .nvmrc is present, that version of node will be used.
This command requires a use target set using the <light_cyan>use</light_cyan> command.
USAGE:
Expand Down
67 changes: 67 additions & 0 deletions src/commands/playwright.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Handles Playwright commands.
*
* @var bool $is_help Whether we're handling an `help` request on this command or not.
* @var Closure $args The argument map closure, as produced by the `args` function.
* @var string $cli_name The current name of the `slic` CLI application.
*/

namespace StellarWP\Slic;

if ( $is_help ) {
$help = <<< HELP
SUMMARY:
This command requires a use target set using the <light_cyan>use</light_cyan> command.
USAGE:
<yellow>{$cli_name} playwright [...<commands>]</yellow>
EXAMPLES:
<light_cyan>{$cli_name} playwright install</light_cyan>
Install Playwright dependencies in the current <light_cyan>use</light_cyan> target.
<light_cyan>{$cli_name} playwright test</light_cyan>
Run all Playwright tests following the Playwright configuration in the current <light_cyan>use</light_cyan> target.
<light_cyan>{$cli_name} playwright test tests/e2e/my-test.spec.ts</light_cyan>
Run a specific Playwright test file from the root directory of the <light_cyan>use</light_cyan> target.
HELP;

echo colorize( $help );

return;
}

$using = slic_target_or_fail();
echo light_cyan( "Using {$using}" . PHP_EOL );

ensure_service_running( 'slic' );

setup_id();
$playwright_args = $args( '...' );
$status = slic_realtime()(
array_merge(
[
'exec',
'--user',
sprintf( '"%s:%s"', getenv( 'SLIC_UID' ), getenv( 'SLIC_GID' ) ),
'--workdir',
escapeshellarg( get_project_container_path() ),
'slic',
'node_modules/.bin/playwright',
],
$playwright_args
)
);

// If there is a status other than 0, we have an error. Bail.
if ( $status ) {
exit( $status );
}

exit( $status );

0 comments on commit 4ae378b

Please sign in to comment.