tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

smoke.mjs (2943B)


      1 /**
      2 * @license
      3 * Copyright 2023 Google Inc.
      4 * SPDX-License-Identifier: Apache-2.0
      5 */
      6 
      7 import {ok} from 'node:assert';
      8 import {execSync} from 'node:child_process';
      9 import {parseArgs} from 'node:util';
     10 
     11 import {AngularProjectMulti, AngularProjectSingle} from './projects.mjs';
     12 
     13 process.on('uncaughtException', (error, origin) => {
     14  console.error('Unhandled Error at:', error);
     15  console.error('Origin:', origin);
     16  process.exit(1);
     17 });
     18 process.on('unhandledRejection', (reason, promise) => {
     19  console.error('Unhandled Rejection at:', promise);
     20  console.error('Reason:', reason);
     21  process.exit(1);
     22 });
     23 
     24 const {values: args} = parseArgs({
     25  options: {
     26    runner: {
     27      type: 'string',
     28      short: 'r',
     29      default: undefined,
     30    },
     31    name: {
     32      type: 'string',
     33      short: 'n',
     34      default: undefined,
     35    },
     36  },
     37 });
     38 
     39 function verifyAngularCliInstalled() {
     40  if (process.env.CI) {
     41    // Need to install in CI
     42    execSync(
     43      'npm install -g @angular/cli@latest @angular-devkit/schematics-cli',
     44    );
     45    return;
     46  }
     47  const userDeps = execSync('npm list -g --depth=0');
     48 
     49  if (
     50    !userDeps.includes('@angular/cli') ||
     51    !userDeps.includes('@angular-devkit/schematics-cli')
     52  ) {
     53    console.error(
     54      'Angular CLI not installed run `npm install -g @angular/cli @angular-devkit/schematics-cli`',
     55    );
     56    process.exit(1);
     57  }
     58 }
     59 
     60 verifyAngularCliInstalled();
     61 
     62 if (!args.runner) {
     63  const runners = ['node', 'jest', 'jasmine', 'mocha'];
     64  const groups = [];
     65 
     66  for (const runner of runners) {
     67    groups.push([
     68      new AngularProjectSingle(runner),
     69      new AngularProjectMulti(runner),
     70    ]);
     71  }
     72 
     73  const angularProjects = await Promise.allSettled(
     74    groups.flat().map(async project => {
     75      return await project.create();
     76    }),
     77  );
     78  ok(
     79    angularProjects.every(project => {
     80      return project.status === 'fulfilled';
     81    }),
     82    'Building of 1 or more projects failed!',
     83  );
     84 
     85  for await (const runnerGroup of groups) {
     86    const smokeResults = await Promise.allSettled(
     87      runnerGroup.map(async project => {
     88        return await project.runSmoke();
     89      }),
     90    );
     91    ok(
     92      smokeResults.every(project => {
     93        return project.status === 'fulfilled';
     94      }),
     95      `Smoke test for ${runnerGroup[0].runner} failed! ${smokeResults.map(
     96        project => {
     97          return project.reason;
     98        },
     99      )}`,
    100    );
    101  }
    102 } else {
    103  const single = new AngularProjectSingle(args.testRunner, args.name);
    104  const multi = new AngularProjectMulti(args.testRunner, args.name);
    105 
    106  // Create Angular projects
    107  await Promise.all([single.create(), multi.create()]);
    108 
    109  // Add schematic to projects
    110  // Note we can't use Promise.all
    111  // As it will try to install browser and fail
    112  await single.runNgAdd();
    113  await multi.runNgAdd();
    114 
    115  // Run Angular E2E smoke tests
    116  await Promise.all([single.runSmoke(), multi.runSmoke()]);
    117 }
    118 
    119 console.log(`
    120 <---------------->
    121 Smoke test passed!
    122 `);