Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for multiple hostnames #25

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![tests](https://github.com/julienloizelet/ddev-playwright/actions/workflows/tests.yml/badge.svg)](https://github.com/julienloizelet/ddev-playwright/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2024.svg)
[![tests](https://github.com/julienloizelet/ddev-playwright/actions/workflows/tests.yml/badge.svg)](https://github.com/julienloizelet/ddev-playwright/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2025.svg)
[![Version](https://img.shields.io/github/v/release/julienloizelet/ddev-playwright)](https://github.com/julienloizelet/ddev-playwright/releases)

# ddev-playwright
Expand Down Expand Up @@ -30,7 +30,7 @@

## Introduction

[Playwright](https://playwright.dev) was created to accommodate the needs of end-to-end testing.
[Playwright](https://playwright.dev) was created to accommodate the needs of end-to-end testing.

This DDEV add-on allows you to use Playwright in a separate `playwright` service.

Expand All @@ -55,6 +55,9 @@ Then restart your project
ddev restart
```

> [!NOTE]
> If you change `additional_hostnames` or `additional_fqdns`, you have to re-run `ddev add-on get julienloizelet/ddev-playwright`

## Basic usage

### Quick start
Expand Down Expand Up @@ -108,9 +111,9 @@ This command will install `playwright` and all dependencies in a folder defined
You can choose to use `npm` or `yarn` as package manager by using the `--pm` option. By default, `yarn` is used.


**Before running this command**, ensure that you have a `package.json` file in the `PLAYWRIGHT_TEST_DIR` folder.
**Before running this command**, ensure that you have a `package.json` file in the `PLAYWRIGHT_TEST_DIR` folder.

You will find an example of such a file in the `tests/project_root/tests/Playwright`folder of this repository.
You will find an example of such a file in the `tests/project_root/tests/Playwright`folder of this repository.

<details>

Expand Down Expand Up @@ -210,7 +213,7 @@ You can choose to use `npm` or `yarn` as package manager by using the `--pm` opt

You can run all the playwright command with `ddev playwright [command]`.

- To run playwright's test command:
- To run playwright's test command:

```bash
ddev playwright test
Expand Down Expand Up @@ -244,7 +247,7 @@ When running in UI/headed mode, you can use the provided Kasmvnc service by brow

![kasmvnc](./docs/kasmvnc.jpg)

It could be also used to generate playwright code by browsing with the following command:
It could be also used to generate playwright code by browsing with the following command:

```bash
ddev playwright codegen
Expand All @@ -254,7 +257,7 @@ ddev playwright codegen

As for any DDEV additional service, you can use the `ddev exec -s playwright [command]` snippet to run a command in the playwright container.

For example:
For example:

- `ddev exec -s playwright yarn install --cwd ./var/www/html/yarn --force`
- `ddev exec -s playwright yarn --cwd /var/www/html/yarn test "__tests__/1-simple-test.js"`
Expand All @@ -263,10 +266,10 @@ For example:

### `.npmrc` file and `.ddev/homeadditions`

If you wish to use a specific `.npmrc` file (for private NPM registries for example), you just need to place the `.npmrc` file in the `.ddev/homeadditions` folder of your project. This way, the `ddev playwright-install` command
If you wish to use a specific `.npmrc` file (for private NPM registries for example), you just need to place the `.npmrc` file in the `.ddev/homeadditions` folder of your project. This way, the `ddev playwright-install` command
will automatically retrieve it.

More generally, all the `.ddev/homeadditions` folder content is copied to `/home/pwuser` folder when the `playwright`
More generally, all the `.ddev/homeadditions` folder content is copied to `/home/pwuser` folder when the `playwright`
container is build.


Expand Down
2 changes: 0 additions & 2 deletions docker-compose.playwright.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ services:
- .:/mnt/ddev_config
- ddev-global-cache:/mnt/ddev-global-cache
- ../:/var/www/html:rw
external_links:
- ddev-router:${DDEV_HOSTNAME}
working_dir: /var/www/html
33 changes: 33 additions & 0 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,36 @@ project_files:
- playwright-build/xstartup
- playwright-build/entrypoint.sh
- docker-compose.playwright.yaml

post_install_actions:
- |
#ddev-nodisplay
#ddev-description:Checking docker-compose.playwright_extras.yaml for changes
if [ -f docker-compose.playwright_extras.yaml ] && ! grep -q '#ddev-generated' docker-compose.playwright_extras.yaml; then
echo "Existing docker-compose.playwright_extras.yaml does not have #ddev-generated, so can't be updated"
exit 2
fi
- |
#ddev-nodisplay
#ddev-description:Adding all hostnames to the playwright container to make them available
cat <<-END >docker-compose.playwright_extras.yaml
#ddev-generated
services:
playwright:
external_links:
{{- $playwright_hostnames := splitList "," (env "DDEV_HOSTNAME") -}}
{{- range $i, $n := $playwright_hostnames }}
- "ddev-router:{{- replace (env "DDEV_TLD") "\\${DDEV_TLD}" (replace (env "DDEV_PROJECT") "\\${DDEV_PROJECT}" $n) -}}"
{{- end }}
END
removal_actions:
- |
#ddev-nodisplay
#ddev-description:Remove docker-compose.playwright_extras.yaml file
if [ -f docker-compose.playwright_extras.yaml ]; then
if grep -q '#ddev-generated' docker-compose.playwright_extras.yaml; then
rm -f docker-compose.playwright_extras.yaml
else
echo "Unwilling to remove '$DDEV_APPROOT/.ddev/docker-compose.playwright_extras.yaml' because it does not have #ddev-generated in it; you can manually delete it if it is safe to delete."
fi
fi
Loading