-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
packages/scripts/scripts/test/__snapshots__/build-blocks-manifest.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`build-blocks-manifest script should generate expected blocks manifest 1`] = ` | ||
"<?php | ||
// This file is generated. Do not modify it manually. | ||
return array( | ||
'custom-header' => array( | ||
'$schema' => 'https://schemas.wp.org/trunk/block.json', | ||
'apiVersion' => 2, | ||
'name' => 'my-plugin/custom-header', | ||
'title' => 'Custom Header', | ||
'category' => 'text', | ||
'icon' => 'heading', | ||
'description' => 'A custom header block with color options.', | ||
'attributes' => array( | ||
'content' => array( | ||
'type' => 'string', | ||
'source' => 'html', | ||
'selector' => 'h2' | ||
), | ||
'textColor' => array( | ||
'type' => 'string' | ||
), | ||
'backgroundColor' => array( | ||
'type' => 'string' | ||
) | ||
), | ||
'supports' => array( | ||
'html' => false, | ||
'color' => array( | ||
'background' => true, | ||
'text' => true | ||
) | ||
), | ||
'textdomain' => 'my-plugin', | ||
'editorScript' => 'file:./index.js', | ||
'editorStyle' => 'file:./index.css', | ||
'style' => 'file:./style-index.css' | ||
), | ||
'image-gallery' => array( | ||
'$schema' => 'https://schemas.wp.org/trunk/block.json', | ||
'apiVersion' => 2, | ||
'name' => 'my-plugin/image-gallery', | ||
'title' => 'Image Gallery', | ||
'category' => 'media', | ||
'icon' => 'format-gallery', | ||
'description' => 'An image gallery block with customizable layout.', | ||
'attributes' => array( | ||
'images' => array( | ||
'type' => 'array', | ||
'default' => array( | ||
), | ||
'source' => 'query', | ||
'selector' => 'img', | ||
'query' => array( | ||
'url' => array( | ||
'type' => 'string', | ||
'source' => 'attribute', | ||
'attribute' => 'src' | ||
), | ||
'alt' => array( | ||
'type' => 'string', | ||
'source' => 'attribute', | ||
'attribute' => 'alt', | ||
'default' => '' | ||
), | ||
'id' => array( | ||
'type' => 'number', | ||
'source' => 'attribute', | ||
'attribute' => 'data-id' | ||
) | ||
) | ||
), | ||
'columns' => array( | ||
'type' => 'number', | ||
'default' => 3 | ||
), | ||
'imageCrop' => array( | ||
'type' => 'boolean', | ||
'default' => true | ||
) | ||
), | ||
'supports' => array( | ||
'align' => array( | ||
'wide', | ||
'full' | ||
) | ||
), | ||
'textdomain' => 'my-plugin', | ||
'editorScript' => 'file:./index.js', | ||
'editorStyle' => 'file:./index.css', | ||
'style' => 'file:./style-index.css' | ||
), | ||
'simple-button' => array( | ||
'$schema' => 'https://schemas.wp.org/trunk/block.json', | ||
'apiVersion' => 2, | ||
'name' => 'my-plugin/simple-button', | ||
'title' => 'Simple Button', | ||
'category' => 'design', | ||
'icon' => 'button', | ||
'description' => 'A simple button block.', | ||
'supports' => array( | ||
'html' => false | ||
), | ||
'textdomain' => 'my-plugin', | ||
'editorScript' => 'file:./index.js', | ||
'editorStyle' => 'file:./index.css', | ||
'style' => 'file:./style-index.css' | ||
) | ||
); | ||
" | ||
`; | ||
|
||
exports[`build-blocks-manifest script should handle empty input directory 1`] = ` | ||
"<?php | ||
// This file is generated. Do not modify it manually. | ||
return array( | ||
); | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const fs = require( 'fs' ); | ||
const path = require( 'path' ); | ||
const { execSync } = require( 'child_process' ); | ||
const rimraf = require( 'rimraf' ); | ||
|
||
const fixturesPath = path.join( | ||
__dirname, | ||
'fixtures', | ||
'build-blocks-manifest' | ||
); | ||
const outputPath = path.join( __dirname, 'build', 'test-blocks-manifest' ); | ||
|
||
describe( 'build-blocks-manifest script', () => { | ||
beforeAll( () => { | ||
if ( ! fs.existsSync( outputPath ) ) { | ||
fs.mkdirSync( outputPath, { recursive: true } ); | ||
} | ||
rimraf.sync( outputPath ); | ||
} ); | ||
|
||
afterAll( () => { | ||
rimraf.sync( outputPath ); | ||
} ); | ||
|
||
it( 'should generate expected blocks manifest', () => { | ||
const inputDir = path.join( fixturesPath, 'input' ); | ||
const outputFile = path.join( outputPath, 'blocks-manifest.php' ); | ||
|
||
// Run the build-blocks-manifest script | ||
const scriptPath = path.resolve( | ||
__dirname, | ||
'..', | ||
'build-blocks-manifest.js' | ||
); | ||
execSync( | ||
`node ${ scriptPath } --input=${ inputDir } --output=${ outputFile }` | ||
); | ||
|
||
const generatedContent = fs.readFileSync( outputFile, 'utf8' ); | ||
expect( generatedContent ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should handle empty input directory', () => { | ||
const emptyInputDir = path.join( fixturesPath, 'empty-input' ); | ||
const outputFile = path.join( outputPath, 'empty-blocks-manifest.php' ); | ||
|
||
// Run the build-blocks-manifest script with empty input | ||
const scriptPath = path.resolve( | ||
__dirname, | ||
'..', | ||
'build-blocks-manifest.js' | ||
); | ||
const result = execSync( | ||
`node ${ scriptPath } --input=${ emptyInputDir } --output=${ outputFile }`, | ||
{ encoding: 'utf8' } | ||
); | ||
|
||
// Check if warning message is displayed | ||
expect( result ).toContain( 'WARNING' ); | ||
expect( result ).toContain( 'No block.json files were found' ); | ||
|
||
// Read the generated file, compare with expected output | ||
const generatedContent = fs.readFileSync( outputFile, 'utf8' ); | ||
expect( generatedContent ).toMatchSnapshot(); | ||
} ); | ||
} ); |
33 changes: 33 additions & 0 deletions
33
packages/scripts/scripts/test/fixtures/build-blocks-manifest/input/custom-header/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "my-plugin/custom-header", | ||
"title": "Custom Header", | ||
"category": "text", | ||
"icon": "heading", | ||
"description": "A custom header block with color options.", | ||
"attributes": { | ||
"content": { | ||
"type": "string", | ||
"source": "html", | ||
"selector": "h2" | ||
}, | ||
"textColor": { | ||
"type": "string" | ||
}, | ||
"backgroundColor": { | ||
"type": "string" | ||
} | ||
}, | ||
"supports": { | ||
"html": false, | ||
"color": { | ||
"background": true, | ||
"text": true | ||
} | ||
}, | ||
"textdomain": "my-plugin", | ||
"editorScript": "file:./index.js", | ||
"editorStyle": "file:./index.css", | ||
"style": "file:./style-index.css" | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/scripts/scripts/test/fixtures/build-blocks-manifest/input/image-gallery/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "my-plugin/image-gallery", | ||
"title": "Image Gallery", | ||
"category": "media", | ||
"icon": "format-gallery", | ||
"description": "An image gallery block with customizable layout.", | ||
"attributes": { | ||
"images": { | ||
"type": "array", | ||
"default": [], | ||
"source": "query", | ||
"selector": "img", | ||
"query": { | ||
"url": { | ||
"type": "string", | ||
"source": "attribute", | ||
"attribute": "src" | ||
}, | ||
"alt": { | ||
"type": "string", | ||
"source": "attribute", | ||
"attribute": "alt", | ||
"default": "" | ||
}, | ||
"id": { | ||
"type": "number", | ||
"source": "attribute", | ||
"attribute": "data-id" | ||
} | ||
} | ||
}, | ||
"columns": { | ||
"type": "number", | ||
"default": 3 | ||
}, | ||
"imageCrop": { | ||
"type": "boolean", | ||
"default": true | ||
} | ||
}, | ||
"supports": { | ||
"align": [ "wide", "full" ] | ||
}, | ||
"textdomain": "my-plugin", | ||
"editorScript": "file:./index.js", | ||
"editorStyle": "file:./index.css", | ||
"style": "file:./style-index.css" | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/scripts/scripts/test/fixtures/build-blocks-manifest/input/simple-button/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "my-plugin/simple-button", | ||
"title": "Simple Button", | ||
"category": "design", | ||
"icon": "button", | ||
"description": "A simple button block.", | ||
"supports": { | ||
"html": false | ||
}, | ||
"textdomain": "my-plugin", | ||
"editorScript": "file:./index.js", | ||
"editorStyle": "file:./index.css", | ||
"style": "file:./style-index.css" | ||
} |