Skip to content

Commit

Permalink
test(e2e): upload tests (#16078)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley authored Oct 25, 2018
1 parent 3c7fee5 commit 6b8c87e
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
70 changes: 70 additions & 0 deletions core/scripts/screenshot/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions core/src/components/modal/test/basic/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions core/src/components/modal/test/standalone/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions core/src/components/searchbar/test/basic/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
2 changes: 2 additions & 0 deletions core/src/components/searchbar/test/standalone/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
2 changes: 2 additions & 0 deletions core/src/components/searchbar/test/toolbar/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit 6b8c87e

Please sign in to comment.