Skip to content

Commit 8feb200

Browse files
authored
Merge pull request #73 from codebtech/chore/step-e2e-tests
Chore/step e2e tests
2 parents fcbeab9 + b282643 commit 8feb200

34 files changed

+289
-132
lines changed

.github/workflows/e2e.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ jobs:
4848
- name: Run Playwright tests
4949
run: npx playwright test
5050

51-
- uses: actions/upload-artifact@v4
51+
- name: Upload artifacts
52+
uses: actions/upload-artifact@v4
53+
if: always()
5254
with:
5355
name: playwright-report
5456
path: playwright-report/

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ yarn-error.log
55
.phpunit.result.cache
66
.DS_Store
77
testingdb
8-
.vscode
98
.env
109
.auth/
1110
artifacts/

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"shevaua.phpcs",
4+
"sbenp.prettier-vscode"
5+
],
6+
}

README.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ WordPress Feature flags plugin allow developers to configure features in plugins
1010

1111
### PHP filters
1212

13-
#### `mr_feature_flags_max_allowed`
13+
#### `codeb_feature_flags_max_allowed`
1414

1515
Filter to define the maximum number of allowed flags. It is recommended to keep this to default value, which is 20.
1616

1717
Example usage:
1818

1919
```php
2020
add_filter(
21-
'mr_feature_flags_max_allowed',
21+
'codeb_feature_flags_max_allowed',
2222
static function () {
2323
return 10;
2424
}
@@ -27,16 +27,20 @@ add_filter(
2727

2828
### JS filters
2929

30-
##### `mrFeatureFlags.newFlag.defaultStatus`
30+
##### `codebFeatureFlags.newFlag.defaultStatus`
3131

3232
The filter controls whether the new flag is enabled by default or not. Default `true`
3333

3434
Example usage:
3535

3636
```js
37-
addFilter('mrFeatureFlags.newFlag.defaultStatus', 'codeb-feature-flags', () => {
38-
return false;
39-
});
37+
addFilter(
38+
'codebFeatureFlags.newFlag.defaultStatus',
39+
'codeb-feature-flags',
40+
() => {
41+
return false;
42+
}
43+
);
4044
```
4145

4246
## Development setup
@@ -51,27 +55,33 @@ JS setup
5155

5256
- `yarn install`
5357
- `yarn build` to create the build
54-
- `yarn start` to start the development watch mode
58+
- `yarn start` to start the watch mode
59+
60+
### wp-env
61+
62+
This plugin uses `wp-env` setup to for local environment.
63+
64+
- `wp-env start` to start the containers
65+
- `wp-env stop` to stop the containers
66+
67+
More details on how to access local environment can be found [here](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#quick-tldr-instructions).
5568

5669
## Linting and formatting
5770

5871
PHP
5972

6073
- `composer lint`
61-
- To auto fix the linting errors `composer lint:fix`
62-
63-
💡 [VSCode extension](https://marketplace.visualstudio.com/items?itemName=shevaua.phpcs) to auto format PHP files based on `phpcs.xml.dist` configuration
74+
- `composer lint:fix` to auto fix PHP linting errors.
6475

6576
JS
6677

6778
- `yarn lint:js`
68-
69-
💡 [VSCode extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) to auto format JS / TS files based on `.prettierrc.js` configuration
79+
- `yarn lint:js:fix` to auto fix JS linting errors.
7080

7181
CSS
7282

7383
- `yarn lint:css`
74-
- To auto fix the css linting errors `yarn lint:css:fix`
84+
- `yarn lint:css:fix` to auto fix CSS linting errors.
7585

7686
## Testing
7787

@@ -85,10 +95,10 @@ CSS
8595

8696
### JS
8797

88-
- Run `yarn test:js` which will run all jest and React Testing Library tests
98+
- Run `yarn test:js` to run all Jest and React Testing Library tests
8999

90100
### E2E
91101

92102
The E2E tests depends on `wp-env` setup. Ensure you run `wp-env start` before running the tests.
93103

94-
- Run `yarn test:e2e` which will run all Playwright e2e tests.
104+
- Run `yarn test:e2e` to run all Playwright e2e tests.

includes/Api/Flags.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use WP_Error;
1414
use WP_REST_Server;
1515
use WP_REST_Request;
16+
use CodeB\FeatureFlags\Flag;
1617

1718
/**
1819
* Class Settings
@@ -22,13 +23,6 @@
2223
*/
2324
class Flags {
2425

25-
/**
26-
* Name in options table.
27-
*
28-
* @var string $option_name
29-
*/
30-
public static $option_name = 'mr_feature_flags';
31-
3226
/**
3327
* Maximum allowed flags.
3428
*
@@ -83,7 +77,7 @@ public function register_routes(): void {
8377
* @return mixed List of flags.
8478
*/
8579
public function get_all_flags() {
86-
$flags = get_option( self::$option_name, [] );
80+
$flags = get_option( Flag::$option_name, [] );
8781
return rest_ensure_response( $flags );
8882
}
8983

@@ -102,14 +96,14 @@ public function post_flags( WP_REST_Request $request ) {
10296
/**
10397
* Filter to update max allowed feature flags.
10498
*/
105-
$max_allowed_flags = apply_filters( 'mr_feature_flags_max_allowed', self::$max_flags );
99+
$max_allowed_flags = apply_filters( 'codeb_feature_flags_max_allowed', self::$max_flags );
106100
if ( count( $input_data['flags'] ) > $max_allowed_flags ) {
107101
// translators: %d is a placeholder for the maximum allowed flags.
108102
$error_message = sprintf( __( 'Cannot add more than %d flags', 'codeb-feature-flags' ), $max_allowed_flags );
109103
return new WP_Error( 'flag_limit_exceeded', $error_message, array( 'status' => 400 ) );
110104
}
111105

112-
update_option( self::$option_name, $input_data['flags'] );
106+
update_option( Flag::$option_name, $input_data['flags'] );
113107
return rest_ensure_response(
114108
array(
115109
'status' => 200,

includes/Flag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Flag {
2323
*
2424
* @var string $option_name
2525
*/
26-
public static $option_name = 'mr_feature_flags';
26+
public static $option_name = 'codeb_feature_flags';
2727

2828

2929
/**

includes/Helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* This is the init file for the plugin
3+
* Helper class
44
*
55
* @package codeb-feature-flags
66
* @since 0.1.0
@@ -11,7 +11,7 @@
1111
namespace CodeB\FeatureFlags;
1212

1313
/**
14-
* Class FeatureFlags
14+
* Class Helper
1515
*
1616
* @package codeb-feature-flags
1717
* @since 0.1.0

includes/Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ public function register_settings() {
5252
* @return void
5353
*/
5454
public function render_page(): void {
55-
echo '<div id="mr_feature_flags_settings_screen"></div>';
55+
echo '<div id="codeb_feature_flags_settings_screen"></div>';
5656
}
5757
}

package.json

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,60 @@
11
{
2-
"name": "codeb-feature-flags",
3-
"version": "0.2.1",
4-
"description": "Allows developers to enable / disable features based on flags.",
5-
"scripts": {
6-
"start": "wp-scripts start",
7-
"build": "wp-scripts build",
8-
"lint:js": "wp-scripts lint-js",
9-
"lint:css": "wp-scripts lint-style",
10-
"lint:css:fix": "npm run lint:css -- --fix",
11-
"test:js": "wp-scripts test-unit-js",
12-
"test:watch": "wp-scripts test-unit-js --watch",
13-
"prepare": "husky",
14-
"wp-env": "wp-env start",
15-
"test:e2e": "npx playwright test --reporter=list"
16-
},
17-
"devDependencies": {
18-
"@playwright/test": "^1.42.0",
19-
"@testing-library/jest-dom": "^6.4.2",
20-
"@testing-library/react": "14.2.1",
21-
"@types/jest": "^29.5.12",
22-
"@types/node": "^20.11.20",
23-
"@types/react-syntax-highlighter": "^15.5.11",
24-
"@types/wordpress__components": "^23.0.11",
25-
"@wordpress/e2e-test-utils-playwright": "^0.20.0",
26-
"@wordpress/env": "^9.4.0",
27-
"@wordpress/eslint-plugin": "^17.9.0",
28-
"@wordpress/scripts": "^27.3.0",
29-
"eslint": "^8.57.0",
30-
"eslint-import-resolver-alias": "^1.1.2",
31-
"eslint-plugin-cypress": "^2.15.1",
32-
"eslint-plugin-import": "^2.29.1",
33-
"husky": "^9.0.11",
34-
"jest-environment-jsdom": "^29.7.0",
35-
"prettier": "^3.2.5"
36-
},
37-
"keywords": [],
38-
"author": "Mohan Raj <https://mohanraj.dev>",
39-
"license": "ISC",
40-
"dependencies": {
41-
"@wordpress/api-fetch": "^6.48.0",
42-
"@wordpress/components": "^27.0.0",
43-
"@wordpress/data": "^9.22.0",
44-
"@wordpress/dom-ready": "^3.52.0",
45-
"@wordpress/hooks": "^3.52.0",
46-
"@wordpress/i18n": "^4.52.0",
47-
"@wordpress/notices": "^4.20.0",
48-
"dotenv": "^16.4.5",
49-
"react": "18.2.0",
50-
"react-dom": "18.2.0",
51-
"react-syntax-highlighter": "^15.5.0",
52-
"react-test-renderer": "^18.2.0",
53-
"ts-loader": "^9.5.1",
54-
"typescript": "^5.3.3"
55-
}
56-
}
2+
"name": "codeb-feature-flags",
3+
"version": "0.3.0",
4+
"description": "Allows developers to enable / disable features based on flags.",
5+
"license": "ISC",
6+
"author": "Mohan Raj <https://mohanraj.dev>",
7+
"scripts": {
8+
"build": "wp-scripts build",
9+
"lint:css": "wp-scripts lint-style",
10+
"lint:css:fix": "npm run lint:css -- --fix",
11+
"lint:js": "wp-scripts lint-js",
12+
"lint:js:fix": "wp-scripts lint-js --fix",
13+
"prepare": "husky",
14+
"start": "wp-scripts start",
15+
"test:e2e": "npx playwright test --reporter=list",
16+
"test:js": "wp-scripts test-unit-js",
17+
"test:watch": "wp-scripts test-unit-js --watch",
18+
"version:major": "node ./scripts/version major",
19+
"version:minor": "node ./scripts/version minor",
20+
"version:patch": "node ./scripts/version patch",
21+
"wp-env": "wp-env start"
22+
},
23+
"dependencies": {
24+
"@wordpress/api-fetch": "^6.48.0",
25+
"@wordpress/components": "^27.0.0",
26+
"@wordpress/data": "^9.22.0",
27+
"@wordpress/dom-ready": "^3.52.0",
28+
"@wordpress/hooks": "^3.52.0",
29+
"@wordpress/i18n": "^4.52.0",
30+
"@wordpress/notices": "^4.20.0",
31+
"dotenv": "^16.4.5",
32+
"react": "18.2.0",
33+
"react-dom": "18.2.0",
34+
"react-syntax-highlighter": "^15.5.0",
35+
"react-test-renderer": "^18.2.0",
36+
"ts-loader": "^9.5.1",
37+
"typescript": "^5.3.3"
38+
},
39+
"devDependencies": {
40+
"@playwright/test": "^1.42.0",
41+
"@testing-library/jest-dom": "^6.4.2",
42+
"@testing-library/react": "14.2.1",
43+
"@types/jest": "^29.5.12",
44+
"@types/node": "^20.11.20",
45+
"@types/react-syntax-highlighter": "^15.5.11",
46+
"@types/wordpress__components": "^23.0.11",
47+
"@wordpress/e2e-test-utils-playwright": "^0.20.0",
48+
"@wordpress/env": "^9.4.0",
49+
"@wordpress/eslint-plugin": "^17.9.0",
50+
"@wordpress/scripts": "^27.3.0",
51+
"eslint": "^8.57.0",
52+
"eslint-import-resolver-alias": "^1.1.2",
53+
"eslint-plugin-cypress": "^2.15.1",
54+
"eslint-plugin-import": "^2.29.1",
55+
"husky": "^9.0.11",
56+
"jest-environment-jsdom": "^29.7.0",
57+
"prettier": "^3.2.5"
58+
},
59+
"keywords": []
60+
}

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default defineConfig({
1212
fullyParallel: true,
1313
forbidOnly: !!process.env.CI,
1414
retries: process.env.CI ? 2 : 0,
15-
workers: 4,
15+
workers: process.env.CI ? 4 : 1,
1616
reporter: 'html',
1717
use: {
1818
baseURL: process.env.WP_BASE_URL,

0 commit comments

Comments
 (0)