github.com/rohankumardubey/nomad@v0.11.8/scripts/screenshots/src/index.js (about)

     1  const puppeteer = require("puppeteer");
     2  const {
     3    capture,
     4    wait,
     5    error,
     6    click,
     7    clickJob,
     8    clickTab,
     9    clickMainMenu,
    10    clickX
    11  } = require("./utils");
    12  
    13  const HOST = process.env.EMBER_HOST || "http://localhost:4200";
    14  console.log(`Using host ${HOST}...`);
    15  
    16  const ANSI_YELLOW = "\x1b[33m%s\x1b[0m";
    17  
    18  (async () => {
    19    const startTime = Date.now();
    20    console.log("Preparing puppeteer...");
    21  
    22    // Create a new browser and tab
    23    const browser = await puppeteer.launch({
    24      // Docker related chrome flags
    25      args: [
    26        "--no-sandbox",
    27        "--disable-setuid-sandbox",
    28        "--disable-dev-shm-usage"
    29      ]
    30    });
    31    const page = await browser.newPage();
    32  
    33    // Make sure the page is 4K is high-dpi scaling
    34    page.setViewport({ width: 1440, height: 900, deviceScaleFactor: 2 });
    35    console.log("Loading Nomad UI...");
    36    console.log(
    37      ANSI_YELLOW,
    38      "\n!! Make sure to use the everyFeature Mirage scenario !!\n"
    39    );
    40  
    41    try {
    42      await page.goto(`${HOST}/ui/`);
    43    } catch (err) {
    44      await error(
    45        browser,
    46        "Could not load the Nomad UI. Is the Ember server running?"
    47      );
    48    }
    49  
    50    // Give Mirage a chance to settle
    51    console.log("Waiting for Mirage...");
    52    await wait(5000);
    53    console.log("Starting capture sequence!\n");
    54  
    55    // DEBUG: log the URL on all navigations
    56    monitorURL(page);
    57  
    58    await capture(page, "jobs-list");
    59  
    60    await clickJob(page, "service");
    61    await capture(page, "job-detail-service");
    62    await page.goBack();
    63  
    64    await clickJob(page, "batch");
    65    await capture(page, "job-detail-batch");
    66    await page.goBack();
    67  
    68    await clickJob(page, "system");
    69    await capture(page, "job-detail-system");
    70    await page.goBack();
    71  
    72    await clickJob(page, "periodic");
    73    await capture(page, "job-detail-periodic");
    74    await click(page, "tr.job-row");
    75    await capture(page, "job-detail-periodic-child");
    76    await page.goBack();
    77    await page.goBack();
    78  
    79    await clickJob(page, "parameterized");
    80    await capture(page, "job-detail-parameterized");
    81    await click(page, "tr.job-row");
    82    await capture(page, "job-detail-parameterized-child");
    83    await page.goBack();
    84    await page.goBack();
    85  
    86    await clickJob(page, "service");
    87  
    88    await clickTab(page, "Definition");
    89    await capture(page, "job-detail-tab-definition");
    90    await page.click(".boxed-section .button.is-light.is-compact.pull-right");
    91    await capture(page, "job-detail-tab-definition-editing");
    92  
    93    await clickTab(page, "Versions");
    94    await capture(page, "job-detail-tab-versions");
    95    await page.click(".timeline-object .button.is-light.is-compact.pull-right");
    96    await capture(page, "job-detail-tab-versions-expanded");
    97  
    98    await clickTab(page, "Deployments");
    99    await capture(page, "job-detail-tab-deployments");
   100    await page.click(".timeline-object .button.is-light.is-compact.pull-right");
   101    await capture(page, "job-detail-tab-deployments-expanded");
   102  
   103    await clickTab(page, "Allocations");
   104    await capture(page, "job-detail-tab-allocations");
   105  
   106    await clickTab(page, "Evaluations");
   107    await capture(page, "job-detail-tab-evaluations");
   108  
   109    await clickMainMenu(page, "Jobs");
   110    await page.click(".toolbar-item .button.is-primary");
   111    await capture(page, "job-run-empty");
   112    // Fill in the code editor somehow
   113    // Capture the plan stage
   114  
   115    await clickMainMenu(page, "Jobs");
   116    await clickJob(page, "service");
   117    await click(page, ".task-group-row");
   118    await capture(page, "task-group");
   119  
   120    await clickMainMenu(page, "Jobs");
   121    await clickJob(page, "service");
   122  
   123    const allocCount = await page.$$eval(".allocation-row", s => s.length);
   124    for (let i = 1; i <= allocCount; i++) {
   125      await click(page, `.allocation-row:nth-of-type(${i}) a.is-primary`);
   126      await capture(page, `allocation-${i}`);
   127      await page.goBack();
   128      await wait(2000);
   129    }
   130  
   131    await click(page, ".allocation-row a.is-primary");
   132    await click(page, ".task-row");
   133    await capture(page, "task-detail");
   134  
   135    await clickTab(page, "Logs");
   136    await capture(page, "task-logs");
   137  
   138    await clickMainMenu(page, "Clients");
   139    await capture(page, "clients-list");
   140  
   141    const clientCount = await page.$$eval(".client-node-row", s => s.length);
   142    for (let i = 1; i <= clientCount; i++) {
   143      await click(page, `.client-node-row:nth-of-type(${i})`);
   144      await capture(page, `client-detail-${i}`);
   145      await page.goBack();
   146      await wait(500);
   147    }
   148  
   149    await clickMainMenu(page, "Servers");
   150    await capture(page, "servers-list");
   151  
   152    await click(page, `.server-agent-row:nth-of-type(2)`);
   153    await capture(page, "server-detail");
   154  
   155    await clickX(page, '//a[contains(text(), "ACL Tokens")]');
   156    await capture(page, "acl-tokens");
   157  
   158    console.log(`All done! ${humanDuration(Date.now() - startTime)}`);
   159    process.exit();
   160  })();
   161  
   162  async function* watchURL(page) {
   163    while (true) {
   164      await page.waitForNavigation();
   165      yield page.url();
   166    }
   167  }
   168  
   169  async function monitorURL(page) {
   170    for await (let url of watchURL(page)) {
   171      console.log(`=> ${url}`);
   172    }
   173  }
   174  
   175  function humanDuration(duration) {
   176    const ms = duration % 1000;
   177    const s = Math.floor((duration / 1000) % 60);
   178    const m = Math.floor(duration / 1000 / 60);
   179  
   180    const fs = s < 10 ? `0${s}` : `${s}`;
   181    const fms = ms < 10 ? `00${ms}` : ms < 100 ? `0${ms}` : `${ms}`;
   182  
   183    if (m) return `${m}m ${fs}s ${fms}ms`;
   184    else if (s) return `${fs}s ${fms}ms`;
   185    return `${fms}ms`;
   186  }