-
Notifications
You must be signed in to change notification settings - Fork 5
/
compile.js
137 lines (128 loc) · 4.92 KB
/
compile.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
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
const fs = require("fs");
const path = require("path");
const assert = require("assert").strict;
qx.Class.define("qxl.apiviewer.compile.CompilerApi", {
extend: qx.tool.cli.api.CompilerApi,
members: {
async load() {
this.addListener(
"changeCommand",
function () {
let command = this.getCommand();
if (command instanceof qx.tool.cli.commands.Test) {
command.addListener("runTests", this.__appTesting, this);
if (command.setNeedsServer) {
command.setNeedsServer(true);
}
}
},
this
);
return this.base(arguments);
},
// Test application in headless Chrome and Firefox
// see https://github.com/microsoft/playwright/blob/master/docs/api.md
__appTesting: async function (data) {
let result = data.getData();
let nodes = ["Packages", "data", "ui"];
let href = `http://localhost:8080/`;
return new qx.Promise(async function (resolve) {
try {
const playwright = this.require("playwright");
for (const browserType of ["chromium", "firefox" /*, 'webkit'*/]) {
console.info("APIVIEWER: Running test in " + browserType);
const launchArgs = {
args: ["--no-sandbox", "--disable-setuid-sandbox"]
};
const browser = await playwright[browserType].launch(launchArgs);
const context = await browser.newContext();
const page = await context.newPage();
page.on("pageerror", exception => {
qx.tool.compiler.Console.error(`Error on page ${page.url()}: ${exception}`);
result.setExitCode(1);
resolve();
});
await page.goto(href);
let url = page.url();
for (const node of nodes) {
qx.tool.compiler.Console.info(` >>> Clicking on node '${node}'`);
await page.click(`.qx-main >> text=${node}`);
for (let i = 0; i < 10; i++) {
await page.keyboard.press("ArrowDown");
await page.waitForTimeout(1000);
// assert that url hash has changed
assert.notEqual(page.url(), url);
url = page.url();
qx.tool.compiler.Console.log(" - " + url);
}
}
await browser.close();
}
resolve();
} catch (e) {
qx.tool.compiler.Console.error(e);
result.setExitCode(1);
resolve();
}
}, this);
}
}
});
qx.Class.define("qxl.apiviewer.compile.LibraryApi", {
extend: qx.tool.cli.api.LibraryApi,
members: {
__getMakersForClass(className) {
let command = this.getCompilerApi().getCommand();
let makers = command.getMakers();
return makers.filter(maker => {
let res = maker.getApplications().find(app => app.getClassName() === className);
return res;
});
},
async load() {
let command = this.getCompilerApi().getCommand();
if (command instanceof qx.tool.cli.commands.Compile) {
command.addListener("writtenMetaData", async function(e) {
let maker = this.__getMakersForClass("qxl.apiviewer.Application")[0];
if (!maker) {
return;
}
let analyser = maker.getAnalyser();
let lib = analyser.findLibrary("qxl.apiviewer");
const folder = path.join(lib.getRootDir(), lib.getSourcePath(), "qxl/apiviewer/dao");
// preload depend classes
require(path.join(folder, "Node.js"));
require(path.join(folder, "ClassItem.js"));
// load the rest
fs.readdirSync(folder).forEach(file => {
if (path.extname(file) === ".js") {
require(path.join(folder, file));
}
});
require(path.join(lib.getRootDir(), lib.getSourcePath(), "qxl/apiviewer/ClassLoader.js"));
require(path.join(lib.getRootDir(), lib.getSourcePath(), "qxl/apiviewer/CreateClassDb.js"));
require(path.join(lib.getRootDir(), lib.getSourcePath(), "qxl/apiviewer/RequestUtil.js"));
let target = maker.getTarget();
let outputDir = target.getOutputDir();
outputDir = path.join(outputDir, "resource", qxl.apiviewer.ClassLoader.RESOURCEPATH);
let environment = maker.getEnvironment();
let excludeFromAPIViewer = environment["qxl.apiviewer.exclude"];
let includeToAPIViewer = environment["qxl.apiviewer.include"];
let verbose = command.argv.verbose;
let builder = new qxl.apiviewer.CreateClassDb;
await builder.buildAPIData({
outputDir,
verbose,
includeToAPIViewer,
excludeFromAPIViewer
});
}, this);
}
return this.base(arguments);
}
}
});
module.exports = {
LibraryApi: qxl.apiviewer.compile.LibraryApi,
CompilerApi: qxl.apiviewer.compile.CompilerApi
};