From 87ba8acc916033ade2dc48f48eab3b620f7ae1bf Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 17 Oct 2018 16:57:05 -0400 Subject: [PATCH 1/2] Testing: Stub all oEmbed requests as empty string --- test/e2e/specs/demo.test.js | 35 ------------------------ test/e2e/test-mu-plugins/stub-embeds.php | 17 ++++++++++++ 2 files changed, 17 insertions(+), 35 deletions(-) create mode 100644 test/e2e/test-mu-plugins/stub-embeds.php diff --git a/test/e2e/specs/demo.test.js b/test/e2e/specs/demo.test.js index 544e8d9b59cec..7d1ca198a9b42 100644 --- a/test/e2e/specs/demo.test.js +++ b/test/e2e/specs/demo.test.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import fetch from 'node-fetch'; - /** * Internal dependencies */ @@ -10,36 +5,6 @@ import { visitAdmin } from '../support/utils'; describe( 'new editor state', () => { beforeAll( async () => { - // Intercept embed requests so that scripts loaded from third parties - // cannot leave errors in the console and cause the test to fail. - await page.setRequestInterception( true ); - page.on( 'request', async ( request ) => { - if ( request.url().indexOf( 'oembed/1.0/proxy' ) !== -1 ) { - // Because we can't get the responses to requests and modify them on the fly, - // we have to make our own request, get the response, modify it, then use the - // modified values to respond to the request. - const response = await fetch( - request.url(), - { - headers: request.headers(), - method: request.method(), - body: request.postData(), - } - ); - 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]+/, '' ); - request.respond( { - content: 'application/json', - body: JSON.stringify( preview ), - } ); - } else { - request.continue(); - } - } ); - await visitAdmin( 'post-new.php', 'gutenberg-demo' ); } ); diff --git a/test/e2e/test-mu-plugins/stub-embeds.php b/test/e2e/test-mu-plugins/stub-embeds.php new file mode 100644 index 0000000000000..5c45c9ffa13d4 --- /dev/null +++ b/test/e2e/test-mu-plugins/stub-embeds.php @@ -0,0 +1,17 @@ + Date: Wed, 17 Oct 2018 19:21:21 -0400 Subject: [PATCH 2/2] Testing: Update demo content embed assertion --- test/e2e/specs/demo-content-with-keyboard.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/demo-content-with-keyboard.test.js b/test/e2e/specs/demo-content-with-keyboard.test.js index edb49db55c90f..9df5b1b748a78 100644 --- a/test/e2e/specs/demo-content-with-keyboard.test.js +++ b/test/e2e/specs/demo-content-with-keyboard.test.js @@ -358,10 +358,11 @@ describe( 'Demo content post', () => { const postContent = await getEditedPostContent(); - // Some random asserters to ensure blocks have been inserted and the navigation went well + // TODO: A snapshot test should be used, but content must be normalized + // to account for differences in (a) upload path and (b) media IDs. expect( postContent ).toMatch( `

Thanks for testing Gutenberg!

` ); expect( postContent ).toMatch( `
Help build Gutenberg
` ); expect( postContent ).toMatch( `

If you want to learn more about how to build additional blocks, or if you are interested in helping with the project, head over to the GitHub repository.

` ); - expect( postContent ).toMatch( new RegExp( `
\\s*https://vimeo.com/22439234\\s*
` ) ); + expect( postContent ).toMatch( new RegExp( `
\\s*https://vimeo.com/22439234\\s*
` ) ); } ); } );