summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/bin/try-runner.js
blob: 1bab722ad1e0191809980217fa92344915f26e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

/*
 * A small test runner/reporter for node-based tests,
 * which are run via taskcluster node(debugger).
 */

const { execFileSync } = require("child_process");
const { chdir } = require("process");
const path = require("path");

const dbgPath = path.join(__dirname, "..");

function execOut(...args) {
  let out;
  let err;
  try {
    out = execFileSync(...args, { silent: true });
  } catch (e) {
    out = e.stdout;
    err = e.stderr;
  }
  return { out: out.toString(), err: err && err.toString() };
}

function logErrors(tool, errors) {
  for (const error of errors) {
    console.log(`TEST-UNEXPECTED-FAIL ${tool} | ${error}`);
  }
  return errors;
}

function logStart(name) {
  console.log(`TEST START | ${name}`);
}

function jest() {
  logStart("Jest");
  const { out } = execOut("yarn", ["test-ci"]);
  // Remove the non-JSON logs mixed with the JSON output by yarn.
  const jsonOut = out.substring(out.indexOf("{"), out.lastIndexOf("}") + 1);
  const results = JSON.parse(jsonOut);

  // The individual failing tests are in jammed into the same message string :/
  const errors = [].concat(
    ...results.testResults.map(r =>
      r.message.split("\n").filter(l => l.includes("●"))
    )
  );

  logErrors("jest", errors);
  return errors.length == 0;
}

function stylelint() {
  logStart("Stylelint");
  const { out } = execOut("yarn", ["lint:css"]);
  console.log(out);
  const errors = logErrors("stylelint", out.match(/ {2}✖(.*)/g) || []);

  return errors.length == 0;
}

function lintMd() {
  logStart("Remark");

  const { err } = execOut("yarn", ["lint:md"]);
  const errors = logErrors("remark", (err || "").match(/warning(.+)/g) || []);
  return errors.length == 0;
}

chdir(dbgPath);
const jestPassed = jest();
const styleLintPassed = stylelint();
const remarkPassed = lintMd();

const success =
  jestPassed &&
  styleLintPassed &&
  remarkPassed;

console.log({
  jestPassed,
  styleLintPassed,
  remarkPassed,
});

if (!success) {
  console.log(
    "[debugger-node-test-runner] You can find documentation about the " +
      "debugger node tests at https://firefox-source-docs.mozilla.org/devtools/tests/node-tests.html"
  );
}

process.exitCode = success ? 0 : 1;
console.log("CODE", process.exitCode);