Skip to content

Commit 9aff2ac

Browse files
committed
Update module repos and generate docs
1 parent 0114f00 commit 9aff2ac

16 files changed

Lines changed: 1174 additions & 45 deletions

File tree

docs/pages/modules/fields/index.md

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ cd fields
5959
Install dependencies:
6060

6161
```sh
62-
composer install & npm ci
62+
npm ci
6363
```
6464

65+
### JS and CSS
66+
6567
Build for development - watch files for changes and rebuild
6668

6769
```sh
@@ -88,7 +90,7 @@ Start a local test site using [`wp-now`](https://github.com/WordPress/playground
8890
npm run start
8991
```
9092

91-
For convenience, this also concurrently builds for development and watches files to rebuild.
93+
For convenience, this also concurrently runs `npm run dev`.
9294

9395
### Dev dependencies
9496

@@ -124,14 +126,14 @@ Mainly it's useful for mounting local folders into the virtual file system. For
124126

125127
This module comes with a suite of unit and integration tests.
126128

127-
`composer install --dev` will install PHPUnit.
128-
129129
#### Method 1: Cloning wordpress-develop.git (Previous)
130130

131131
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).
132132

133133
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.
134134

135+
To install PHPUnit with this method, run `composer install`. You'll need `composer` installed globally.
136+
135137
Run `vendor/bin/phpunit` to launch the tests and hope for all green ;)
136138

137139
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.
146148

147149
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.
148150

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+
```
150156

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/).
152158

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.
154160

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.
156162

157-
To run the tests with Docker installed:
163+
```sh
164+
npm run env:composer:install
158165
```
159-
npm install
166+
167+
To run the tests:
168+
169+
```sh
160170
npm run env:test:8.2
161171
npm run env:test:7.4
162172
```
163173

164174
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.
165175

166176
To stop the Docker process:
167-
```
177+
178+
```sh
168179
npm run env:stop
169180
```
170181

171182
To “destroy” and remove cache:
172-
```
183+
184+
```sh
173185
npm run env:destroy
174186
```
175187

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+
176204
### Jest
177205

178206
We rely on Jest to test the frontend side of the module:

docs/pages/modules/framework/index.md

Lines changed: 218 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Many of these were refactored from the deprecated [plugin framework v2](https://
1212

1313
#### Source code
1414

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.
15+
Git repository: https://github.com/tangibleinc/framework
1616

1717
## Modules
1818

@@ -27,3 +27,220 @@ The framework is developed within the [Template System](https://github.com/tangi
2727
- [Object](object)
2828
- [Plugin](plugin)
2929
- [Select](select)
30+
31+
## Develop
32+
33+
Prerequisites: [Git](https://git-scm.com/), [Node](https://nodejs.org/en/) (version 18 and above)
34+
35+
Clone the repository and install dependencies.
36+
37+
```sh
38+
git clone git@github.com:tangibleinc/framework.git
39+
cd framework
40+
npm install
41+
```
42+
43+
### JS and CSS
44+
45+
Build for development - watch files for changes and rebuild
46+
47+
```sh
48+
npm run dev
49+
```
50+
51+
Build for production
52+
53+
```sh
54+
npm run build
55+
```
56+
57+
Format to code standard
58+
59+
```sh
60+
npm run format
61+
```
62+
63+
#### Build modules for development
64+
65+
Watch files for changes and rebuild.
66+
67+
```sh
68+
npm run dev [module1 module2..]
69+
```
70+
71+
Press CTRL + C to stop.
72+
73+
#### Build modules for production
74+
75+
Builds minified bundles with source maps.
76+
77+
```sh
78+
npm run build [module1 module2..]
79+
```
80+
81+
#### Format code
82+
83+
Format files to code standard with [Prettier](https://prettier.io) and [PHP Beautify](https://github.com/tangibleinc/php-beautify).
84+
85+
```sh
86+
npm run format [module1 module2..]
87+
```
88+
89+
### Local dev site
90+
91+
Start a local dev site using [`wp-now`](https://github.com/WordPress/playground-tools/blob/trunk/packages/wp-now/README.md).
92+
93+
```sh
94+
npm run start
95+
```
96+
97+
Press CTRL + C to stop.
98+
99+
#### Dev dependencies
100+
101+
Optionally, install dev dependencies such as third-party plugins before starting the site.
102+
103+
```sh
104+
npm run install:dev
105+
```
106+
107+
To keep them updated, run:
108+
109+
```sh
110+
npm run update:dev
111+
```
112+
113+
#### Customize environment
114+
115+
Create a file named `.wp-env.override.json` to customize the WordPress environment. This file is listed in `.gitignore` so it's local to your setup.
116+
117+
Mainly it's useful for mounting local folders into the virtual file system. For example, to link another plugin in the parent directory:
118+
119+
```json
120+
{
121+
"mappings": {
122+
"wp-content/plugins/example-plugin": "../example-plugin"
123+
}
124+
}
125+
```
126+
127+
## Tests
128+
129+
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.
234+
235+
- `test` - https://playwright.dev/docs/api/class-test
236+
- `expect` - https://playwright.dev/docs/api/class-genericassertions
237+
- `admin` - https://github.com/WordPress/gutenberg/tree/trunk/packages/e2e-test-utils-playwright/src/admin
238+
- `page` - https://playwright.dev/docs/api/class-page
239+
- `request` - https://playwright.dev/docs/api/class-apirequestcontext
240+
241+
#### References
242+
243+
Examples of how to write end-to-end tests:
244+
245+
- WordPress E2E tests - https://github.com/WordPress/wordpress-develop/blob/trunk/tests/e2e
246+
- Gutenberg E2E tests - https://github.com/WordPress/gutenberg/tree/trunk/test/e2e

0 commit comments

Comments
 (0)