@wordpress/block-serialization-spec-parser 5.54.0 → 5.54.1-next.v.202609031004.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/block-serialization-spec-parser",
3
- "version": "5.54.0",
3
+ "version": "5.54.1-next.v.202609031004.0",
4
4
  "description": "Block serialization specification parser for WordPress posts.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -36,6 +36,9 @@
36
36
  "pegjs": "^0.10.0",
37
37
  "phpegjs": "^1.0.0-beta7"
38
38
  },
39
+ "devDependencies": {
40
+ "vitest": "^4.1.10"
41
+ },
39
42
  "publishConfig": {
40
43
  "access": "public"
41
44
  },
@@ -45,5 +48,5 @@
45
48
  "build:js": "pegjs --format commonjs -o ./parser.js ./grammar.pegjs",
46
49
  "build:php": "node bin/create-php-parser.js"
47
50
  },
48
- "gitHead": "5ef24f60261976bb198ad035db24bf81c1fb92b4"
51
+ "gitHead": "7275d6c6d93b542fca3cd98cdb9c7344ddd11e19"
49
52
  }
package/shared-tests.js CHANGED
@@ -1,4 +1,8 @@
1
- export const jsTester = ( parse ) => () => {
1
+ import { spawnSync } from 'node:child_process';
2
+
3
+ export const jsTester = ( parse, runner ) => () => {
4
+ runner ??= globalThis;
5
+ const { describe, expect, test } = runner;
2
6
  describe( 'output structure', () => {
3
7
  test( 'output is an array', () => {
4
8
  expect( parse( '' ) ).toEqual( expect.any( Array ) );
@@ -196,7 +200,9 @@ export const jsTester = ( parse ) => () => {
196
200
  '<p>Break me</p><!-- wp:block --><!-- /wp:block -->',
197
201
  ].forEach( ( input ) =>
198
202
  expect( parse( input ) ).toEqual( [
199
- expect.objectContaining( { innerHTML: '<p>Break me</p>' } ),
203
+ expect.objectContaining( {
204
+ innerHTML: '<p>Break me</p>',
205
+ } ),
200
206
  expect.objectContaining( {
201
207
  blockName: 'core/block',
202
208
  innerHTML: '',
@@ -233,7 +239,9 @@ export const jsTester = ( parse ) => () => {
233
239
  blockName: 'core/block',
234
240
  innerHTML: '',
235
241
  } ),
236
- expect.objectContaining( { innerHTML: '<p>Break me</p>' } ),
242
+ expect.objectContaining( {
243
+ innerHTML: '<p>Break me</p>',
244
+ } ),
237
245
  ] )
238
246
  ) );
239
247
  } );
@@ -319,44 +327,39 @@ export const jsTester = ( parse ) => () => {
319
327
  const hasPHP =
320
328
  'test' === process.env.NODE_ENV
321
329
  ? ( () => {
322
- const process = require( 'child_process' ).spawnSync(
323
- 'php',
324
- [ '-r', 'echo 1;' ],
325
- {
326
- encoding: 'utf8',
327
- }
328
- );
330
+ const phpProcess = spawnSync( 'php', [ '-r', 'echo 1;' ], {
331
+ encoding: 'utf8',
332
+ } );
329
333
 
330
- return process.status === 0 && process.stdout === '1';
334
+ return phpProcess.status === 0 && phpProcess.stdout === '1';
331
335
  } )()
332
336
  : false;
333
337
 
334
338
  // Skipping if `php` isn't available to us, such as in local dev without it
335
339
  // skipping preserves snapshots while commenting out or simply
336
- // not injecting the tests prompts `jest` to remove "obsolete snapshots"
337
- const makeTest = hasPHP
338
- ? // eslint-disable-next-line jest/valid-describe-callback, jest/valid-title
339
- ( ...args ) => describe( ...args )
340
- : // eslint-disable-next-line jest/no-disabled-tests, jest/valid-describe-callback, jest/valid-title
341
- ( ...args ) => describe.skip( ...args );
340
+ // not injecting the tests can prompt snapshot-aware runners to remove
341
+ // "obsolete snapshots"
342
+ const makeTest = ( describe ) =>
343
+ hasPHP
344
+ ? ( ...args ) => describe( ...args )
345
+ : ( ...args ) => describe.skip( ...args );
342
346
 
343
- export const phpTester = ( name, filename ) =>
344
- makeTest(
347
+ export const phpTester = ( name, filename, testRunner = globalThis ) => {
348
+ const { describe } = testRunner;
349
+ return makeTest( describe )(
345
350
  name,
346
351
  'test' === process.env.NODE_ENV
347
352
  ? jsTester( ( doc ) => {
348
- const process = require( 'child_process' ).spawnSync(
349
- 'php',
350
- [ '-f', filename ],
351
- {
352
- input: doc,
353
- encoding: 'utf8',
354
- timeout: 30 * 1000, // Abort after 30 seconds, that's too long anyway.
355
- }
356
- );
353
+ const phpProcess = spawnSync( 'php', [ '-f', filename ], {
354
+ input: doc,
355
+ encoding: 'utf8',
356
+ timeout: 30 * 1000, // Abort after 30 seconds, that's too long anyway.
357
+ } );
357
358
 
358
- if ( process.status !== 0 ) {
359
- throw new Error( process.stderr || process.stdout );
359
+ if ( phpProcess.status !== 0 ) {
360
+ throw new Error(
361
+ phpProcess.stderr || phpProcess.stdout
362
+ );
360
363
  }
361
364
 
362
365
  try {
@@ -367,16 +370,17 @@ export const phpTester = ( name, filename ) =>
367
370
  * This is an issue with the test runner, not with the parser.
368
371
  */
369
372
  return JSON.parse(
370
- process.stdout.replace(
373
+ phpProcess.stdout.replace(
371
374
  /"attrs":\s*\[\]/g,
372
375
  '"attrs":{}'
373
376
  )
374
377
  );
375
378
  } catch {
376
379
  throw new Error(
377
- 'failed to parse JSON:\n' + process.stdout
380
+ 'failed to parse JSON:\n' + phpProcess.stdout
378
381
  );
379
382
  }
380
- } )
383
+ }, testRunner )
381
384
  : () => {}
382
385
  );
386
+ };
package/test/index.js CHANGED
@@ -1,10 +1,15 @@
1
- import path from 'path';
2
- import { parse } from '../';
1
+ import { createRequire } from 'node:module';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { describe, expect, test } from 'vitest';
3
4
  import { jsTester, phpTester } from '../shared-tests';
5
+ const require = createRequire( import.meta.url );
6
+ const { parse } = require( '../parser.js' );
7
+ const testRunner = { describe, expect, test };
4
8
 
5
- describe( 'block-serialization-spec-parser-js', jsTester( parse ) ); // eslint-disable-line jest/valid-describe-callback
9
+ describe( 'block-serialization-spec-parser-js', jsTester( parse, testRunner ) );
6
10
 
7
11
  phpTester(
8
12
  'block-serialization-spec-parser-php',
9
- path.join( __dirname, 'test-parser.php' )
13
+ fileURLToPath( new URL( './test-parser.php', import.meta.url ) ),
14
+ testRunner
10
15
  );