Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
Sebastian Noack
2018/08/22 18:16:38
Why not calling it test_runner.js and put it under
tlucas
2018/08/22 20:24:01
From what i saw, there's virtually no code from ad
Sebastian Noack
2018/08/22 20:54:35
Fair enough. Still what is the advantage of the di
tlucas
2018/08/23 08:47:27
With the current implementation of the packagers,
Sebastian Noack
2018/08/23 16:38:44
Well changing buildtools to not include test_runne
tlucas
2018/08/24 10:25:08
For the buildtools, same argument as somewhere els
| |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 const FIREFOX_VERSION = "57.0"; | |
21 | |
22 const path = require("path"); | |
23 const webdriver = require("selenium-webdriver"); | |
24 const {By, until} = webdriver; | |
25 const firefox = require("selenium-webdriver/firefox"); | |
26 const {Command} = require("selenium-webdriver/lib/command"); | |
20 const {ensureFirefox} = require("../adblockpluscore/test/runners/" + | 27 const {ensureFirefox} = require("../adblockpluscore/test/runners/" + |
21 "firefox_download"); | 28 "firefox_download"); |
22 const webdriver = require("selenium-webdriver"); | |
23 const By = webdriver.By; | |
Sebastian Noack
2018/08/22 18:16:38
Nit: Use desctrucuring.
tlucas
2018/08/22 20:24:02
I assume you expected something like (with the com
Sebastian Noack
2018/08/22 20:54:35
Better:
const {By, until} = webdriver;
tlucas
2018/08/23 08:47:28
Done.
| |
24 const until = webdriver.until; | |
Sebastian Noack
2018/08/22 18:16:38
Nit: This seems to be unused.
tlucas
2018/08/22 20:24:01
It's used in line 86;
...
driver.wait(unti
Sebastian Noack
2018/08/22 20:54:35
My bad.
| |
25 | 29 |
26 const FIREFOX_VERSION = "57.0"; | 30 function reportElements(test, driver, success) |
27 | 31 { |
28 const Command = require("selenium-webdriver/lib/command").Command; | 32 return driver.findElements( |
29 const path = require("path"); | 33 By.css(`#qunit-tests ${success ? ".pass" : ".fail"} .test-name`) |
30 const firefox = require("selenium-webdriver/firefox"); | 34 ).then(elements => Promise.all(elements.map(elem => |
35 elem.getAttribute("innerHTML").then(data => test.ok(success, data)) | |
36 ))); | |
37 } | |
31 | 38 |
32 exports.runFirefox = function(test) | 39 exports.runFirefox = function(test) |
33 { | 40 { |
34 test.expect(14); | |
Sebastian Noack
2018/08/22 18:16:38
Where is this number coming from?
tlucas
2018/08/22 20:24:01
It's the number of test-groups for qunit, when run
Sebastian Noack
2018/08/22 20:54:35
So that means whenever the number of qunit tests c
tlucas
2018/08/23 08:47:27
The only drawback of not using expect() is, we wou
| |
35 // https://stackoverflow.com/a/45045036 | 41 // https://stackoverflow.com/a/45045036 |
36 function installWebExt(driver, extension) | 42 function installWebExt(driver, extension) |
37 { | 43 { |
38 let cmd = new Command("moz-install-web-ext") | 44 let cmd = new Command("moz-install-web-ext") |
39 .setParameter("path", path.resolve(extension)) | 45 .setParameter("path", path.resolve(extension)) |
40 .setParameter("temporary", true); | 46 .setParameter("temporary", true); |
41 | 47 |
42 driver.getExecutor() | 48 driver.getExecutor() |
43 .defineCommand(cmd.getName(), "POST", | 49 .defineCommand(cmd.getName(), "POST", |
44 "/session/:sessionId/moz/addon/install"); | 50 "/session/:sessionId/moz/addon/install"); |
45 | 51 |
46 return driver.schedule(cmd, "installWebExt(" + extension + ")"); | 52 return driver.schedule(cmd, `installWebExt(${extension})`); |
47 } | 53 } |
48 | |
49 // Spawn the Firefox process in headless mode | |
Sebastian Noack
2018/08/22 18:16:38
Nit: This comment seems redundant to me.
tlucas
2018/08/22 20:24:01
Done.
| |
50 | 54 |
51 ensureFirefox(FIREFOX_VERSION).then(firefoxPath => | 55 ensureFirefox(FIREFOX_VERSION).then(firefoxPath => |
52 { | 56 { |
53 let binary = new firefox.Binary(firefoxPath); | 57 let binary = new firefox.Binary(firefoxPath); |
54 | 58 |
55 binary.addArguments("-headless"); | 59 binary.addArguments("-headless"); |
56 | 60 |
57 let options = new firefox.Options() | 61 let options = new firefox.Options() |
58 .setBinary(binary); | 62 .setBinary(binary); |
59 | 63 |
60 let driver = new webdriver.Builder() | 64 let driver = new webdriver.Builder() |
61 .forBrowser("firefox") | 65 .forBrowser("firefox") |
62 .setFirefoxOptions(options) | 66 .setFirefoxOptions(options) |
63 .build(); | 67 .build(); |
64 | 68 |
65 installWebExt(driver, "./devenv.gecko"); | 69 installWebExt(driver, "./devenv.gecko"); |
66 | 70 |
67 driver.wait(() => | 71 driver.wait(() => |
68 { | |
69 // Wait for the firstrun-page to be loaded | 72 // Wait for the firstrun-page to be loaded |
70 return driver.getAllWindowHandles().then(handles => | 73 driver.getAllWindowHandles().then(handles => |
71 { | 74 { |
72 if (handles.length > 1) | 75 if (handles.length > 1) |
73 { | 76 { |
74 driver.switchTo().window(handles[1]); | 77 driver.switchTo().window(handles[1]); |
75 return true; | 78 return true; |
76 } | 79 } |
77 return false; | 80 return false; |
78 }); | 81 }) |
79 }).then(() => | 82 ).then(() => |
80 { | |
81 // Navigate to the qunit index | 83 // Navigate to the qunit index |
82 driver.executeScript("location.href = \"qunit/index.html\";"); | 84 driver.executeScript("location.href = \"qunit/index.html\";") |
Sebastian Noack
2018/08/22 18:16:38
Wouldn't driver.navigate().to() be more appropriat
tlucas
2018/08/22 20:24:02
driver.navigate().to() expects absolute URLs, so w
Sebastian Noack
2018/08/22 20:54:35
Acknowledged.
| |
83 }).then(() => | 85 ).then(() => |
84 { | |
85 // Wait for qunit-results to be present | 86 // Wait for qunit-results to be present |
86 driver.wait(until.elementLocated(By.id("qunit-testresult"))); | 87 driver.wait(until.elementLocated(By.id("qunit-testresult"))) |
87 }).then(() => | 88 ).then(() => |
88 { | |
89 // Wait for tests to finish | 89 // Wait for tests to finish |
90 driver.wait(() => | 90 driver.wait(() => |
91 { | 91 driver.findElement(By.id("qunit-testresult")) |
92 return driver.findElement(By.id("qunit-testresult")) | 92 .getAttribute("innerHTML").then(data => |
Sebastian Noack
2018/08/22 18:16:38
Nit: return + braces are redundant.
tlucas
2018/08/22 20:24:01
Could you help me out here, what should it look li
Sebastian Noack
2018/08/22 20:54:35
Sorry, I thought for some reason Hubert was the au
tlucas
2018/08/23 08:47:27
Done. (also for the braces / return around "Wait f
| |
93 .getAttribute("innerHTML").then(data => | 93 data.includes("Tests completed"))) |
94 { | 94 ).then(() => Promise.all([ |
95 return data.search("Tests completed") >= 0; | 95 reportElements(test, driver, true), |
96 }); | 96 reportElements(test, driver, false) |
97 }); | 97 ])).then(() => |
98 }).then(() => | |
99 { | |
100 // Find passed tests | |
101 driver.findElements(By.css("#qunit-tests .pass .test-name")) | |
102 .then(elements => | |
103 { | |
104 elements.forEach(elem => | |
Sebastian Noack
2018/08/22 18:16:38
Nit: We prefer for..of loops over forEach().
tlucas
2018/08/22 20:24:01
Done.
| |
105 { | |
106 elem.getAttribute("innerHTML").then(data => | |
107 { | |
108 test.ok(true, data); | |
109 }); | |
110 }); | |
111 }); | |
112 // Find failed tests | |
113 driver.findElements(By.css("#qunit-tests .fail .test-name")) | |
114 .then(elements => | |
115 { | |
116 elements.forEach(elem => | |
Sebastian Noack
2018/08/22 18:16:38
Nit: See above.
tlucas
2018/08/22 20:24:01
Done.
| |
117 { | |
118 elem.getAttribute("innerHTML").then(data => | |
119 { | |
120 test.ok(false, "Undefined error in " + data); | |
121 }); | |
122 }); | |
123 }); | |
124 }).then(() => | |
125 { | 98 { |
126 driver.quit(); | 99 driver.quit(); |
127 test.done(); | 100 test.done(); |
128 }); | 101 }, err => |
102 driver.quit().then(() => | |
103 { | |
104 throw err; | |
105 }) | |
106 ); | |
129 }); | 107 }); |
130 }; | 108 }; |
LEFT | RIGHT |