aboutsummaryrefslogtreecommitdiff
path: root/test/travis-ufuzz.js
blob: 579b7448e4adb6a68b6bcef79cd58ae3be59c4a1 (about) (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
"use strict";

var period = 45 * 60 * 1000;
var wait = 2 * 60 * 1000;
var ping = 5 * 60 * 1000;
if (process.argv.length > 2) {
    var token = process.argv[2];
    var branch = process.argv[3] || "v" + require("../package.json").version;
    var project = encodeURIComponent(process.argv[4] || "mishoo/UglifyJS2");
    (function init() {
        setTimeout(init, period + wait);
        var options = require("url").parse("https://api.travis-ci.org/repo/" + project + "/requests");
        options.method = "POST";
        options.headers = {
            "Content-Type": "application/json",
            "Travis-API-Version": 3,
            "Authorization": "token " + token
        };
        require("https").request(options, function(res) {
            console.log("HTTP", res.statusCode);
            console.log(JSON.stringify(res.headers, null, 2));
            console.log();
            res.setEncoding("utf8");
            res.on("data", console.log);
        }).on("error", console.error).end(JSON.stringify({
            request: {
                message: "ufuzz testing (when idle)",
                branch: branch,
                config: {
                    merge_mode: "replace",
                    language: "node_js",
                    node_js: "9",
                    sudo: false,
                    script: "node test/travis-ufuzz"
                }
            }
        }));
    })();
} else {
    var child = require("child_process").spawn("node", [
        "--max-old-space-size=2048",
        "test/ufuzz"
    ], {
        stdio: [ "ignore", "pipe", "pipe" ]
    }).on("exit", function() {
        console.log(line);
        clearInterval(keepAlive);
        clearTimeout(timer);
    });
    var line = "";
    child.stdout.on("data", function(data) {
        line += data;
    });
    child.stderr.on("data", function() {
        process.exitCode = 1;
    }).pipe(process.stdout);
    var keepAlive = setInterval(function() {
        var end = line.lastIndexOf("\r");
        console.log(line.slice(line.lastIndexOf("\r", end - 1) + 1, end));
        line = line.slice(end + 1);
    }, ping);
    var timer = setTimeout(function() {
        clearInterval(keepAlive);
        child.removeAllListeners("exit");
        child.kill();
    }, period);
}