summaryrefslogtreecommitdiff
path: root/js/test/Common/run.js
blob: 90f457c1e93881cbc7bd91aaeb7c95d4bd554924 (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
// **********************************************************************
//
// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

var es5 = process.argv[2] === "--es5";
if(es5)
{
    process.argv.splice(2, 1);
}

var Ice = require(es5 ? "ice/src/es5" : "ice").Ice;

var write = function(msg)
{
    process.stdout.write(msg);
};

var writeLine = function(msg)
{
    this.write(msg + "\n");
};

var exception = function(ex)
{
    console.log(ex.toString());
    if(ex.stack)
    {
        console.log(ex.stack);
    }
    process.exit(1);
};

var id = new Ice.InitializationData();
id.properties = Ice.createProperties(process.argv);
var exe = process.argv[2];
var test = module.require(exe);
if(exe === "Server" || exe === "ServerAMD")
{
    var ready = new Ice.Promise();
    test = exe === "Server" ? test._server : test._serveramd;
    test({write: write, writeLine: writeLine}, id, ready).catch(exception);
    ready.then(() => console.log("server ready"));
}
else
{
    test._test({write: write, writeLine: writeLine}, id).catch(exception);
}