Skip to content

Commit

Permalink
Ensure that there is at least one fixture file for each registered block
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen committed May 23, 2017
1 parent 5c6d335 commit df253a2
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion blocks/test/full-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
*/
import fs from 'fs';
import path from 'path';
import { uniq, isObject, omit } from 'lodash';
import { uniq, isObject, omit, startsWith } from 'lodash';
import { expect } from 'chai';
import { format } from 'util';

/**
* Internal dependencies
Expand All @@ -14,6 +15,7 @@ import {
parseWithTinyMCE,
} from '../api/parser';
import serialize from '../api/serializer';
import { getBlocks } from '../api/registration';

const fixturesDir = path.join( __dirname, 'fixtures' );

Expand Down Expand Up @@ -127,4 +129,52 @@ describe( 'full post content fixture', () => {
expect( serializedActual ).to.eql( serializedExpected );
} );
} );

it( 'should be present for each block', () => {
const errors = [];

getBlocks().map( block => block.slug ).forEach( slug => {
const slugToFilename = slug.replace( /\//g, '-' );
const foundFixtures = fileBasenames
.filter( basename => (
basename === slugToFilename ||
startsWith( basename, slugToFilename + '-' )
) )
.map( basename => {
const filename = basename + '.html';
return {
filename,
contents: readFixtureFile( filename ),
};
} )
.filter( fixture => fixture.contents !== null );

if ( ! foundFixtures.length ) {
errors.push( format(
"Expected a fixture file called '%s.html' or '%s-*.html'.",
slugToFilename,
slugToFilename
) );
}

foundFixtures.forEach( fixture => {
const delimiter = new RegExp(
'<!--\\s*wp:' + slug + '(\\s+|\\s*-->)'
);
if ( ! delimiter.test( fixture.contents ) ) {
errors.push( format(
"Expected fixture file '%s' to test the '%s' block.",
fixture.filename,
slug
) );
}
} );
} );

if ( errors.length ) {
throw new Error(
'Problem(s) with fixture files:\n\n' + errors.join( '\n' )
);
}
} );
} );

0 comments on commit df253a2

Please sign in to comment.