forked from cocos/cocos-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspawn-runner.js
69 lines (62 loc) · 1.93 KB
/
spawn-runner.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// so as to run tests in page-level
if (cc.sys.platform === cc.sys.EDITOR_CORE) {
var Ipc = require('ipc');
var Path = require('path');
var Url = require('url');
var Electron = require('electron');
var spawnWorker = function (title, scriptUrl, debug) {
describe(title, function () {
if (debug) {
this.timeout(0);
}
var win;
// close window afterward
after(function ( done ) {
win.once('closed', function () {
win = null;
done();
});
if (!debug) {
win.close();
}
});
//
it('should running on page-level', function( done ) {
this.timeout(0);
Ipc.on('runner:end', function () {
done();
});
win = new Electron.BrowserWindow({
title: title,
width: 400,
height: 400,
show: !!debug,
});
if (debug) {
win.openDevTools();
}
var query = {scriptUrl: scriptUrl};
var url = Url.format({
protocol: 'file',
pathname: Path.resolve(__dirname, 'runner.html'),
slashes: true,
hash: encodeURIComponent(JSON.stringify(query))
});
win.loadUrl(url);
});
});
};
module.exports = (function (descCtx, scriptUrl, debug, testInPage, testInCore) {
if (testInPage) {
var title = descCtx.title;
spawnWorker(title, scriptUrl, debug);
}
var shouldStopCore = testInCore;
return shouldStopCore;
});
}
else {
module.exports = function () {
return true;
};
}