/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/scenes/e2e/screenshot.ts
53 строки
1 KB
Kristiyan Kostadinov
build: reuse tslint rules for docs site and fix failures
29 апр 2025, 15:02
29 апр 2025, 15:02
da9627d
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import * as fs from 'fs'; import * as path from 'path'; import {by, element} from 'protractor'; const OUTPUT_DIR = path.join(__dirname, '..', '..', 'src', 'assets', 'screenshots'); export class Screenshot { /** The filename used to store the screenshot. */ get filename(): string { return ( this.id .toLowerCase() .replace(/\s/g, '_') .replace(/[^/a-z0-9_-]+/g, '') + '.scene.png' ); } /** The full path to the screenshot */ get fullPath(): string { return path.resolve(OUTPUT_DIR, this.filename); } constructor(readonly id: string) {} async takeScreenshot() { const png = await element(by.tagName('app-scene-viewer')).takeScreenshot(); this.storeScreenshot(png); } /** Replaces the existing screenshot with the newly generated one. */ storeScreenshot(png: string) { if (!fs.existsSync(OUTPUT_DIR)) { fs.mkdirSync(OUTPUT_DIR, '444'); } if (fs.existsSync(OUTPUT_DIR)) { fs.writeFileSync(this.fullPath, png, {encoding: 'base64'}); } } } export function screenshot(id: string): Promise<void> { const s = new Screenshot(id); return s.takeScreenshot(); }