File size: 6,096 Bytes
30c32c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
const tap = require('tap');
const Runtime = require('../../src/engine/runtime');
const {Map} = require('immutable');

const test = tap.test;

test('setFramerate emits an event', t => {
    t.plan(1);
    const rt = new Runtime();
    rt.addListener('FRAMERATE_CHANGED', framerate => {
        if (framerate === 13) {
            t.pass();
        }
    });
    rt.setFramerate(13);
    t.end();
});

test('setFramerate and setCompatibilityMode do not emit a stop event if not running', t => {
    const rt = new Runtime();
    rt.addListener('RUNTIME_STOPPED', () => {
        t.fail();
    });
    rt.setFramerate(13);
    rt.setCompatibilityMode(true);
    t.end();
});

test('setInterpolation emits an event', t => {
    t.plan(1);
    const rt = new Runtime();
    rt.addListener('INTERPOLATION_CHANGED', enabled => {
        if (enabled) {
            t.pass();
        }
    });
    rt.setInterpolation(true);
    t.end();
});

test('setInterpolation does not restart runtime if not running', t => {
    const rt = new Runtime();
    let started = false;
    let stopped = false;
    rt.addListener('RUNTIME_STARTED', () => {
        started = true;
    });
    rt.addListener('RUNTIME_STOPPED', () => {
        stopped = true;
    });
    rt.setInterpolation(true);
    t.equal(started, false);
    t.equal(stopped, false);
    t.end();
});

test('Stopping the runtime emits an event', t => {
    const rt = new Runtime();
    rt.start();
    let stopped = false;
    rt.addListener('RUNTIME_STOPPED', () => {
        stopped = true;
    });
    rt.stop();
    t.equal(stopped, true);
    t.end();
});

test('Stop does not emit an event if already stopped', t => {
    const rt = new Runtime();
    let stopped = false;
    rt.addListener('RUNTIME_STOPPED', () => {
        stopped = true;
    });
    rt.stop();
    t.equal(stopped, false);
    t.end();
});

test('setRuntimeOptions emits an event', t => {
    t.plan(1);
    const rt = new Runtime();
    rt.addListener('RUNTIME_OPTIONS_CHANGED', options => {
        if (options.option === 17) {
            t.pass();
        }
    });
    rt.setRuntimeOptions({option: 17});
    t.end();
});

test('setRuntimeOptions supports partial updates', t => {
    t.plan(1);
    const rt = new Runtime();
    rt.setRuntimeOptions({option: 17});
    rt.addListener('RUNTIME_OPTIONS_CHANGED', options => {
        if (options.option === 17) {
            t.pass();
        }
    });
    rt.setRuntimeOptions({otherOption: 1});
    t.end();
});

test('setCompilerOptions emits an event', t => {
    t.plan(1);
    const rt = new Runtime();
    rt.addListener('COMPILER_OPTIONS_CHANGED', options => {
        if (options.option === 17) {
            t.pass();
        }
    });
    rt.setCompilerOptions({option: 17});
    t.end();
});

test('setCompilerOptions supports partial updates', t => {
    t.plan(1);
    const rt = new Runtime();
    rt.setCompilerOptions({option: 17});
    rt.addListener('COMPILER_OPTIONS_CHANGED', options => {
        if (options.option === 17) {
            t.pass();
        }
    });
    rt.setCompilerOptions({otherOption: 1});
    t.end();
});

test('maxClones runtime option', t => {
    const rt = new Runtime();
    rt.setRuntimeOptions({maxClones: 10});
    for (let i = 0; i < 10; i++) {
        t.equal(rt.clonesAvailable(), true);
        rt.changeCloneCounter(1);
    }
    rt.changeCloneCounter(1);
    t.equal(rt.clonesAvailable(), false);
    t.end();
});

test('stageWidth and stageHeight', t => {
    const rt = new Runtime();
    t.equal(rt.stageWidth, 480);
    t.equal(rt.stageHeight, 360);
    t.end();
});

test('debug', t => {
    const rt = new Runtime();
    t.equal(rt.debug, false);
    rt.enableDebug();
    t.equal(rt.debug, true);
    t.end();
});

test('setStageSize preserves monitor position relative to center of stage', t => {
    const rt = new Runtime();
    rt.requestAddMonitor(new Map([
        ['id', 'abc'],
        // top right corner
        ['x', 0],
        ['y', 0]
    ]));
    rt.setStageSize(640, 362);
    const finalState = rt.getMonitorState().get('abc');
    t.equal(finalState.get('x'), 80);
    t.equal(finalState.get('y'), 1);
    t.end();
});

test('setStageSize argument range', t => {
    const rt = new Runtime();

    rt.once('STAGE_SIZE_CHANGED', (width, height) => {
        t.equal(width, 101);
        t.equal(height, 103);
    });
    rt.setStageSize(101, 103);

    rt.once('STAGE_SIZE_CHANGED', (width, height) => {
        t.equal(width, 1);
        t.equal(height, 1);
    });
    rt.setStageSize(-3.1, 0);

    rt.once('STAGE_SIZE_CHANGED', (width, height) => {
        t.equal(width, 99);
        t.equal(height, 10000);
    });
    rt.setStageSize(99.3, 10000);

    t.end();
});

test('getNumberOfCloudVariables', t => {
    const rt = new Runtime();

    t.equal(rt.getNumberOfCloudVariables(), 0);
    rt.addCloudVariable();
    t.equal(rt.getNumberOfCloudVariables(), 1);
    rt.addCloudVariable();
    t.equal(rt.getNumberOfCloudVariables(), 2);
    rt.removeCloudVariable();
    t.equal(rt.getNumberOfCloudVariables(), 1);
    rt.removeCloudVariable();
    t.equal(rt.getNumberOfCloudVariables(), 0);

    rt.dispose();
    t.equal(rt.getNumberOfCloudVariables(), 0);
    rt.addCloudVariable();
    t.equal(rt.getNumberOfCloudVariables(), 1);

    t.end();
});

test('currentStepTime default value', t => {
    const rt = new Runtime();
    t.type(rt.currentStepTime, 'number');
    t.ok(rt.currentStepTime > 0);
    t.end();
});

test('convertToPackagedRuntime', t => {
    const rt = new Runtime();
    t.equal(rt.isPackaged, false);
    rt.convertToPackagedRuntime();
    t.equal(rt.isPackaged, true);
    t.end();
});

test('convertToPackagedRuntime and attachStorage call order', t => {
    try {
        const rt1 = new Runtime();
        rt1.attachStorage({});
        rt1.convertToPackagedRuntime();
    } catch (e) {
        t.equal(e.message, 'convertToPackagedRuntime must be called before attachStorage');
    }
    const rt2 = new Runtime();
    rt2.convertToPackagedRuntime();
    rt2.attachStorage({});
    t.end();
});