Skip to content

Commit b752009

Browse files
committed
Update local dev and test setup
- Update dependencies - Test with PHP 7.4 and 8.4 - E2E tests with Playwright and WordPress Playground
1 parent 567b2e4 commit b752009

File tree

9 files changed

+79
-93
lines changed

9 files changed

+79
-93
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
/artifacts
12
/publish
23
/vendor
34
node_modules
45
*.log
56
*.local.js
67

78
# Ignore lock files to allow any package manager
9+
bun.lock
810
bun.lockb
911
composer.lock
1012
package-lock.json

.wp-env.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
{
22
"core": "WordPress/WordPress",
33
"phpVersion": "8.2",
4-
"plugins": [
5-
"."
6-
],
7-
"config": {
8-
"WP_DEBUG": true,
9-
"WP_DEBUG_LOG": true
10-
},
4+
"plugins": ["."],
115
"mappings": {
6+
"wp-content/tangible": "./vendor/tangible",
127
"wp-content/plugins/advanced-custom-fields": "./vendor/tangible-dev/advanced-custom-fields",
138
"wp-content/plugins/beaver-builder-lite-version": "./vendor/tangible-dev/beaver-builder-lite-version",
149
"wp-content/plugins/elementor": "./vendor/tangible-dev/elementor",
15-
"wp-content/plugins/tangible-e2e-plugin": "./vendor/tangible/template-system/framework/env/e2e-plugin",
16-
"wp-content/themes/empty-block-theme": "./vendor/tangible/template-system/framework/empty-block-theme"
10+
"wp-content/plugins/tangible-e2e-plugin": "./vendor/tangible/framework/env/e2e-plugin",
11+
"wp-content/themes/empty-block-theme": "./vendor/tangible/framework/empty-block-theme"
1712
}
1813
}

blueprint.dev.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
{
2-
"landingPage": "/wp-admin/edit.php?post_type=tangible_template",
2+
"landingPage": "/wp-admin/options-general.php?page=tangible-loops-and-logic-settings&dismiss_admin_notice=true",
33
"steps": [
4+
{
5+
"step": "setSiteOptions",
6+
"options": {
7+
"blogname": "Loops & Logic",
8+
"blogdescription": ""
9+
}
10+
},
411
{
512
"step": "defineWpConfigConsts",
613
"consts": {
7-
"WP_DEBUG": true
14+
"WP_DEBUG": true
815
},
916
"method": "rewrite-wp-config"
1017
},
1118
{
12-
"step": "login",
13-
"username": "admin",
14-
"password": "password"
15-
},
19+
"step": "login",
20+
"username": "admin"
21+
},
1622
{
1723
"step": "activatePlugin",
1824
"pluginPath": "/var/www/html/wp-content/plugins/tangible-e2e-plugin"

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"tangible/framework": "dev-main",
1919
"tangible/template-system": "dev-main"
2020
},
21-
"require-dev": {},
21+
"require-dev": {
22+
"phpunit/phpunit": "9.6.x-dev",
23+
"yoast/phpunit-polyfills": "2.x-dev"
24+
},
2225
"minimum-stability": "dev"
2326
}

package.json

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"name": "tangible-loops-and-logic",
33
"type": "module",
44
"private": true,
5+
"homepage": "https://github.com/tangibleinc/loops-and-logic",
6+
"repository": {
7+
"url": "git+ssh://git@github.com/tangibleinc/loops-and-logic.git"
8+
},
59
"scripts": {
610
"start": "wp-now start --blueprint=blueprint.dev.json",
711
"dev": "concurrently --raw 'roll dev' 'npm run start'",
@@ -14,10 +18,21 @@
1418
"archive": "roll archive && rm -rf publish/tangible-loops-and-logic && unzip publish/tangible-loops-and-logic.zip -d publish/ && npm run test:archive",
1519
"// Test": "",
1620
"test": "roll run tests/index.ts",
17-
"test:all": "npm run test && npm run test:8.3 && npm run e2e",
18-
"test:8.3": "roll run tests/index.ts PHP_VERSION=8.3",
21+
"test:all": "npm run test:7.4 && npm run test:8.4 && npm run e2e",
22+
"test:7.4": "roll run tests/index.ts PHP_VERSION=7.4",
23+
"test:8.4": "roll run tests/index.ts PHP_VERSION=8.4",
1924
"test:archive": "roll run tests/index.ts TEST_ARCHIVE=1",
20-
"e2e": "playwright test --config tests/e2e/playwright.config.js",
25+
"-- Local environment --": "https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env",
26+
"env": "wp-env",
27+
"env:start": "wp-env start",
28+
"env:stop": "wp-env stop",
29+
"env:test": "PLUGIN=tangible-loops-and-logic; wp-env run tests-cli wp plugin activate $PLUGIN && wp-env run tests-wordpress /var/www/html/wp-content/plugins/$PLUGIN/vendor/bin/phpunit --testdox -c /var/www/html/wp-content/plugins/$PLUGIN/phpunit.xml --verbose",
30+
"env:test:7.4": "WP_ENV_PHP_VERSION=7.4 wp-env start && npm run env:test",
31+
"env:test:8.2": "WP_ENV_PHP_VERSION=8.2 wp-env start && npm run env:test",
32+
"env:destroy": "wp-env destroy",
33+
"env:clean": "wp-env clean all",
34+
"-- End-to-end testing --": "https://playwright.dev/",
35+
"e2e": "playwright test --config tests/playwright.config.js",
2136
"e2e:install": "playwright install chromium",
2237
"e2e:debug": "npm run e2e -- --debug",
2338
"e2e:ui": "npm run e2e -- --ui",
@@ -26,15 +41,16 @@
2641
"dependencies": {
2742
},
2843
"devDependencies": {
29-
"@playwright/test": "^1.49.0",
30-
"@tangible/now": "^1.1.3",
44+
"@playwright/test": "^1.50.0",
45+
"@tangible/env": "^2025.1.30",
46+
"@tangible/now": "^2.0.3",
3147
"@tangible/roller": "^2.1.4",
32-
"@wordpress/e2e-test-utils-playwright": "^1.12.0",
48+
"@wordpress/e2e-test-utils-playwright": "^1.16.0",
49+
"@wordpress/env": "^10.16.0",
3350
"chokidar-cli": "^3.0.0",
34-
"concurrently": "^9.1.0",
51+
"concurrently": "^9.1.2",
3552
"testra": "^2.1.4"
3653
},
37-
"homepage": "",
3854
"author": "Team Tangible",
3955
"license": "MIT",
4056
"keywords": []

tests/.wp-env.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
2+
"extends": "../.wp-env.json",
23
"mappings": {
3-
"wp-content/plugins/advanced-custom-fields": "../vendor/tangible-dev/advanced-custom-fields",
4-
"wp-content/plugins/beaver-builder-lite-version": "../vendor/tangible-dev/beaver-builder-lite-version",
5-
"wp-content/plugins/elementor": "../vendor/tangible-dev/elementor",
6-
"wp-content/plugins/tangible-loops-and-logic": "..",
7-
"wp-content/plugins/tangible-e2e-plugin": "../vendor/tangible/template-system/framework/env/e2e-plugin",
8-
"wp-content/themes/empty-block-theme": "../vendor/tangible/template-system/framework/empty-block-theme"
4+
"wp-content/plugins/tangible-loops-and-logic": ".."
95
}
106
}

tests/e2e/index.js

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { describe, test, expect } from '../../vendor/tangible/template-system/framework/playwright/index.js'
1+
import { describe, test, expect } from '@tangible/env/playwright'
22

33
/**
4-
* Tests to exercise the frontend and admin features of the Template System.
4+
* Tests to exercise the frontend and admin features of Tangible Blocks.
55
*
6-
* To interact with pages, locate elements by user-visible locators like
6+
* Note: To interact with pages, locate elements by user-visible locators like
77
* accessible role, instead of CSS selectors which can change.
88
*
99
* @see https://playwright.dev/docs/locators#locating-elements
@@ -22,17 +22,13 @@ describe('Admin', () => {
2222
})
2323

2424
const plugins = [
25-
['Loops & Logic', 'tangible-loops-and-logic/tangible-loops-and-logic'],
26-
['E2E', 'e2e-plugin/index'],
27-
28-
['Advanced Custom Fields', 'advanced-custom-fields/acf'],
25+
['Tangible Loops & Logic', 'tangible-loops-and-logic/tangible-loops-and-logic'],
26+
['Tangible E2E', 'tangible-e2e-plugin/index'],
2927
['Elementor', 'elementor/elementor'],
3028
['Beaver Builder', 'beaver-builder-lite-version/fl-builder'],
31-
// ['WP Fusion Lite', 'wp-fusion-lite/wp-fusion-lite']
3229
]
3330

3431
for (const [pluginTitle, pluginBasename] of plugins) {
35-
3632
test(`${pluginTitle} installed`, async ({ admin, page, requestUtils }) => {
3733
await admin.visitAdminPage('/')
3834

@@ -41,66 +37,42 @@ describe('Admin', () => {
4137
// })
4238
// expect(plugins).toContain(pluginBasename)
4339
// console.log('plugins', plugins)
44-
try {
45-
const result = await requestUtils.rest({
46-
path: `wp/v2/plugins/${pluginBasename}`,
47-
})
48-
// console.log('plugin', result)
49-
50-
expect(result.plugin).toBe(pluginBasename)
51-
} catch (e) {
52-
if (e.code === 'rest_plugin_not_found') {
53-
console.log(`Optional plugin ${pluginTitle} is not installed`)
54-
} else {
55-
console.error(e)
56-
}
57-
}
40+
41+
const result = await requestUtils.rest({
42+
path: `wp/v2/plugins/${pluginBasename}`,
43+
})
44+
// console.log('plugin', result)
45+
46+
expect(result.plugin).toBe(pluginBasename)
5847
})
5948

60-
test(`Activate ${pluginTitle}`, async ({
61-
admin,
62-
page,
63-
request,
64-
requestUtils,
65-
}) => {
49+
test(`Activate ${pluginTitle}`, async ({ admin, page, request, requestUtils }) => {
6650
await admin.visitAdminPage('plugins.php')
6751

6852
// See if plugin is active or not
69-
const pluginClasses = await page.evaluate(
70-
({ pluginBasename }) => {
71-
const $row = document.querySelector(
72-
`[data-plugin="${pluginBasename}.php"]`,
73-
)
74-
if (!$row) return []
75-
return [...$row?.classList]
76-
},
77-
{ pluginBasename },
78-
)
79-
80-
if (pluginTitle !== 'Template System' && !pluginClasses.length) {
81-
return
82-
}
53+
const pluginClasses = await page.evaluate(({ pluginBasename }) => {
54+
const $row = document.querySelector(
55+
`[data-plugin="${pluginBasename}.php"]`
56+
)
57+
return [...$row.classList]
58+
}, { pluginBasename })
8359

8460
if (!pluginClasses.includes('active')) {
8561
await expect(pluginClasses).toContain('inactive')
8662

8763
// Find the Activate link
8864

89-
const activateLink = await page.evaluate(
90-
({ pluginBasename }) => {
91-
const $row = document.querySelector(
92-
`[data-plugin="${pluginBasename}.php"]`,
93-
)
94-
const $activate = $row.querySelector('a.edit')
95-
return $activate?.href
96-
},
97-
{ pluginBasename },
98-
)
65+
const activateLink = await page.evaluate(({ pluginBasename }) => {
66+
const $row = document.querySelector(
67+
`[data-plugin="${pluginBasename}.php"]`
68+
)
69+
const $activate = $row.querySelector('a.edit')
70+
return $activate?.href
71+
}, { pluginBasename })
9972

10073
await expect(activateLink).toBeTruthy()
10174

10275
// Make a POST request
103-
10476
await request.post(activateLink)
10577
}
10678

@@ -239,5 +211,4 @@ test('Code editor', async ({ admin, page }) => {
239211
() => Boolean(window.Tangible && window.Tangible.TemplateSystem && window.Tangible.TemplateSystem.CodeEditor)
240212
)).toBe(true)
241213

242-
243214
})

tests/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, is, ok, run } from 'testra'
2-
import { getServer } from '../vendor/tangible/template-system/framework/env'
2+
import { getServer } from '@tangible/env'
33

44
async function ensurePlugin({ wpx }) {
55
return wpx/* php */ `
@@ -39,11 +39,10 @@ export default run(async () => {
3939
setSiteTemplate,
4040
resetSiteTemplate,
4141
} = await getServer({
42-
phpVersion: process.env.PHP_VERSION || '7.4',
42+
phpVersion: process.env.PHP_VERSION || '8.2',
4343
mappings: process.env.TEST_ARCHIVE
4444
? {
45-
'wp-content/plugins/tangible-loops-and-logic':
46-
'../publish/tangible-loops-and-logic',
45+
'wp-content/plugins/tangible-loops-and-logic': '../publish/tangible-loops-and-logic',
4746
}
4847
: {},
4948
reset: true,
@@ -55,6 +54,4 @@ export default run(async () => {
5554
let result = await ensurePlugin({ wpx })
5655
is(true, result, 'activate plugin')
5756
})
58-
59-
await import(`../vendor/tangible/template-system/tests/index.ts`)
6057
})

tests/playwright.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import path, { dirname } from 'node:path'
22
import { fileURLToPath } from 'url'
3-
import { createConfig } from '../vendor/tangible/template-system/framework/playwright/config.js'
3+
import { createConfig } from '@tangible/env/playwright/config'
44

55
const __dirname = dirname(fileURLToPath(import.meta.url))
66

77
export default createConfig({
88
testDir: __dirname,
9-
testMatch: 'e2e/**/*.js'
9+
testMatch: 'e2e/**/*.js',
1010
})

0 commit comments

Comments
 (0)