diff --git a/core/scripts/screenshot/ci.js b/core/scripts/screenshot/ci.js index 7ca33b98546..51c77a025dd 100644 --- a/core/scripts/screenshot/ci.js +++ b/core/scripts/screenshot/ci.js @@ -106,9 +106,79 @@ class CIScreenshotConnector extends IonicConnector { timespan.finish(`publishing build finished`); + await this.uploadTests(results); + return results; } + async uploadTests(results) { + const timespan = this.logger.createTimeSpan(`uploading tests started`); + + const appRoot = path.join(__dirname, '..', '..'); + let uploadPaths = []; + + const cssDir = path.join(appRoot, 'css'); + fs.readdirSync(cssDir).forEach(cssFile => { + uploadPaths.push(path.join(cssDir, cssFile)); + }); + + uploadPaths.push(path.join(appRoot, 'scripts', 'testing', 'styles.css')); + + const distDir = path.join(appRoot, 'dist'); + uploadPaths.push(path.join(distDir, 'ionic.js')); + + const distIonicDir = path.join(distDir, 'ionic'); + fs.readdirSync(distIonicDir).forEach(distIonicFile => { + uploadPaths.push(path.join(distIonicDir, distIonicFile)); + }); + + // const distIonicSvgDir = path.join(distIonicDir, 'svg'); + // fs.readdirSync(distIonicSvgDir).forEach(distIonicSvgFile => { + // uploadPaths.push(path.join(distIonicSvgDir, distIonicSvgFile)); + // }); + + results.currentBuild.screenshots.forEach(screenshot => { + const testDir = path.dirname(screenshot.testPath); + const testIndexHtml = path.join(appRoot, testDir, 'index.html'); + if (!uploadPaths.includes(testIndexHtml)) { + uploadPaths.push(testIndexHtml); + } + }); + + uploadPaths = uploadPaths.filter(p => p.endsWith('.js') || p.endsWith('.css') || p.endsWith('.html') || p.endsWith('.svg')); + + const fileCount = uploadPaths.length; + + const uploadBatches = []; + while (uploadPaths.length > 0) { + uploadBatches.push(uploadPaths.splice(0, 20)); + } + + for (const batch of uploadBatches) { + await Promise.all(batch.map(async uploadPath => { + const stream = fs.createReadStream(uploadPath); + const relPath = path.relative(appRoot, uploadPath); + const key = `test/${results.currentBuild.id}/${relPath}`; + + let contentType = 'text/plain'; + if (uploadPath.endsWith('.js')) { + contentType = 'application/javascript' + } else if (uploadPath.endsWith('.css')) { + contentType = 'text/css' + } else if (uploadPath.endsWith('.html')) { + contentType = 'text/html' + } else if (uploadPath.endsWith('.svg')) { + contentType = 'image/svg+xml' + } + + this.logger.debug(`uploading: ${key} ${contentType}`); + await s3.upload({ Bucket: S3_BUCKET, Key: key, Body: stream, ContentType: contentType }).promise(); + })); + } + + timespan.finish(`uploading tests finished: ${fileCount} files`); + } + async getScreenshotCache() { const timespan = this.logger.createTimeSpan(`get screenshot cache started`, true); diff --git a/core/src/components/modal/test/basic/e2e.ts b/core/src/components/modal/test/basic/e2e.ts index 5d566922b1c..8f8ac8d077c 100644 --- a/core/src/components/modal/test/basic/e2e.ts +++ b/core/src/components/modal/test/basic/e2e.ts @@ -6,8 +6,10 @@ it('modal: basic', async () => { }); await page.click('.e2ePresentModal'); - const popover = await page.find('ion-modal'); - expect(popover).not.toBeNull(); + + const modal = await page.find('ion-modal'); + await modal.waitForVisible(); + await page.waitFor(250); const compare = await page.compareScreenshot(); expect(compare).toMatchScreenshot(); diff --git a/core/src/components/modal/test/standalone/e2e.ts b/core/src/components/modal/test/standalone/e2e.ts index a32ca1cb39f..097eb1ee7c5 100644 --- a/core/src/components/modal/test/standalone/e2e.ts +++ b/core/src/components/modal/test/standalone/e2e.ts @@ -6,8 +6,10 @@ it('modal: standalone', async () => { }); await page.click('#basic'); - const popover = await page.find('ion-modal'); - expect(popover).not.toBeNull(); + + const modal = await page.find('ion-modal'); + await modal.waitForVisible(); + await page.waitFor(250); const compare = await page.compareScreenshot(); expect(compare).toMatchScreenshot(); diff --git a/core/src/components/searchbar/test/basic/e2e.ts b/core/src/components/searchbar/test/basic/e2e.ts index b3314157cf4..d9f66b549c6 100644 --- a/core/src/components/searchbar/test/basic/e2e.ts +++ b/core/src/components/searchbar/test/basic/e2e.ts @@ -5,6 +5,8 @@ it('searchbar: basic', async () => { url: '/src/components/searchbar/test/basic?ionic:_testing=true' }); + await page.waitFor(250); + const compare = await page.compareScreenshot(); expect(compare).toMatchScreenshot(); }); diff --git a/core/src/components/searchbar/test/standalone/e2e.ts b/core/src/components/searchbar/test/standalone/e2e.ts index 2754d56848b..2d3d88157a5 100644 --- a/core/src/components/searchbar/test/standalone/e2e.ts +++ b/core/src/components/searchbar/test/standalone/e2e.ts @@ -5,6 +5,8 @@ it('searchbar: standalone', async () => { url: '/src/components/searchbar/test/standalone?ionic:_testing=true' }); + await page.waitFor(250); + const compare = await page.compareScreenshot(); expect(compare).toMatchScreenshot(); }); diff --git a/core/src/components/searchbar/test/toolbar/e2e.ts b/core/src/components/searchbar/test/toolbar/e2e.ts index 551293194bf..b2eea4a4a0d 100644 --- a/core/src/components/searchbar/test/toolbar/e2e.ts +++ b/core/src/components/searchbar/test/toolbar/e2e.ts @@ -5,6 +5,8 @@ it('searchbar: toolbar', async () => { url: '/src/components/searchbar/test/toolbar?ionic:_testing=true' }); + await page.waitFor(250); + const compare = await page.compareScreenshot(); expect(compare).toMatchScreenshot(); });