Skip to content

Commit 4d8ddd9

Browse files
authored
[Blueprints] Add dispose functions in afterEach hooks in tests (#2921)
## Motivation for the change, related issues Based on [this comment](#2910 (comment)) The `nx run playground-blueprints:"test:vite"` command systematically fails due to 10 seconds timeout on the `should activate a plugin file located in the plugins directory` test. IIRC I also faced that situation with the PHP.wasm node tests and adding dispose methods made the trick. Let's see if it works here too. ## Implementation details Adding the following portion of code where necessary : ```typescript afterEach(async () => { php.exit(); await handler[Symbol.asyncDispose](); }); ``` ## Testing Instructions CI
1 parent f6196cc commit 4d8ddd9

19 files changed

+76
-9
lines changed

packages/playground/blueprints/src/lib/steps/activate-plugin.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ describe('Blueprint step activatePlugin()', () => {
2525
php = await handler.getPrimaryPhp();
2626
});
2727

28+
afterEach(async () => {
29+
php.exit();
30+
await handler[Symbol.asyncDispose]();
31+
});
32+
2833
it('should activate a plugin file located in the plugins directory', async () => {
2934
const docroot = handler.documentRoot;
3035
php.writeFile(

packages/playground/blueprints/src/lib/steps/activate-theme.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ describe('Blueprint step activateTheme()', () => {
2525
php = await handler.getPrimaryPhp();
2626
});
2727

28+
afterEach(async () => {
29+
php.exit();
30+
await handler[Symbol.asyncDispose]();
31+
});
32+
2833
it('should activate the theme', async () => {
2934
const docroot = php.documentRoot;
3035
php.mkdir(`${docroot}/wp-content/themes/test-theme`);

packages/playground/blueprints/src/lib/steps/define-wp-config-consts.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ describe('defineBeforeRun', () => {
1010
php = new PHP(await loadNodeRuntime(RecommendedPHPVersion));
1111
});
1212

13+
afterEach(() => {
14+
php.exit();
15+
});
16+
1317
it('should define the constants before running the requested script', async () => {
1418
const constants = {
1519
SITE_URL: 'http://test.url',

packages/playground/blueprints/src/lib/steps/import-theme-starter-content.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ describe('Blueprint step importThemeStarterContent', () => {
2424
php = await handler.getPrimaryPhp();
2525
});
2626

27+
afterEach(async () => {
28+
php.exit();
29+
await handler[Symbol.asyncDispose]();
30+
});
31+
2732
it('Should import theme starter content', async () => {
2833
const docroot = php.documentRoot;
2934
// Create a test theme with starter content, Must have at a minimum

packages/playground/blueprints/src/lib/steps/import-wxr.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ describe('Blueprint step importWxr', () => {
9191
});
9292
}, 30_000);
9393

94+
afterEach(async () => {
95+
php.exit();
96+
await handler[Symbol.asyncDispose]();
97+
});
98+
9499
it(
95100
'Should import a WXR file with JSON-encoded UTF-8 characters',
96101
async () => {
@@ -270,7 +275,7 @@ describe('Blueprint step importWxr', () => {
270275
const result = await php.run({
271276
code: `<?php
272277
require getenv('DOCROOT') . '/wp-load.php';
273-
278+
274279
// Get all imported posts
275280
$posts = get_posts([
276281
'post_type' => ['post', 'page'],
@@ -279,10 +284,10 @@ describe('Blueprint step importWxr', () => {
279284
'orderby' => 'ID',
280285
'order' => 'ASC'
281286
]);
282-
287+
283288
// Get admin user info
284289
$admin_user = get_user_by('login', 'admin');
285-
290+
286291
$post_authors = [];
287292
foreach ($posts as $post) {
288293
$author = get_user_by('ID', $post->post_author);
@@ -295,7 +300,7 @@ describe('Blueprint step importWxr', () => {
295300
'author_display_name' => $author ? $author->display_name : null,
296301
];
297302
}
298-
303+
299304
echo json_encode([
300305
'admin_user_id' => $admin_user ? $admin_user->ID : null,
301306
'admin_user_login' => $admin_user ? $admin_user->user_login : null,

packages/playground/blueprints/src/lib/steps/install-plugin.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ async function zipFiles(
1414
const zipFilePath = `/${zipFileName}`;
1515

1616
await php.run({
17-
code: `<?php $zip = new ZipArchive();
18-
$zip->open("${zipFilePath}", ZIPARCHIVE::CREATE);
17+
code: `<?php $zip = new ZipArchive();
18+
$zip->open("${zipFilePath}", ZIPARCHIVE::CREATE);
1919
$files = ${phpVar(files)};
2020
foreach($files as $path => $content) {
2121
$zip->addFromString($path, $content);
@@ -86,6 +86,10 @@ describe('Blueprint step installPlugin', () => {
8686
installedPluginPath = `${pluginsPath}/${pluginName}`;
8787
});
8888

89+
afterEach(() => {
90+
php.exit();
91+
});
92+
8993
it('should install a plugin', async () => {
9094
await installPlugin(php, {
9195
pluginData: await zipFiles(php, zipFileName, {

packages/playground/blueprints/src/lib/steps/install-theme.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ describe('Blueprint step installTheme', () => {
4646
expect(php.fileExists(zipFilePath)).toBe(true);
4747
});
4848

49-
afterEach(() => {
49+
afterEach(async () => {
5050
php.exit();
51+
await handler[Symbol.asyncDispose]();
5152
});
5253

5354
const expectedThemeIndexPhpPath =
@@ -179,7 +180,11 @@ describe('Blueprint step installTheme', () => {
179180
targetFolderName: 'test-expected-theme',
180181
},
181182
});
182-
expect(php.fileExists(`${rootPath}/wp-content/themes/test-expected-theme/`)).toBe(true);
183+
expect(
184+
php.fileExists(
185+
`${rootPath}/wp-content/themes/test-expected-theme/`
186+
)
187+
).toBe(true);
183188
});
184189
});
185190
});

packages/playground/blueprints/src/lib/steps/login.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ describe('Blueprint step login', () => {
2626
php = await handler.getPrimaryPhp();
2727
});
2828

29+
afterEach(async () => {
30+
php.exit();
31+
await handler[Symbol.asyncDispose]();
32+
});
33+
2934
const requestFollowRedirects = async (request: PHPRequest) => {
3035
let response = await handler.request(request);
3136
while (response.httpStatusCode === 302) {

packages/playground/blueprints/src/lib/steps/mkdir.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('Blueprint step mkdir', () => {
1616

1717
afterEach(() => {
1818
loggerErrorSpy.mockRestore();
19+
php.exit();
1920
});
2021

2122
it('should create a directory', async () => {

packages/playground/blueprints/src/lib/steps/mv.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('Blueprint step mv()', () => {
1818

1919
afterEach(() => {
2020
loggerErrorSpy.mockRestore();
21+
php.exit();
2122
});
2223

2324
it('should move a file', async () => {

0 commit comments

Comments
 (0)