Repository navigation
test(e2e): Cover delivery through a custom domain (CNAME) - #1353
utkarshcloudinary wants to merge 6 commits into
Conversation
2dd4986 to
ef58d3a
Compare
Move galleryBlock(), openGallery() and collectImageUrls() out of the gallery delivery spec into tests/e2e/utils/gallery.js, so the custom domain spec can render the Gallery block the same way.
- ensureCloudinaryConnected() accepts { cname, privateCdn } and adds
them to the connection string. It now fails when the plugin does
not save the new string.
- expectCloudinaryUrl() accepts { host, cloudName, privateCdn }.
- routeCnameToCloudinary() sends requests for a fake custom domain on
to res.cloudinary.com, so the images still load.
Connect with a fake custom domain and check that the image block, the Gallery widget and the Cloudinary video player use it. Check that private_cdn=false keeps the cloud name in the path. Restore the plain connection in afterAll. Refs WPP-1240
Replace the local saveSettings() copy with the one in tests/e2e/utils/settings.js.
ef58d3a to
4513a60
Compare
gabrielcld2
left a comment
There was a problem hiding this comment.
This is looking good 👍 A few comments and suggestions, but nothing major.
| expect( params.get( 'cloudinary[private_cdn]' ) ).toBe( 'true' ); | ||
| } ); | ||
|
|
||
| test( 'with private_cdn=false the path keeps the cloud name', async ( { |
There was a problem hiding this comment.
Should this test cover the gallery too? Gallery always sends privateCdn: true when a cname is set (php/media/class-gallery.php, in get_config() and in the block attributes), whatever private_cdn says in the connection string. So with private_cdn=false I'd expect the widget to leave the cloud name out of its URLs, and a CNAME that isn't a private CDN can't serve those.
If that's right, it's a plugin bug and this spec is a good place to catch it, even as a test.fixme until it's fixed. If it's intended, a short comment here explaining why the gallery is left out would help.
There was a problem hiding this comment.
You're right, it's a plugin bug. Gallery sets privateCdn: true whenever a cname is set and ignores private_cdn. I confirmed it locally: with private_cdn=false the widget renders 0 of 3 images, because its URLs leave out the cloud name. Added in 4399523 as test.fixme( 'gallery widget path keeps the cloud name' ) inside the private_cdn=false block, with a comment pointing at class-gallery.php. It can become a plain test once the plugin is fixed.
| test( 'with private_cdn=false the path keeps the cloud name', async ( { | ||
| page, | ||
| } ) => { | ||
| ensureCloudinaryConnected( { cname: CNAME, privateCdn: false } ); |
There was a problem hiding this comment.
This switches the connection to private_cdn=false, and only afterAll switches it back. So any test added after this one would run with private_cdn=false too. Could we switch it back at the end of the test (try/finally with ensureCloudinaryConnected( { cname: CNAME } ))? Or at least add a comment saying this test has to stay last.
There was a problem hiding this comment.
Done in 4399523. The private_cdn=false tests are now in their own describe block: its beforeAll switches to private_cdn=false and its afterAll switches back to the plain cname. A test added outside the block keeps the private CDN connection.
| } | ||
|
|
||
| module.exports = { | ||
| GALLERY_CONTAINER, |
There was a problem hiding this comment.
Nit: nothing imports GALLERY_CONTAINER or WIDGET_TIMEOUT, and the same goes for CLOUDINARY_HOST in utils/delivery.js. Fine to keep them if you expect to need them soon. Otherwise we could remove them from the exports.
There was a problem hiding this comment.
Removed in 4399523. GALLERY_CONTAINER, WIDGET_TIMEOUT and CLOUDINARY_HOST are still used inside their own files, just no longer exported.
Switch to private_cdn=false in a describe block's beforeAll and back in its afterAll, so a test added later does not inherit it. Add a gallery test for private_cdn=false as test.fixme. Gallery always passes privateCdn: true to the widget when a custom domain is set, so the widget leaves the cloud name out of its URLs and no image loads. Remove exports that nothing imports.
Lint failed in CI because the gallery fixme test was formatted with an older local prettier than the one in package-lock.json.
Adds an e2e spec for delivery through a custom domain (CNAME). The spec connects with a fake domain in the connection string and checks that the image block, the Gallery widget and the Cloudinary video player use it. It also checks that
private_cdn=falsekeeps the cloud name in the path.Approach
cloudinary-cname-delivery.spec.js(@serial) connects with?cname=cdn.e2e-cloudinary.testbefore the upload, as the ticket suggests. The plugin only checks the domain format and never resolves it.routeCnameToCloudinary()sends requests for the fake domain on tores.cloudinary.com, and adds the cloud name to the path for a private CDN. So the images really load, and the Gallery widget reachesdata-ready="true". This also proves that the path the plugin builds is a valid Cloudinary path.srcand everysrcsetURL use the domain, and the path does not start with/<cloud_name>/. Lazy load is off and breakpoints are on, so the server writes a Cloudinarysrcsetto check.<img>URL uses the domain.cloudinary[cname],cloudinary[secure_distribution]andcloudinary[private_cdn].private_cdn=false: the URLs use the domain, and the path starts with/<cloud_name>/. Atest.fixmecovers the Gallery widget in this mode:Galleryalways sendsprivateCdn: truewhen a custom domain is set and ignoresprivate_cdn, so the widget leaves the cloud name out and no image loads.afterAllconnects without the domain first, then restores the settings and deletes the posts and attachments. So the other delivery specs in the same serial run get plainres.cloudinary.comURLs.ensureCloudinaryConnected()accepts{ cname, privateCdn }. It now fails if the plugin does not save the new connection string, which the plugin does when the API test of the string fails.expectCloudinaryUrl()accepts{ host, cloudName, privateCdn }. A plain cloud name still works as before.tests/e2e/utils/gallery.js. The gallery spec uses them and works as before.QA notes
npm run test:e2e:serial -- cloudinary-cname-deliverynpm run test:e2e:serial(the other delivery specs must still pass after this spec in the same run)