You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You will need a copy of https://github.com/WordPress/wordpress-develop.git available. You can run `git clone https://github.com/WordPress/wordpress-develop.git` in this directory as this is where the bootstrap script expects it to be by default (the `WORDPRESS_DEVELOP_DIR` environment variable overrides this path).
132
132
133
133
Bootstrap the WordPress development environment by running `npm i; npm run build:dev`. Then copy wp-tests-config-sample.php to wp-tests-config.php inside the wordpress-develop directory and set the database credentials as needed. **WARNING!** This database is **dropped** everytime the tests run. Do not use a production database.
134
134
135
+
To install PHPUnit with this method, run `composer install`. You'll need `composer` installed globally.
136
+
135
137
Run `vendor/bin/phpunit` to launch the tests and hope for all green ;)
136
138
137
139
Unit and integration tests are mixed together (as is usual in WordPress) and can be found in tests/phpunit/cases and its subdirectories. Every case is in a class extending a TestCase, every test should be a public function starting with "test". We prefer snake case.
@@ -146,33 +148,59 @@ https://docs.phpunit.de/en/9.6/ for more information.
146
148
147
149
Alternatively, you can use the [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/) tool to quickly spin up a local dev and test environment, optionally switching between multiple PHP versions.
148
150
149
-
Please note that `wp-env` requires Docker to be installed. There are instructions available for installing Docker on [Windows](https://docs.docker.com/desktop/install/windows-install/), [macOS](https://docs.docker.com/desktop/install/mac-install/), and [Linux](https://docs.docker.com/desktop/install/linux-install/).
151
+
The test environment is started by running:
152
+
153
+
```sh
154
+
npm run env:start
155
+
```
150
156
151
-
This repository includes NPM scripts to run the tests with PHP versions 8.2 and 7.4.
157
+
This uses [`wp-env`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/) to quickly spin up a local dev and test environment, optionally switching between multiple PHP versions. `wp-env` requires Docker to be installed. There are instructions available for installing Docker on [Windows](https://docs.docker.com/desktop/install/windows-install/), [macOS](https://docs.docker.com/desktop/install/mac-install/), and [Linux](https://docs.docker.com/desktop/install/linux-install/).
152
158
153
-
**Note**: We need to maintain compatibility with PHP 7.4, as WordPress itself only has “beta support” for PHP 8.x. See https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/ for more information.
159
+
Visit [http://localhost:8888](http://localhost:8888)to see the dev site, and [http://localhost:8889](http://localhost:8880) for the test site, whose database is cleared on every run.
154
160
155
-
If you’re on Windows, you might have to use [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/install) to run the tests (see [this comment](https://bitbucket.org/tangibleinc/tangible-fields-module/pull-requests/30#comment-389568162)).
161
+
Before running tests, install PHPUnit as a dev dependency using Composer in the container.
156
162
157
-
To run the tests with Docker installed:
163
+
```sh
164
+
npm run env:composer:install
158
165
```
159
-
npm install
166
+
167
+
To run the tests:
168
+
169
+
```sh
160
170
npm run env:test:8.2
161
171
npm run env:test:7.4
162
172
```
163
173
164
174
The version-specific commands take a while to start, but afterwards you can run npm run env:test to re-run tests in the same environment.
165
175
166
176
To stop the Docker process:
167
-
```
177
+
178
+
```sh
168
179
npm run env:stop
169
180
```
170
181
171
182
To “destroy” and remove cache:
172
-
```
183
+
184
+
```sh
173
185
npm run env:destroy
174
186
```
175
187
188
+
#### Notes
189
+
190
+
To run more than one instance of `wp-env`, set different ports for the dev and test sites:
191
+
192
+
```sh
193
+
WP_ENV_PORT=3333 WP_ENV_TESTS_PORT=3334 npm run env:start
194
+
```
195
+
196
+
---
197
+
198
+
This repository includes NPM scripts to run the tests with PHP versions 8.2 and 7.4. We need to maintain compatibility with PHP 7.4, as WordPress itself only has “beta support” for PHP 8.x. See https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/ for more information.
199
+
200
+
---
201
+
202
+
If you’re on Windows, you might have to use [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/install) to run the tests (see [this comment](https://bitbucket.org/tangibleinc/tangible-fields-module/pull-requests/30#comment-389568162)).
203
+
176
204
### Jest
177
205
178
206
We rely on Jest to test the frontend side of the module:
Copy file name to clipboardExpand all lines: docs/pages/modules/framework/index.md
+218-1Lines changed: 218 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Many of these were refactored from the deprecated [plugin framework v2](https://
12
12
13
13
#### Source code
14
14
15
-
The framework is developed within the [Template System](https://github.com/tangibleinc/template-system). It is also published as [its own repository](https://github.com/tangibleinc/framework) to support plugins installing it as a Composer module.
This plugin comes with a suite of unit and integration tests.
130
+
131
+
The test environment is started by running:
132
+
133
+
```sh
134
+
npm run env:start
135
+
```
136
+
137
+
This uses [`wp-env`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/) to quickly spin up a local dev and test environment, optionally switching between multiple PHP versions. It requires **Docker** to be installed. There are instructions available for installing Docker on [Windows](https://docs.docker.com/desktop/install/windows-install/), [macOS](https://docs.docker.com/desktop/install/mac-install/), and [Linux](https://docs.docker.com/desktop/install/linux-install/).
138
+
139
+
Visit [http://localhost:8888](http://localhost:8888) to see the dev site, and [http://localhost:8889](http://localhost:8880) for the test site, whose database is cleared on every run.
140
+
141
+
Before running tests, install PHPUnit as a dev dependency using Composer inside the container.
142
+
143
+
```sh
144
+
npm run env:composer:install
145
+
```
146
+
147
+
Composer will add and remove folders in the `vendor` folder, based on `composer.json` and `composer.lock`. If you have any existing Git repositories, ensure they don't have any work in progress before running the above command.
148
+
149
+
Run the tests:
150
+
151
+
```sh
152
+
npm run env:test
153
+
```
154
+
155
+
For each PHP version:
156
+
157
+
```sh
158
+
npm run env:test:7.4
159
+
npm run env:test:8.2
160
+
```
161
+
162
+
The version-specific commands take a while to start, but afterwards you can run `npm run env:test` to re-run tests in the same environment.
163
+
164
+
To stop the Docker process:
165
+
166
+
```sh
167
+
npm run env:stop
168
+
```
169
+
170
+
To remove Docker containers, volumes, images associated with the test environment.
171
+
172
+
```sh
173
+
npm run env:destroy
174
+
```
175
+
176
+
#### Notes
177
+
178
+
To run more than one instance of `wp-env`, set different ports for the dev and test sites:
179
+
180
+
```sh
181
+
WP_ENV_PORT=3333 WP_ENV_TESTS_PORT=3334 npm run env:start
182
+
```
183
+
184
+
---
185
+
186
+
This repository includes NPM scripts to run the tests with PHP versions 8.2 and 7.4. We need to maintain compatibility with PHP 7.4, as WordPress itself only has “beta support” for PHP 8.x. See https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/ for more information.
187
+
188
+
---
189
+
190
+
If you’re on Windows, you might have to use [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/install) to run the tests (see [this comment](https://bitbucket.org/tangibleinc/tangible-fields-module/pull-requests/30#comment-389568162)).
191
+
192
+
### End-to-end tests
193
+
194
+
The folder `/tests/e2e` contains end-to-end-tests using [Playwright](https://playwright.dev/docs/intro) and [WordPress E2E Testing Utils](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-e2e-test-utils-playwright/).
195
+
196
+
#### Prepare
197
+
198
+
Before the first time you run it, install the browser engine.
199
+
200
+
```sh
201
+
npx playwright install chromium
202
+
```
203
+
204
+
#### Run
205
+
206
+
Run the tests. This will start the local WordPress environment with `wp-env` as needed. Then Playwright starts a browser engine to interact with the test site.
207
+
208
+
```sh
209
+
npm run test:e2e
210
+
```
211
+
212
+
#### Watch mode
213
+
214
+
There is a "Watch mode", where it will watch the test files for changes and re-run them.
215
+
This provides a helpful feedback loop when writing tests, as a kind of test-driven development. Press CTRL + C to stop the process.
216
+
217
+
```sh
218
+
npm run test:e2e:watch
219
+
```
220
+
221
+
A common usage is to have terminal sessions open with `npm run dev` (build assets and watch to rebuild) and `npm run tdd` (run tests and watch to re-run).
222
+
223
+
#### UI mode
224
+
225
+
There's also "UI mode" that opens a browser interface to see the tests run.
226
+
227
+
```sh
228
+
npm run test:e2e:ui
229
+
```
230
+
231
+
#### Utilities
232
+
233
+
Here are the common utilities used to write the tests.
0 commit comments