Skip to content

Commit

Permalink
Use mock response for demo test if Vimeo is down (WordPress#10720)
Browse files Browse the repository at this point in the history
  • Loading branch information
notnownikki authored and antpb committed Oct 26, 2018
1 parent c93eace commit e6c1832
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions test/e2e/specs/demo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import fetch from 'node-fetch';
*/
import { visitAdmin } from '../support/utils';

const MOCK_VIMEO_RESPONSE = {
url: 'https://vimeo.com/22439234',
html: '<iframe width="16" height="9"></iframe>',
type: 'video',
provider_name: 'Vimeo',
provider_url: 'https://vimeo.com',
version: '1.0',
};

describe( 'new editor state', () => {
beforeAll( async () => {
// Intercept embed requests so that scripts loaded from third parties
Expand All @@ -27,13 +36,22 @@ describe( 'new editor state', () => {
}
);
const preview = await response.json();
// Remove the first src attribute. This stops the Vimeo iframe loading the actual
// embedded content, but the height and width are preserved so layout related
// attributes, like aspect ratio CSS classes, remain the same.
preview.html = preview.html.replace( /src=[^\s]+/, '' );
let responseBody;
if ( 'Embed Handler' === preview.provider_name ) {
// If Vimeo is down, that would make this test fail. So if we get a
// response from 'Embed Handler' instead of 'Vimeo', respond with a mock
// response, so we don't hold up development while Vimeo is down.
responseBody = MOCK_VIMEO_RESPONSE;
} else {
// Remove the first src attribute. This stops the Vimeo iframe loading the actual
// embedded content, but the height and width are preserved so layout related
// attributes, like aspect ratio CSS classes, remain the same.
preview.html = preview.html.replace( /src=[^\s]+/, '' );
responseBody = preview;
}
request.respond( {
content: 'application/json',
body: JSON.stringify( preview ),
body: JSON.stringify( responseBody ),
} );
} else {
request.continue();
Expand Down

0 comments on commit e6c1832

Please sign in to comment.