1 // This package needs to be install:
4 // npm install browser-ui-test
6 const fs = require("fs");
7 const path = require("path");
8 const {Options, runTest} = require('browser-ui-test');
11 console.log("rustdoc-js options:");
12 console.log(" --doc-folder [PATH] : location of the generated doc folder");
13 console.log(" --file [PATH] : file to run (can be repeated)");
14 console.log(" --debug : show extra information about script run");
15 console.log(" --show-text : render font in pages");
16 console.log(" --no-headless : disable headless mode");
17 console.log(" --help : show this message then quit");
18 console.log(" --tests-folder [PATH] : location of the .GOML tests folder");
21 function parseOptions(args) {
30 var correspondances = {
31 "--doc-folder": "doc_folder",
32 "--tests-folder": "tests_folder",
34 "--show-text": "show_text",
35 "--no-headless": "no_headless",
38 for (var i = 0; i < args.length; ++i) {
39 if (args[i] === "--doc-folder"
40 || args[i] === "--tests-folder"
41 || args[i] === "--file") {
43 if (i >= args.length) {
44 console.log("Missing argument after `" + args[i - 1] + "` option.");
47 if (args[i - 1] !== "--file") {
48 opts[correspondances[args[i - 1]]] = args[i];
50 opts["files"].push(args[i]);
52 } else if (args[i] === "--help") {
55 } else if (correspondances[args[i]]) {
56 opts[correspondances[args[i]]] = true;
58 console.log("Unknown option `" + args[i] + "`.");
59 console.log("Use `--help` to see the list of options");
63 if (opts["tests_folder"].length < 1) {
64 console.log("Missing `--tests-folder` option.");
65 } else if (opts["doc_folder"].length < 1) {
66 console.log("Missing `--doc-folder` option.");
73 async function main(argv) {
74 let opts = parseOptions(argv.slice(2));
79 const options = new Options();
81 // This is more convenient that setting fields one by one.
84 "--variable", "DOC_PATH", opts["doc_folder"],
89 if (opts["show_text"]) {
90 args.push("--show-text");
92 if (opts["no_headless"]) {
93 args.push("--no-headless");
95 options.parseArguments(args);
97 console.error(`invalid argument: ${error}`);
103 if (opts["files"].length === 0) {
104 files = fs.readdirSync(opts["tests_folder"]).filter(file => path.extname(file) == ".goml");
106 files = opts["files"].filter(file => path.extname(file) == ".goml");
110 for (var i = 0; i < files.length; ++i) {
111 const testPath = path.join(opts["tests_folder"], files[i]);
112 await runTest(testPath, options).then(out => {
113 const [output, nb_failures] = out;
115 if (nb_failures > 0) {