-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.js
50 lines (43 loc) · 1.14 KB
/
tester.js
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
const gameModulePath = process.argv[2];
const squishPath = process.argv[3];
const path = require('path');
const fs = require('fs');
process.env.SQUISH_PATH = squishPath;
const runTest = (game) => {
const gameRoot = game.getRoot && game.getRoot();
if (!game.getLayers) {
throw new Error('No getLayers method found');
} else {
game.getLayers().forEach(layer => {
if (!layer.root) {
throw new Error("No root found for layer");
}
});
}
};
if (gameModulePath) {
console.log(`using game path ${gameModulePath}`);
const rootDir = gameModulePath.replace('index.js', '');
const nodeModulesPath = path.resolve('node_modules');
fs.symlink(nodeModulesPath, `${rootDir}/node_modules`, 'dir', (err) => {
if (!err) {
try {
const timeout = setTimeout(() => {
throw new Error("Test timed out");
}, 5000);
const gameClass = require(gameModulePath);
const game = new gameClass();
runTest(game);
clearTimeout(timeout);
} catch (err) {
console.log(err);
throw new Error(err);
}
} else {
console.log('error');
console.log(err);
}
});
} else {
console.log('no path');
}