Skip to content

Commit

Permalink
Fix fixture serialization with double newline ending (#2069)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth authored and nylen committed Jul 30, 2017
1 parent 0220853 commit b948f6b
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 19 deletions.
6 changes: 4 additions & 2 deletions blocks/test/fixtures/core__cover-text.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[
{
"uid": "_uid_0",
"isValid": false,
"name": "core/cover-text",
"isValid": false,
"attributes": {
"backgroundColor": "#fcb900",
"content": [
[ "Text with color." ]
[
"Text with color."
]
]
},
"originalContent": "<div style=\"background-color:#fcb900\"><p>Text with color.</p></div>"
Expand Down
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core__latest-posts.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:core/latest-posts {"postsToShow":5,"displayPostDate":true} /-->
<!-- wp:core/latest-posts {"postsToShow":5,"displayPostDate":false} /-->
6 changes: 3 additions & 3 deletions blocks/test/fixtures/core__latest-posts.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"name": "core/latest-posts",
"isValid": true,
"attributes": {
"columns": 3,
"postsToShow": 5,
"displayPostDate": true,
"layout": "list"
"displayPostDate": false,
"layout": "list",
"columns": 3
}
}
]
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core__latest-posts.parsed.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"blockName": "core/latest-posts",
"attrs": {
"postsToShow": 5,
"displayPostDate": true
"displayPostDate": false
},
"rawContent": ""
},
Expand Down
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core__latest-posts.serialized.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:core/latest-posts {"displayPostDate":true} /-->
<!-- wp:core/latest-posts /-->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:core/latest-posts {"postsToShow":5,"displayPostDate":true} /-->
13 changes: 13 additions & 0 deletions blocks/test/fixtures/core__latest-posts__displayPostDate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"uid": "_uid_0",
"name": "core/latest-posts",
"isValid": true,
"attributes": {
"postsToShow": 5,
"displayPostDate": true,
"layout": "list",
"columns": 3
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"blockName": "core/latest-posts",
"attrs": {
"postsToShow": 5,
"displayPostDate": true
},
"rawContent": ""
},
{
"attrs": {},
"rawContent": "\n"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:core/latest-posts {"displayPostDate":true} /-->
4 changes: 2 additions & 2 deletions blocks/test/fixtures/core__text__align-right.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"name": "core/text",
"isValid": true,
"attributes": {
"dropCap": false,
"align": "right",
"content": [
[
"... like this one, which is separate from the above and right aligned."
]
],
"dropCap": false
]
}
}
]
26 changes: 17 additions & 9 deletions blocks/test/full-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import fs from 'fs';
import path from 'path';
import { uniq, isObject, omit, startsWith } from 'lodash';
import { uniq, isObject, omit, startsWith, get } from 'lodash';
import { format } from 'util';

/**
Expand Down Expand Up @@ -172,7 +172,7 @@ describe( 'full post content fixture', () => {

if ( ! serializedExpected ) {
if ( process.env.GENERATE_MISSING_FIXTURES ) {
serializedExpected = serializedActual + '\n';
serializedExpected = serializedActual;
writeFixtureFile( f + '.serialized.html', serializedExpected );
} else {
throw new Error(
Expand Down Expand Up @@ -204,15 +204,23 @@ describe( 'full post content fixture', () => {
startsWith( basename, nameToFilename + '__' )
) )
.map( basename => {
const filename = basename + '.html';
const parsedBlockFilename = basename + '.json';
// The file that contains the input HTML for this test.
const inputFilename = basename + '.html';
// The parser output for this test. For missing files,
// JSON.parse( null ) === null.
const parserOutput = JSON.parse(
readFixtureFile( basename + '.json' )
);
// The name of the first block that this fixture file
// contains (if any).
const firstBlock = get( parserOutput, [ '0', 'name' ], null );
return {
filename,
contents: readFixtureFile( filename ),
parsed: JSON.parse( readFixtureFile( parsedBlockFilename ) )[ 0 ],
filename: inputFilename,
parserOutput,
firstBlock,
};
} )
.filter( fixture => fixture.contents !== null );
.filter( fixture => fixture.parserOutput !== null );

if ( ! foundFixtures.length ) {
errors.push( format(
Expand All @@ -223,7 +231,7 @@ describe( 'full post content fixture', () => {
}

foundFixtures.forEach( fixture => {
if ( name !== fixture.parsed.name ) {
if ( name !== fixture.firstBlock ) {
errors.push( format(
'Expected fixture file \'%s\' to test the \'%s\' block.',
fixture.filename,
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
"dev": "cross-env BABEL_ENV=default webpack --watch",
"test": "npm run lint && npm run test-unit",
"ci": "concurrently \"npm run lint && npm run build\" \"npm run test-unit:coverage-ci\"",
"fixtures:clean": "rimraf \"blocks/test/fixtures/*.+(json|serialized.html)\"",
"fixtures:generate": "GENERATE_MISSING_FIXTURES=y npm run test-unit",
"fixtures:regenerate": "npm run fixtures:clean && npm run fixtures:generate",
"package-plugin": "./bin/build-plugin-zip.sh",
"docs-start": "./docutron/bin/cli.js start",
"docs-build": "./docutron/bin/cli.js build",
Expand Down

0 comments on commit b948f6b

Please sign in to comment.