From 8143584730ca3ea963d32a1800e35198f3dd380f Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 28 Jul 2017 09:28:18 -0400 Subject: [PATCH 01/10] Add npm scripts for (re)generating fixtures --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 634986b6a4ba90..a95cd4ad975bcd 100644 --- a/package.json +++ b/package.json @@ -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", From e689050cccba55b46c0fec57c53d6cfbb0da4d00 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 28 Jul 2017 09:28:35 -0400 Subject: [PATCH 02/10] Ensure serialized fixtures includes single newline ending --- blocks/test/full-content.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/test/full-content.js b/blocks/test/full-content.js index e13392673411b7..f22a4df584a589 100644 --- a/blocks/test/full-content.js +++ b/blocks/test/full-content.js @@ -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( From d0d341a26199d04ca424c41a67c4b523a0e18459 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 28 Jul 2017 09:29:18 -0400 Subject: [PATCH 03/10] Update revised fixtures --- blocks/test/fixtures/core__cover-text.json | 6 ++++-- blocks/test/fixtures/core__latest-posts.json | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/blocks/test/fixtures/core__cover-text.json b/blocks/test/fixtures/core__cover-text.json index b6e9e0d51346f3..74bf459027e959 100644 --- a/blocks/test/fixtures/core__cover-text.json +++ b/blocks/test/fixtures/core__cover-text.json @@ -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": "

Text with color.

" diff --git a/blocks/test/fixtures/core__latest-posts.json b/blocks/test/fixtures/core__latest-posts.json index 153471c7c68270..c1e9e6f8d44334 100644 --- a/blocks/test/fixtures/core__latest-posts.json +++ b/blocks/test/fixtures/core__latest-posts.json @@ -4,10 +4,10 @@ "name": "core/latest-posts", "isValid": true, "attributes": { - "columns": 3, "postsToShow": 5, "displayPostDate": false, - "layout": "list" + "layout": "list", + "columns": 3 } } ] From f02dfe15033c21ad01ab44c306aa52be74cd065f Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 30 Jul 2017 18:22:30 +0100 Subject: [PATCH 04/10] Try: configure codecov.io to ignore PRs that do not change coverage --- codecov.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000000000..ba6f0b2b6e5eac --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ +comment: + require_changes: true From 8c7f3171eb8c64723c7b8eaab1ab29dd525e973d Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 30 Jul 2017 20:27:01 +0100 Subject: [PATCH 05/10] Fix the tests --- blocks/test/fixtures/core__latest-posts.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/test/fixtures/core__latest-posts.json b/blocks/test/fixtures/core__latest-posts.json index c1e9e6f8d44334..238718c80ea868 100644 --- a/blocks/test/fixtures/core__latest-posts.json +++ b/blocks/test/fixtures/core__latest-posts.json @@ -5,7 +5,7 @@ "isValid": true, "attributes": { "postsToShow": 5, - "displayPostDate": false, + "displayPostDate": true, "layout": "list", "columns": 3 } From 546c984d198018eb2a83fe0123d6d7d1ea4f0ee4 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 30 Jul 2017 20:51:28 +0100 Subject: [PATCH 06/10] Update revised fixtures again --- blocks/test/fixtures/core__text__align-right.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/test/fixtures/core__text__align-right.json b/blocks/test/fixtures/core__text__align-right.json index 73496b8ab977a3..176a94f69cbdfd 100644 --- a/blocks/test/fixtures/core__text__align-right.json +++ b/blocks/test/fixtures/core__text__align-right.json @@ -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 + ] } } ] From 0fdda96fbad4a63c1ba0fa7f06a0a538c31d07b4 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 30 Jul 2017 20:54:03 +0100 Subject: [PATCH 07/10] Simplify the first `core/latest-posts` fixture --- blocks/test/fixtures/core__latest-posts.html | 2 +- blocks/test/fixtures/core__latest-posts.json | 2 +- blocks/test/fixtures/core__latest-posts.parsed.json | 2 +- blocks/test/fixtures/core__latest-posts.serialized.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/blocks/test/fixtures/core__latest-posts.html b/blocks/test/fixtures/core__latest-posts.html index d3128a66820632..99d215f58affad 100644 --- a/blocks/test/fixtures/core__latest-posts.html +++ b/blocks/test/fixtures/core__latest-posts.html @@ -1 +1 @@ - + diff --git a/blocks/test/fixtures/core__latest-posts.json b/blocks/test/fixtures/core__latest-posts.json index 238718c80ea868..c1e9e6f8d44334 100644 --- a/blocks/test/fixtures/core__latest-posts.json +++ b/blocks/test/fixtures/core__latest-posts.json @@ -5,7 +5,7 @@ "isValid": true, "attributes": { "postsToShow": 5, - "displayPostDate": true, + "displayPostDate": false, "layout": "list", "columns": 3 } diff --git a/blocks/test/fixtures/core__latest-posts.parsed.json b/blocks/test/fixtures/core__latest-posts.parsed.json index c0b53e30ca56b6..ac3a8dba1cc674 100644 --- a/blocks/test/fixtures/core__latest-posts.parsed.json +++ b/blocks/test/fixtures/core__latest-posts.parsed.json @@ -3,7 +3,7 @@ "blockName": "core/latest-posts", "attrs": { "postsToShow": 5, - "displayPostDate": true + "displayPostDate": false }, "rawContent": "" }, diff --git a/blocks/test/fixtures/core__latest-posts.serialized.html b/blocks/test/fixtures/core__latest-posts.serialized.html index ab37368489fdaf..6c80203bbda2b7 100644 --- a/blocks/test/fixtures/core__latest-posts.serialized.html +++ b/blocks/test/fixtures/core__latest-posts.serialized.html @@ -1 +1 @@ - + From 2ad7c1739f8ab5c3f898a3ca87c665232dd31105 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 30 Jul 2017 21:10:39 +0100 Subject: [PATCH 08/10] Add another `core/latest-posts` fixture --- blocks/test/fixtures/core__latest-posts__displayPostDate.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 blocks/test/fixtures/core__latest-posts__displayPostDate.html diff --git a/blocks/test/fixtures/core__latest-posts__displayPostDate.html b/blocks/test/fixtures/core__latest-posts__displayPostDate.html new file mode 100644 index 00000000000000..d3128a66820632 --- /dev/null +++ b/blocks/test/fixtures/core__latest-posts__displayPostDate.html @@ -0,0 +1 @@ + From 3d248baeedd877f2b53dd38227f2e22f73f5d7fe Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 30 Jul 2017 21:11:03 +0100 Subject: [PATCH 09/10] Fix some irrelevant test failures with partial sets of fixture files --- blocks/test/full-content.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/blocks/test/full-content.js b/blocks/test/full-content.js index f22a4df584a589..daf002e8c9ccc1 100644 --- a/blocks/test/full-content.js +++ b/blocks/test/full-content.js @@ -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'; /** @@ -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( @@ -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, From 3fddff0a97f85e01e7d640d259e0950b0091df5f Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 30 Jul 2017 21:28:00 +0100 Subject: [PATCH 10/10] Add the rest of the second `core/latest-posts` fixture file set --- .../core__latest-posts__displayPostDate.json | 13 +++++++++++++ ...core__latest-posts__displayPostDate.parsed.json | 14 ++++++++++++++ ...__latest-posts__displayPostDate.serialized.html | 1 + 3 files changed, 28 insertions(+) create mode 100644 blocks/test/fixtures/core__latest-posts__displayPostDate.json create mode 100644 blocks/test/fixtures/core__latest-posts__displayPostDate.parsed.json create mode 100644 blocks/test/fixtures/core__latest-posts__displayPostDate.serialized.html diff --git a/blocks/test/fixtures/core__latest-posts__displayPostDate.json b/blocks/test/fixtures/core__latest-posts__displayPostDate.json new file mode 100644 index 00000000000000..238718c80ea868 --- /dev/null +++ b/blocks/test/fixtures/core__latest-posts__displayPostDate.json @@ -0,0 +1,13 @@ +[ + { + "uid": "_uid_0", + "name": "core/latest-posts", + "isValid": true, + "attributes": { + "postsToShow": 5, + "displayPostDate": true, + "layout": "list", + "columns": 3 + } + } +] diff --git a/blocks/test/fixtures/core__latest-posts__displayPostDate.parsed.json b/blocks/test/fixtures/core__latest-posts__displayPostDate.parsed.json new file mode 100644 index 00000000000000..c0b53e30ca56b6 --- /dev/null +++ b/blocks/test/fixtures/core__latest-posts__displayPostDate.parsed.json @@ -0,0 +1,14 @@ +[ + { + "blockName": "core/latest-posts", + "attrs": { + "postsToShow": 5, + "displayPostDate": true + }, + "rawContent": "" + }, + { + "attrs": {}, + "rawContent": "\n" + } +] diff --git a/blocks/test/fixtures/core__latest-posts__displayPostDate.serialized.html b/blocks/test/fixtures/core__latest-posts__displayPostDate.serialized.html new file mode 100644 index 00000000000000..ab37368489fdaf --- /dev/null +++ b/blocks/test/fixtures/core__latest-posts__displayPostDate.serialized.html @@ -0,0 +1 @@ +