@wordpress/block-serialization-spec-parser 5.54.1-next.v.202608281122.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 +5 -2
- package/shared-tests.js +37 -33
- package/test/index.js +9 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-serialization-spec-parser",
|
|
3
|
-
"version": "5.54.1-next.v.
|
|
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": "
|
|
51
|
+
"gitHead": "7275d6c6d93b542fca3cd98cdb9c7344ddd11e19"
|
|
49
52
|
}
|
package/shared-tests.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
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( {
|
|
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( {
|
|
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
|
|
323
|
-
'
|
|
324
|
-
|
|
325
|
-
{
|
|
326
|
-
encoding: 'utf8',
|
|
327
|
-
}
|
|
328
|
-
);
|
|
330
|
+
const phpProcess = spawnSync( 'php', [ '-r', 'echo 1;' ], {
|
|
331
|
+
encoding: 'utf8',
|
|
332
|
+
} );
|
|
329
333
|
|
|
330
|
-
return
|
|
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
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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
|
-
|
|
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
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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 (
|
|
359
|
-
throw new Error(
|
|
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
|
-
|
|
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' +
|
|
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
|
|
2
|
-
import {
|
|
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 ) );
|
|
9
|
+
describe( 'block-serialization-spec-parser-js', jsTester( parse, testRunner ) );
|
|
6
10
|
|
|
7
11
|
phpTester(
|
|
8
12
|
'block-serialization-spec-parser-php',
|
|
9
|
-
|
|
13
|
+
fileURLToPath( new URL( './test-parser.php', import.meta.url ) ),
|
|
14
|
+
testRunner
|
|
10
15
|
);
|