mirror of
				https://github.com/ionic-team/ionic-framework.git
				synced 2025-11-04 03:48:13 +08:00 
			
		
		
		
	test(e2e): upload tests (#16078)
This commit is contained in:
		@ -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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user