From 3296c1f303a0ced2fb6c357454adc8c8b55ffe7d Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Tue, 24 Aug 2021 10:34:54 +0200 Subject: [PATCH 01/13] Bump fs-extra --- packages/calypso-e2e/package.json | 3 ++- yarn.lock | 25 +++++++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/packages/calypso-e2e/package.json b/packages/calypso-e2e/package.json index 17b17a945b251..dfb32bf512933 100644 --- a/packages/calypso-e2e/package.json +++ b/packages/calypso-e2e/package.json @@ -25,7 +25,8 @@ "@types/jest": "^25.2.3", "@types/node": "^15.0.2", "asana-phrase": "^0.0.8", - "fs-extra": "3.0.1" + "fs-extra": "^10.0.0", + "mockdate": "^3.0.5" }, "scripts": { "clean": "yarn build --clean && npx rimraf dist", diff --git a/yarn.lock b/yarn.lock index b419087f56d77..148834f79128e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13299,15 +13299,6 @@ fs-exists-sync@^0.1.0: resolved "https://registry.yarnpkg.com/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz#982d6893af918e72d08dec9e8673ff2b5a8d6add" integrity sha1-mC1ok6+RjnLQjeyehnP/K1qNat0= -fs-extra@3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-3.0.1.tgz#3794f378c58b342ea7dbbb23095109c4b3b62291" - integrity sha1-N5TzeMWLNC6n27sjCVEJxLO2IpE= - dependencies: - graceful-fs "^4.1.2" - jsonfile "^3.0.0" - universalify "^0.1.0" - fs-extra@^0.22.1: version "0.22.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-0.22.1.tgz#5fd6f8049dc976ca19eb2355d658173cabcce056" @@ -13328,6 +13319,15 @@ fs-extra@^0.30.0: path-is-absolute "^1.0.0" rimraf "^2.2.8" +fs-extra@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1" + integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ== + dependencies: + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^2.0.0" + fs-extra@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" @@ -17351,13 +17351,6 @@ jsonfile@^2.1.0: optionalDependencies: graceful-fs "^4.1.6" -jsonfile@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-3.0.1.tgz#a5ecc6f65f53f662c4415c7675a0331d0992ec66" - integrity sha1-pezG9l9T9mLEQVx2daAzHQmS7GY= - optionalDependencies: - graceful-fs "^4.1.6" - jsonfile@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" From 0adb97f334527ae45017e7e6e1f0e67a9be1e9b9 Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Tue, 24 Aug 2021 11:40:23 +0200 Subject: [PATCH 02/13] Debug media --- packages/calypso-e2e/src/media-helper.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/calypso-e2e/src/media-helper.ts b/packages/calypso-e2e/src/media-helper.ts index c7d5750093a41..9e720be627a00 100644 --- a/packages/calypso-e2e/src/media-helper.ts +++ b/packages/calypso-e2e/src/media-helper.ts @@ -82,6 +82,12 @@ export function createTestFile( { // Attempting to copy the file elsewhere will trigger the following error on TeamCity: // EPERM: operation not permitted const testFilePath = path.join( sourceFileDir, fileName ); + + console.dir( require( 'os' ).userInfo() ); + console.dir( fs.statSync( sourceFilePath ) ); + console.dir( fs.statSync( sourceFileDir ) ); + console.dir( fs.statSync( testFilePath ) ); + // Copy the source file specified to testFilePath, creating a clone differing only by name. fs.copySync( sourceFilePath, testFilePath ); From 7015a9cc31e69f70304bcc602e6036c114cfc9de Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Tue, 24 Aug 2021 12:00:36 +0200 Subject: [PATCH 03/13] Drop fs-extra --- packages/calypso-e2e/package.json | 2 -- packages/calypso-e2e/src/media-helper.ts | 11 +++-------- yarn.lock | 16 ---------------- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/packages/calypso-e2e/package.json b/packages/calypso-e2e/package.json index dfb32bf512933..11498306322da 100644 --- a/packages/calypso-e2e/package.json +++ b/packages/calypso-e2e/package.json @@ -21,11 +21,9 @@ }, "devDependencies": { "@types/config": "^0.0.39", - "@types/fs-extra": "^9.0.12", "@types/jest": "^25.2.3", "@types/node": "^15.0.2", "asana-phrase": "^0.0.8", - "fs-extra": "^10.0.0", "mockdate": "^3.0.5" }, "scripts": { diff --git a/packages/calypso-e2e/src/media-helper.ts b/packages/calypso-e2e/src/media-helper.ts index 9e720be627a00..c097e5bdf7ea1 100644 --- a/packages/calypso-e2e/src/media-helper.ts +++ b/packages/calypso-e2e/src/media-helper.ts @@ -1,6 +1,6 @@ +import fs from 'fs'; import path from 'path'; import config from 'config'; -import fs from 'fs-extra'; import { getTimestamp } from './data-helper'; const artifacts: { [ key: string ]: string } = config.get( 'artifacts' ); @@ -48,7 +48,7 @@ export function getVideoDir(): string { * @returns {void} No return value. */ export function deleteFile( filePath: string ): void { - fs.removeSync( filePath ); + fs.unlinkSync( filePath ); } /** @@ -83,13 +83,8 @@ export function createTestFile( { // EPERM: operation not permitted const testFilePath = path.join( sourceFileDir, fileName ); - console.dir( require( 'os' ).userInfo() ); - console.dir( fs.statSync( sourceFilePath ) ); - console.dir( fs.statSync( sourceFileDir ) ); - console.dir( fs.statSync( testFilePath ) ); - // Copy the source file specified to testFilePath, creating a clone differing only by name. - fs.copySync( sourceFilePath, testFilePath ); + fs.copyFileSync( sourceFilePath, testFilePath ); return testFilePath; } diff --git a/yarn.lock b/yarn.lock index 148834f79128e..875af72079ab9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3926,13 +3926,6 @@ resolved "https://registry.yarnpkg.com/@types/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#40363bb847cb86b2c2e1599f1398d11e8329c921" integrity sha512-mky/O83TXmGY39P1H9YbUpjV6l6voRYlufqfFCvel8l1phuy8HRjdWc1rrPuN53ITBJlbyMSV6z3niOySO5pgQ== -"@types/fs-extra@^9.0.12": - version "9.0.12" - resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.12.tgz#9b8f27973df8a7a3920e8461517ebf8a7d4fdfaf" - integrity sha512-I+bsBr67CurCGnSenZZ7v94gd3tc3+Aj2taxMT4yu4ABLuOgOjeFxX3dokG24ztSRg5tnT00sL8BszO7gSMoIw== - dependencies: - "@types/node" "*" - "@types/glob-base@^0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@types/glob-base/-/glob-base-0.3.0.tgz#a581d688347e10e50dd7c17d6f2880a10354319d" @@ -13319,15 +13312,6 @@ fs-extra@^0.30.0: path-is-absolute "^1.0.0" rimraf "^2.2.8" -fs-extra@^10.0.0: - version "10.0.0" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1" - integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ== - dependencies: - graceful-fs "^4.2.0" - jsonfile "^6.0.1" - universalify "^2.0.0" - fs-extra@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" From 1f48befd462b832a2d453efb611831a3640d238c Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Wed, 25 Aug 2021 05:23:18 +0200 Subject: [PATCH 04/13] Try copying it manually --- packages/calypso-e2e/src/media-helper.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/calypso-e2e/src/media-helper.ts b/packages/calypso-e2e/src/media-helper.ts index c097e5bdf7ea1..2c245ed8b5d6a 100644 --- a/packages/calypso-e2e/src/media-helper.ts +++ b/packages/calypso-e2e/src/media-helper.ts @@ -1,3 +1,4 @@ +import cp from 'child_process'; import fs from 'fs'; import path from 'path'; import config from 'config'; @@ -84,6 +85,11 @@ export function createTestFile( { const testFilePath = path.join( sourceFileDir, fileName ); // Copy the source file specified to testFilePath, creating a clone differing only by name. + console.log( cp.execSync( `ls -la ${ sourceFileDir }` ) ); + console.log( cp.execSync( `ls -la ${ sourceFilePath }` ) ); + console.log( cp.execSync( `ls -la ${ testFilePath }` ) ); + console.log( cp.execSync( `cp ${ sourceFilePath } ${ testFilePath }` ) ); + fs.copyFileSync( sourceFilePath, testFilePath ); return testFilePath; From 9ea22cf8d5d2a504240cbd8c9d5694a1469d29c2 Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Wed, 25 Aug 2021 07:02:31 +0200 Subject: [PATCH 05/13] Use try/catch --- packages/calypso-e2e/src/media-helper.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/calypso-e2e/src/media-helper.ts b/packages/calypso-e2e/src/media-helper.ts index 2c245ed8b5d6a..53246cbdbe505 100644 --- a/packages/calypso-e2e/src/media-helper.ts +++ b/packages/calypso-e2e/src/media-helper.ts @@ -85,10 +85,21 @@ export function createTestFile( { const testFilePath = path.join( sourceFileDir, fileName ); // Copy the source file specified to testFilePath, creating a clone differing only by name. - console.log( cp.execSync( `ls -la ${ sourceFileDir }` ) ); - console.log( cp.execSync( `ls -la ${ sourceFilePath }` ) ); - console.log( cp.execSync( `ls -la ${ testFilePath }` ) ); - console.log( cp.execSync( `cp ${ sourceFilePath } ${ testFilePath }` ) ); + try { + console.log( cp.execSync( `ls -la ${ sourceFileDir }` ) ); + } catch {} + try { + console.log( cp.execSync( `ls -la ${ sourceFilePath }` ) ); + } catch {} + try { + console.log( cp.execSync( `ls -la ${ testFilePath }` ) ); + } catch {} + try { + console.log( cp.execSync( `cp ${ sourceFilePath } ${ testFilePath }` ) ); + } catch {} + try { + console.log( cp.execSync( `ls -la ${ testFilePath }` ) ); + } catch {} fs.copyFileSync( sourceFilePath, testFilePath ); From 9321a33b218740e765469a4c47ea9c1b0f5de7d9 Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Wed, 25 Aug 2021 07:22:02 +0200 Subject: [PATCH 06/13] toString --- packages/calypso-e2e/src/media-helper.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/calypso-e2e/src/media-helper.ts b/packages/calypso-e2e/src/media-helper.ts index 53246cbdbe505..a9df401fb9de7 100644 --- a/packages/calypso-e2e/src/media-helper.ts +++ b/packages/calypso-e2e/src/media-helper.ts @@ -86,19 +86,19 @@ export function createTestFile( { // Copy the source file specified to testFilePath, creating a clone differing only by name. try { - console.log( cp.execSync( `ls -la ${ sourceFileDir }` ) ); + console.log( cp.execSync( `ls -la ${ sourceFileDir }` ).toString() ); } catch {} try { - console.log( cp.execSync( `ls -la ${ sourceFilePath }` ) ); + console.log( cp.execSync( `ls -la ${ sourceFilePath }` ).toString() ); } catch {} try { - console.log( cp.execSync( `ls -la ${ testFilePath }` ) ); + console.log( cp.execSync( `ls -la ${ testFilePath }` ).toString() ); } catch {} try { - console.log( cp.execSync( `cp ${ sourceFilePath } ${ testFilePath }` ) ); + console.log( cp.execSync( `cp ${ sourceFilePath } ${ testFilePath }` ).toString() ); } catch {} try { - console.log( cp.execSync( `ls -la ${ testFilePath }` ) ); + console.log( cp.execSync( `ls -la ${ testFilePath }` ).toString() ); } catch {} fs.copyFileSync( sourceFilePath, testFilePath ); From d5715b4d03a0e29894e5ea5f6261656f8c344e0f Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Wed, 25 Aug 2021 08:10:06 +0200 Subject: [PATCH 07/13] Try to be concurrency friendly --- packages/calypso-e2e/src/media-helper.ts | 55 ++++++------------- .../specs-playwright/wp-blocks__coblocks.ts | 11 +++- .../specs-playwright/wp-blocks__media-spec.ts | 55 ++++++++++--------- .../specs-playwright/wp-media__edit-spec.js | 6 +- .../specs-playwright/wp-media__upload-spec.js | 37 +++++++------ 5 files changed, 83 insertions(+), 81 deletions(-) diff --git a/packages/calypso-e2e/src/media-helper.ts b/packages/calypso-e2e/src/media-helper.ts index a9df401fb9de7..f8c085a961154 100644 --- a/packages/calypso-e2e/src/media-helper.ts +++ b/packages/calypso-e2e/src/media-helper.ts @@ -1,5 +1,5 @@ -import cp from 'child_process'; -import fs from 'fs'; +import fs from 'fs/promises'; +import os from 'os'; import path from 'path'; import config from 'config'; import { getTimestamp } from './data-helper'; @@ -46,10 +46,10 @@ export function getVideoDir(): string { * Given a full path to file on disk, remove the file. * * @param {string} filePath Full path on disk. - * @returns {void} No return value. + * @returns {Promise< void >} No return value. */ -export function deleteFile( filePath: string ): void { - fs.unlinkSync( filePath ); +export async function deleteFile( filePath: string ): Promise< void > { + await fs.unlink( filePath ); } /** @@ -58,15 +58,15 @@ export function deleteFile( filePath: string ): void { * @param {{[key: string]: string}} param0 Parameter object. * @param {string} param0.sourceFileName Basename of the source file to be cloned. * @param {string} [param0.testFileName] Basename of the test file to be generated. - * @returns {string} Full path to the generated test file. + * @returns {Promise} Full path to the generated test file. */ -export function createTestFile( { +export async function createTestFile( { sourceFileName, testFileName, }: { sourceFileName: string; testFileName?: string; -} ): string { +} ): Promise< string > { let fileName = getTimestamp(); // If the output `testFileName` is defined, use that as part of the final filename. if ( testFileName ) { @@ -79,29 +79,10 @@ export function createTestFile( { const sourceFileDir = path.join( __dirname, '../../../../../test/e2e/image-uploads/' ); const sourceFilePath = path.join( sourceFileDir, sourceFileName ); - // Generated test file will also go under the source directory. - // Attempting to copy the file elsewhere will trigger the following error on TeamCity: - // EPERM: operation not permitted - const testFilePath = path.join( sourceFileDir, fileName ); + const tempDir = await fs.mkdtemp( path.join( os.tmpdir(), 'foo-' ) ); + const testFilePath = path.join( tempDir, fileName ); - // Copy the source file specified to testFilePath, creating a clone differing only by name. - try { - console.log( cp.execSync( `ls -la ${ sourceFileDir }` ).toString() ); - } catch {} - try { - console.log( cp.execSync( `ls -la ${ sourceFilePath }` ).toString() ); - } catch {} - try { - console.log( cp.execSync( `ls -la ${ testFilePath }` ).toString() ); - } catch {} - try { - console.log( cp.execSync( `cp ${ sourceFilePath } ${ testFilePath }` ).toString() ); - } catch {} - try { - console.log( cp.execSync( `ls -la ${ testFilePath }` ).toString() ); - } catch {} - - fs.copyFileSync( sourceFilePath, testFilePath ); + await fs.copyFile( sourceFilePath, testFilePath ); return testFilePath; } @@ -109,10 +90,10 @@ export function createTestFile( { /** * Returns the path to a generated temporary JPEG image file. * - * @returns {string} Full path on disk to the generated test file. + * @returns {Promise} Full path on disk to the generated test file. */ -export function createTestImage(): string { - return createTestFile( { sourceFileName: 'image0.jpg' } ); +export async function createTestImage(): Promise< string > { + return await createTestFile( { sourceFileName: 'image0.jpg' } ); } /** @@ -120,8 +101,8 @@ export function createTestImage(): string { * * @returns {string} Full path on disk to the generated test file. */ -export function createTestAudio(): string { - return createTestFile( { sourceFileName: 'bees.mp3' } ); +export async function createTestAudio(): Promise< string > { + return await createTestFile( { sourceFileName: 'bees.mp3' } ); } /** @@ -129,6 +110,6 @@ export function createTestAudio(): string { * * @returns {string} Full path on disk to the generated test file. */ -export function createInvalidFile(): string { - return createTestFile( { sourceFileName: 'unsupported_extension.mkv' } ); +export async function createInvalidFile(): Promise< string > { + return await createTestFile( { sourceFileName: 'unsupported_extension.mkv' } ); } diff --git a/test/e2e/specs/specs-playwright/wp-blocks__coblocks.ts b/test/e2e/specs/specs-playwright/wp-blocks__coblocks.ts index 20153c8c45e1e..af022dd7b856c 100644 --- a/test/e2e/specs/specs-playwright/wp-blocks__coblocks.ts +++ b/test/e2e/specs/specs-playwright/wp-blocks__coblocks.ts @@ -18,18 +18,22 @@ describe( DataHelper.createSuiteTitle( 'Blocks: CoBlocks' ), () => { let gutenbergEditorPage: GutenbergEditorPage; let pricingTableBlock: PricingTableBlock; let page: Page; + let logoImage: string; // Test data const pricingTableBlockPrice = 888; const heroBlockHeading = 'Hero heading'; const clicktoTweetBlockTweet = 'The foolish man seeks happiness in the distance. The wise grows it under his feet. — James Oppenheim'; - const logoImage = MediaHelper.createTestImage(); setupHooks( ( args ) => { page = args.page; } ); + beforeAll( async () => { + logoImage = await MediaHelper.createTestImage(); + } ); + it( 'Log in', async function () { const loginFlow = new LoginFlow( page, 'gutenbergSimpleSiteUser' ); await loginFlow.logIn(); @@ -87,7 +91,6 @@ describe( DataHelper.createSuiteTitle( 'Blocks: CoBlocks' ), () => { ${ DynamicHRBlock } | ${ null } ${ HeroBlock } | ${ [ heroBlockHeading ] } ${ ClicktoTweetBlock } | ${ [ clicktoTweetBlockTweet ] } - ${ LogosBlock } | ${ [ path.parse( logoImage ).name ] } `( `Confirm $block.blockName block is visible in published post`, async ( { block, content } ) => { @@ -95,4 +98,8 @@ describe( DataHelper.createSuiteTitle( 'Blocks: CoBlocks' ), () => { await block.validatePublishedContent( page, content ); } ); + + it( `Confirm Logso block is visible in published post`, async () => { + await LogosBlock.validatePublishedContent( page, path.parse( logoImage ).name ); + } ); } ); diff --git a/test/e2e/specs/specs-playwright/wp-blocks__media-spec.ts b/test/e2e/specs/specs-playwright/wp-blocks__media-spec.ts index 996499faaa96c..c29a1dcbc5720 100644 --- a/test/e2e/specs/specs-playwright/wp-blocks__media-spec.ts +++ b/test/e2e/specs/specs-playwright/wp-blocks__media-spec.ts @@ -15,20 +15,23 @@ import { Page } from 'playwright'; describe( DataHelper.createSuiteTitle( 'Blocks: Media (Upload)' ), () => { let gutenbergEditorPage: GutenbergEditorPage; let page: Page; - - const testFiles = { - image: MediaHelper.createTestImage(), - image_reserved_name: MediaHelper.createTestFile( { - sourceFileName: 'image0.jpg', - testFileName: 'filewith#?#?reservedurlchars', - } ), - audio: MediaHelper.createTestAudio(), - }; + let testFiles: { image: string; image_reserved_name: string; audio: string }; setupHooks( ( args ) => { page = args.page; } ); + beforeAll( async () => { + testFiles = { + image: await MediaHelper.createTestImage(), + image_reserved_name: await MediaHelper.createTestFile( { + sourceFileName: 'image0.jpg', + testFileName: 'filewith#?#?reservedurlchars', + } ), + audio: await MediaHelper.createTestAudio(), + }; + } ); + it( 'Log in', async function () { const loginFlow = new LoginFlow( page, 'gutenbergSimpleSiteUser' ); await loginFlow.logIn(); @@ -72,20 +75,22 @@ describe( DataHelper.createSuiteTitle( 'Blocks: Media (Upload)' ), () => { await gutenbergEditorPage.publish( { visit: true } ); } ); - // Pass in a 1D array of values or text strings to validate each block. - // The full filename (name.extension) is not used within the Image block, but the file name is. - // `path.parse` is called to trim the extension. - it.each` - block | content - ${ ImageBlock } | ${ [ path.parse( testFiles.image ).name ] } - ${ ImageBlock } | ${ [ path.parse( testFiles.image_reserved_name ).name.replace( /[^a-zA-Z ]/g, '' ) ] } - ${ AudioBlock } | ${ [ path.parse( testFiles.audio ).base ] } - ${ FileBlock } | ${ [ path.parse( testFiles.audio ).name ] } - `( - `Confirm $block.blockName block is visible in published post`, - async ( { block, content } ) => { - // Pass the Block object class here then call the static method to validate. - await block.validatePublishedContent( page, content ); - } - ); + it( `Confirm Image block is visible in published post`, async () => { + await ImageBlock.validatePublishedContent( page, path.parse( testFiles.image ).name ); + } ); + + it( `Confirm Image block is visible in published post (reserved name)`, async () => { + await ImageBlock.validatePublishedContent( + page, + path.parse( testFiles.image_reserved_name ).name.replace( /[^a-zA-Z ]/g, '' ) + ); + } ); + + it( `Confirm Audio block is visible in published post`, async () => { + await ImageBlock.validatePublishedContent( page, path.parse( testFiles.audio ).base ); + } ); + + it( `Confirm File block is visible in published post`, async () => { + await ImageBlock.validatePublishedContent( page, path.parse( testFiles.audio ).name ); + } ); } ); diff --git a/test/e2e/specs/specs-playwright/wp-media__edit-spec.js b/test/e2e/specs/specs-playwright/wp-media__edit-spec.js index c7eca73dcea12..bb0ac605eaa08 100644 --- a/test/e2e/specs/specs-playwright/wp-media__edit-spec.js +++ b/test/e2e/specs/specs-playwright/wp-media__edit-spec.js @@ -8,13 +8,17 @@ import { } from '@automattic/calypso-e2e'; describe( DataHelper.createSuiteTitle( 'Media: Edit Media' ), function () { - const testImage = MediaHelper.createTestImage(); + let testImage; let page; setupHooks( ( args ) => { page = args.page; } ); + beforeAll( async () => { + testImage = await MediaHelper.createTestImage(); + } ); + describe.each` siteType | user ${ 'Simple' } | ${ 'defaultUser' } diff --git a/test/e2e/specs/specs-playwright/wp-media__upload-spec.js b/test/e2e/specs/specs-playwright/wp-media__upload-spec.js index ab56cedb10669..7a6c7c009f90f 100644 --- a/test/e2e/specs/specs-playwright/wp-media__upload-spec.js +++ b/test/e2e/specs/specs-playwright/wp-media__upload-spec.js @@ -9,17 +9,21 @@ import { } from '@automattic/calypso-e2e'; describe( DataHelper.createSuiteTitle( 'Media: Upload' ), () => { - const testFiles = [ - { type: 'image', filepath: MediaHelper.createTestImage() }, - { type: 'audio', filepath: MediaHelper.createTestAudio() }, - ]; - const invalidFile = MediaHelper.createInvalidFile(); + let testFiles; let page; setupHooks( ( args ) => { page = args.page; } ); + beforeAll( async () => { + testFiles = { + image: await MediaHelper.createTestImage(), + audio: await MediaHelper.createTestAudio(), + invalid: await MediaHelper.createInvalidFile(), + }; + } ); + // Parametrized test. describe.each` siteType | user @@ -42,17 +46,19 @@ describe( DataHelper.createSuiteTitle( 'Media: Upload' ), () => { mediaPage = new MediaPage( page ); } ); - it.each( testFiles )( - 'Upload $type and confirm addition to gallery', - async ( { filepath } ) => { - const uploadedItem = await mediaPage.upload( filepath ); - assert.strictEqual( await uploadedItem.isVisible(), true ); - } - ); + it( 'Upload image and confirm addition to gallery', async () => { + const uploadedItem = await mediaPage.upload( testFiles.image ); + assert.strictEqual( await uploadedItem.isVisible(), true ); + } ); + + it( 'Upload audio and confirm addition to gallery', async () => { + const uploadedItem = await mediaPage.upload( testFiles.audio ); + assert.strictEqual( await uploadedItem.isVisible(), true ); + } ); it( 'Upload an unsupported file type and see the rejection notice', async function () { try { - await mediaPage.upload( invalidFile ); + await mediaPage.upload( testFiles.invalid ); } catch ( error ) { assert.match( error.message, /could not be uploaded/i ); } @@ -60,10 +66,9 @@ describe( DataHelper.createSuiteTitle( 'Media: Upload' ), () => { } ); // Clean up test files. - afterAll( () => { + afterAll( async () => { for ( const testFile of Object.values( testFiles ) ) { - MediaHelper.deleteFile( testFile.filepath ); + await MediaHelper.deleteFile( testFile.filepath ); } - MediaHelper.deleteFile( invalidFile ); } ); } ); From f37def3420844c99ff3483b192236c681d3a5ee5 Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Wed, 25 Aug 2021 08:57:02 +0200 Subject: [PATCH 08/13] Use e2e prefix --- packages/calypso-e2e/src/media-helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/calypso-e2e/src/media-helper.ts b/packages/calypso-e2e/src/media-helper.ts index f8c085a961154..f350650e06afc 100644 --- a/packages/calypso-e2e/src/media-helper.ts +++ b/packages/calypso-e2e/src/media-helper.ts @@ -79,7 +79,7 @@ export async function createTestFile( { const sourceFileDir = path.join( __dirname, '../../../../../test/e2e/image-uploads/' ); const sourceFilePath = path.join( sourceFileDir, sourceFileName ); - const tempDir = await fs.mkdtemp( path.join( os.tmpdir(), 'foo-' ) ); + const tempDir = await fs.mkdtemp( path.join( os.tmpdir(), 'e2e-' ) ); const testFilePath = path.join( tempDir, fileName ); await fs.copyFile( sourceFilePath, testFilePath ); From 5605808bd2dc8ae058272722ed5e8a1daaf3dd2f Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Wed, 25 Aug 2021 08:57:19 +0200 Subject: [PATCH 09/13] Fix typo --- test/e2e/specs/specs-playwright/wp-blocks__coblocks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/specs-playwright/wp-blocks__coblocks.ts b/test/e2e/specs/specs-playwright/wp-blocks__coblocks.ts index af022dd7b856c..e2570ea0d32c9 100644 --- a/test/e2e/specs/specs-playwright/wp-blocks__coblocks.ts +++ b/test/e2e/specs/specs-playwright/wp-blocks__coblocks.ts @@ -99,7 +99,7 @@ describe( DataHelper.createSuiteTitle( 'Blocks: CoBlocks' ), () => { } ); - it( `Confirm Logso block is visible in published post`, async () => { + it( `Confirm Logos block is visible in published post`, async () => { await LogosBlock.validatePublishedContent( page, path.parse( logoImage ).name ); } ); } ); From 8c7a501e84dd3e82fadccaa66e53c72f73bd07ee Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Wed, 25 Aug 2021 08:59:04 +0200 Subject: [PATCH 10/13] Drop deleteFile --- packages/calypso-e2e/src/media-helper.ts | 10 ---------- .../specs/specs-playwright/wp-media__upload-spec.js | 7 ------- 2 files changed, 17 deletions(-) diff --git a/packages/calypso-e2e/src/media-helper.ts b/packages/calypso-e2e/src/media-helper.ts index f350650e06afc..52a94d3a75c57 100644 --- a/packages/calypso-e2e/src/media-helper.ts +++ b/packages/calypso-e2e/src/media-helper.ts @@ -42,16 +42,6 @@ export function getVideoDir(): string { return path.resolve( getAssetDir(), process.env.VIDEODIR || artifacts.video ); } -/** - * Given a full path to file on disk, remove the file. - * - * @param {string} filePath Full path on disk. - * @returns {Promise< void >} No return value. - */ -export async function deleteFile( filePath: string ): Promise< void > { - await fs.unlink( filePath ); -} - /** * Creates a temporary test file by cloning a source file under a new name. * diff --git a/test/e2e/specs/specs-playwright/wp-media__upload-spec.js b/test/e2e/specs/specs-playwright/wp-media__upload-spec.js index 7a6c7c009f90f..55b96eb3b8f3a 100644 --- a/test/e2e/specs/specs-playwright/wp-media__upload-spec.js +++ b/test/e2e/specs/specs-playwright/wp-media__upload-spec.js @@ -64,11 +64,4 @@ describe( DataHelper.createSuiteTitle( 'Media: Upload' ), () => { } } ); } ); - - // Clean up test files. - afterAll( async () => { - for ( const testFile of Object.values( testFiles ) ) { - await MediaHelper.deleteFile( testFile.filepath ); - } - } ); } ); From 0846d895352f697c7118b4f568b65c0683c0c479 Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Wed, 25 Aug 2021 09:26:29 +0200 Subject: [PATCH 11/13] Drop unused dep --- packages/calypso-e2e/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/calypso-e2e/package.json b/packages/calypso-e2e/package.json index 11498306322da..c6b260800655d 100644 --- a/packages/calypso-e2e/package.json +++ b/packages/calypso-e2e/package.json @@ -23,8 +23,7 @@ "@types/config": "^0.0.39", "@types/jest": "^25.2.3", "@types/node": "^15.0.2", - "asana-phrase": "^0.0.8", - "mockdate": "^3.0.5" + "asana-phrase": "^0.0.8" }, "scripts": { "clean": "yarn build --clean && npx rimraf dist", From 609628643cc5b0b7a5b2c44e6907f1807470a886 Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Wed, 25 Aug 2021 11:39:36 +0200 Subject: [PATCH 12/13] Fix test code --- test/e2e/specs/specs-playwright/wp-blocks__media-spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/specs-playwright/wp-blocks__media-spec.ts b/test/e2e/specs/specs-playwright/wp-blocks__media-spec.ts index c29a1dcbc5720..831ad254092e9 100644 --- a/test/e2e/specs/specs-playwright/wp-blocks__media-spec.ts +++ b/test/e2e/specs/specs-playwright/wp-blocks__media-spec.ts @@ -87,10 +87,10 @@ describe( DataHelper.createSuiteTitle( 'Blocks: Media (Upload)' ), () => { } ); it( `Confirm Audio block is visible in published post`, async () => { - await ImageBlock.validatePublishedContent( page, path.parse( testFiles.audio ).base ); + await AudioBlock.validatePublishedContent( page ); } ); it( `Confirm File block is visible in published post`, async () => { - await ImageBlock.validatePublishedContent( page, path.parse( testFiles.audio ).name ); + await FileBlock.validatePublishedContent( page, path.parse( testFiles.audio ).name ); } ); } ); From e19490b25bfdcab07ce84edfeb33cc1c0eae736a Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Wed, 25 Aug 2021 12:21:21 +0200 Subject: [PATCH 13/13] Do not overwrite docker params --- .teamcity/_self/projects/WebApp.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/.teamcity/_self/projects/WebApp.kt b/.teamcity/_self/projects/WebApp.kt index b1d886036665e..90725a01ae531 100644 --- a/.teamcity/_self/projects/WebApp.kt +++ b/.teamcity/_self/projects/WebApp.kt @@ -646,7 +646,6 @@ fun playwrightBuildType( viewportName: String, buildUuid: String ): BuildType { xvfb-run yarn jest --reporters=jest-teamcity --reporters=default --testNamePattern @parallel --maxWorkers=%E2E_WORKERS% specs/specs-playwright """.trimIndent() dockerImage = "%docker_image_e2e%" - dockerRunParameters = "-u %env.UID% --security-opt seccomp=.teamcity/docker-seccomp.json --shm-size=8gb" } bashNodeScript { name = "Collect results"