Skip to content

Commit 3b85b67

Browse files
emdashcodesemdashcodesgziolojustlevinejonathanbossenger
authored
Add client-only ability registration (#69)
* Client only abilities * fix: Add proper server ability validation in registerAbility * feat: Add ClientAbility and ServerAbility types for better type safety * refactor: Remove location field, use callback presence for execution type * feat: add permissionCallback on the client * update: check if ability is already registered in registerAbility * fix: wrap client errors in i18n * Add client library tests and code quality infrastructure (#70) * Add testing & linting infa * Remove uncessary combined checks * Add client tests * test: Use proper TypeScript types instead of 'as any' in tests * Fix typescript check for extra server check * test: update tests for client-only abilities API changes * chore: add build:client and dev:client scripts to root package.json * fix: formatting * fix: prettier issues * fix: apply Prettier formatting to README and validation.ts * deps: remove @types/wordpress__api-fetch since types are already shipped * fix: move validation to the store * fix: validate ability name uses same format as server * tests: clean up CI checks * deps: fix dev dependencies and remove extra package-lock.json * fix: rename main dev and build commands * fix: better match server validation rules for schema * Fix remaining validation issues Co-authored-by: emdashcodes <[email protected]> Co-authored-by: gziolo <[email protected]> Co-authored-by: justlevine <[email protected]> Co-authored-by: jonathanbossenger <[email protected]> --------- Co-authored-by: emdashcodes <[email protected]> Co-authored-by: gziolo <[email protected]> Co-authored-by: justlevine <[email protected]> Co-authored-by: jonathanbossenger <[email protected]> Co-authored-by: swissspidy <[email protected]>
1 parent d774d82 commit 3b85b67

26 files changed

+4188
-29177
lines changed

.github/workflows/test.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,93 @@ jobs:
247247
name: wp-code-coverage-${{ matrix.php }}-${{ matrix.wp }}
248248
path: tests/_output/html
249249
overwrite: true
250+
251+
# Runs JavaScript code quality checks.
252+
#
253+
# Performs the following steps:
254+
# - Checks out the repository.
255+
# - Sets up Node.js.
256+
# - Installs NPM dependencies.
257+
# - Runs Prettier formatting check.
258+
# - Runs JavaScript linting.
259+
# - Runs TypeScript type checking.
260+
jslint:
261+
name: Run JavaScript code quality checks
262+
runs-on: ubuntu-24.04
263+
permissions:
264+
contents: read
265+
timeout-minutes: 20
266+
267+
steps:
268+
- name: Checkout repository
269+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
270+
with:
271+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
272+
persist-credentials: false
273+
274+
- name: Setup Node.js
275+
uses: actions/setup-node@v4
276+
with:
277+
cache: 'npm'
278+
node-version-file: '.nvmrc'
279+
280+
- name: Install NPM dependencies
281+
run: npm ci
282+
283+
- name: Run Prettier format check
284+
run: npm run format
285+
286+
- name: Run JavaScript linting
287+
run: npm run lint:js
288+
289+
- name: Run TypeScript type checking
290+
run: npm run typecheck
291+
292+
# Runs JavaScript tests for the client package.
293+
#
294+
# Performs the following steps:
295+
# - Checks out the repository.
296+
# - Sets up Node.js.
297+
# - Installs NPM dependencies.
298+
# - Runs JavaScript tests with coverage.
299+
# - Uploads coverage reports.
300+
jstest:
301+
name: Run JavaScript tests
302+
runs-on: ubuntu-24.04
303+
permissions:
304+
contents: read
305+
timeout-minutes: 20
306+
307+
steps:
308+
- name: Checkout repository
309+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
310+
with:
311+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
312+
persist-credentials: false
313+
314+
- name: Setup Node.js
315+
uses: actions/setup-node@v4
316+
with:
317+
cache: 'npm'
318+
node-version-file: '.nvmrc'
319+
320+
- name: Install NPM dependencies
321+
run: npm ci
322+
323+
- name: Run JavaScript tests with coverage
324+
run: npm run test:client:coverage
325+
326+
- name: Upload JavaScript coverage to Codecov
327+
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
328+
with:
329+
token: ${{ secrets.CODECOV_TOKEN }}
330+
files: packages/client/coverage/lcov.info
331+
flags: javascript
332+
fail_ci_if_error: true
333+
334+
- name: Upload JavaScript coverage report as artifact
335+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
336+
with:
337+
name: javascript-coverage-report
338+
path: packages/client/coverage/lcov-report
339+
overwrite: true

CONTRIBUTING.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,39 @@ For more information on using `wp-env`, see the [wp-env documentation](https://d
8383

8484
#### Linting and Formatting
8585

86+
##### PHP Code Quality
87+
8688
- `npm run lint:php`: Runs PHPCS linting on the PHP code.
8789
- `npm run lint:php:fix`: Autofixes PHPCS linting issues.
8890
- `npm run lint:php:stan`: Runs PHPStan static analysis.
89-
- `npm run format`: Formats non-PHP files using Prettier.
91+
92+
##### JavaScript Code Quality
93+
94+
The project uses ESLint for linting and Prettier for code formatting, configured through `@wordpress/scripts`.
95+
96+
```bash
97+
# Lint all JavaScript/TypeScript files
98+
npm run lint:js
99+
100+
# Auto-fix linting issues
101+
npm run lint:js:fix
102+
103+
# Run TypeScript typecheck
104+
npm run typecheck
105+
```
106+
107+
##### Formatting Code
108+
109+
Format all files (JavaScript, JSON, Markdown, etc.):
110+
111+
```bash
112+
npm run format
113+
```
90114

91115
### Running Tests
92116

117+
#### PHP Tests
118+
93119
PHPUnit tests can be run using the following command:
94120

95121
```bash
@@ -106,6 +132,26 @@ npm run test:php
106132

107133
You should see the html coverage report in the `tests/_output/html` directory and the clover XML report in `tests/_output/php-coverage.xml`.
108134

135+
#### JavaScript Tests
136+
137+
The JavaScript client package tests can be run using the following commands:
138+
139+
```bash
140+
# Run all JavaScript tests
141+
npm run test:client
142+
143+
# Run tests in watch mode (great for development)
144+
npm run test:client:watch
145+
```
146+
147+
To generate a code coverage report, run:
148+
149+
```bash
150+
npm run test:client:coverage
151+
```
152+
153+
Coverage reports are generated in the `packages/client/coverage/` directory.
154+
109155
### Building the plugin for distribution
110156

111157
To build the plugin for distribution, you can use the following command:

0 commit comments

Comments
 (0)