@eyeo/get-browser-binary 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +1 -3
- package/.mocharc.json +1 -1
- package/README.md +2 -2
- package/RELEASE_NOTES.md +14 -0
- package/package.json +1 -1
- package/src/browsers.js +46 -35
- package/src/utils.js +22 -10
- package/test/browsers.js +48 -5
- package/test/utils.js +23 -7
package/.gitlab-ci.yml
CHANGED
|
@@ -32,12 +32,10 @@ test:browsers:linux:
|
|
|
32
32
|
image: docker:20.10.16
|
|
33
33
|
services:
|
|
34
34
|
- docker:20.10.16-dind
|
|
35
|
-
variables:
|
|
36
|
-
DOCKER_DRIVER: overlay2
|
|
37
35
|
before_script:
|
|
38
36
|
- docker build -f test/docker/Dockerfile -t browsers .
|
|
39
37
|
script:
|
|
40
|
-
- docker run --shm-size=
|
|
38
|
+
- docker run --shm-size=512m -t browsers
|
|
41
39
|
|
|
42
40
|
test:browsers:windows:
|
|
43
41
|
stage: test
|
package/.mocharc.json
CHANGED
package/README.md
CHANGED
|
@@ -88,14 +88,14 @@ Useful to reproduce the CI environment of the `test:browsers:linux` job:
|
|
|
88
88
|
|
|
89
89
|
```shell
|
|
90
90
|
docker build -f test/docker/Dockerfile -t browsers .
|
|
91
|
-
docker run --shm-size=
|
|
91
|
+
docker run --shm-size=512m -it browsers
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
The `grep` and `timeout` options can also be used on Docker via the `TEST_ARGS`
|
|
95
95
|
parameter:
|
|
96
96
|
|
|
97
97
|
```shell
|
|
98
|
-
docker run --shm-size=
|
|
98
|
+
docker run --shm-size=512m -e TEST_ARGS="--grep chromium.*latest --timeout 100000" -it browsers
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
By default, tests delete the `./browser-snapshots` before each `Browser` suite
|
package/RELEASE_NOTES.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# 0.9.0
|
|
2
|
+
|
|
3
|
+
- Fixed a Chromium install issue by increasing the value of
|
|
4
|
+
`MAX_VERSION_DECREMENTS` (!52)
|
|
5
|
+
- `installBrowser()`, `getDriver()` and `download()` have a new optional timeout
|
|
6
|
+
parameter on file downloads (!51)
|
|
7
|
+
|
|
8
|
+
### Testing
|
|
9
|
+
|
|
10
|
+
- Added a test checking that downloaded browser-snapshot files are actually
|
|
11
|
+
cached (#35)
|
|
12
|
+
- Tests running the minimum firefox version showed occasional failures. That was
|
|
13
|
+
fixed by increasing the shared memory size of the docker image (!50)
|
|
14
|
+
|
|
1
15
|
# 0.8.0
|
|
2
16
|
|
|
3
17
|
- Move `takeFullPageScreenshot` to the utils module (#38)
|
package/package.json
CHANGED
package/src/browsers.js
CHANGED
|
@@ -82,11 +82,14 @@ class Browser {
|
|
|
82
82
|
* subclasses.
|
|
83
83
|
* @param {string} version - Either full version number or channel/release.
|
|
84
84
|
* Please find examples on the subclasses.
|
|
85
|
+
* @param {number?} downloadTimeout - Allowed time in ms for the download of
|
|
86
|
+
* install files to complete. When set to 0 there is no time limit. Defaults
|
|
87
|
+
* to 0.
|
|
85
88
|
* @return {BrowserBinary}
|
|
86
89
|
* @throws {Error} Unsupported browser version, Unsupported platform, Browser
|
|
87
90
|
* download failed.
|
|
88
91
|
*/
|
|
89
|
-
static async installBrowser(version) {
|
|
92
|
+
static async installBrowser(version, downloadTimeout = 0) {
|
|
90
93
|
// to be implemented by the subclass
|
|
91
94
|
}
|
|
92
95
|
|
|
@@ -134,11 +137,14 @@ class Browser {
|
|
|
134
137
|
* @param {string} version - Either full version number or channel/release.
|
|
135
138
|
* Please find examples on the subclasses.
|
|
136
139
|
* @param {driverOptions?} options - Options to start the browser with.
|
|
140
|
+
* @param {number?} downloadTimeout - Allowed time in ms for the download of
|
|
141
|
+
* browser install files to complete. When set to 0 there is no time limit.
|
|
142
|
+
* Defaults to 0.
|
|
137
143
|
* @return {webdriver}
|
|
138
144
|
* @throws {Error} Unsupported browser version, Unsupported platform, Browser
|
|
139
145
|
* download failed, Driver download failed, Unable to start driver.
|
|
140
146
|
*/
|
|
141
|
-
static async getDriver(version, options = {}) {
|
|
147
|
+
static async getDriver(version, options = {}, downloadTimeout = 0) {
|
|
142
148
|
// to be implemented by the subclass
|
|
143
149
|
}
|
|
144
150
|
|
|
@@ -208,13 +214,16 @@ class Chromium extends Browser {
|
|
|
208
214
|
* {@link snapshotsBaseDir} folder, ready to go.
|
|
209
215
|
* @param {string} version - Either "latest", "beta", "dev" or a full version
|
|
210
216
|
* number (i.e. "77.0.3865.0"). Defaults to "latest".
|
|
217
|
+
* @param {number?} downloadTimeout - Allowed time in ms for the download of
|
|
218
|
+
* install files to complete. When set to 0 there is no time limit. Defaults
|
|
219
|
+
* to 0.
|
|
211
220
|
* @return {BrowserBinary}
|
|
212
221
|
* @throws {Error} Unsupported browser version, Unsupported platform, Browser
|
|
213
222
|
* download failed.
|
|
214
223
|
*/
|
|
215
|
-
static async installBrowser(version = "latest") {
|
|
224
|
+
static async installBrowser(version = "latest", downloadTimeout = 0) {
|
|
216
225
|
const MIN_VERSION = 75;
|
|
217
|
-
const MAX_VERSION_DECREMENTS =
|
|
226
|
+
const MAX_VERSION_DECREMENTS = 200;
|
|
218
227
|
|
|
219
228
|
checkVersion(version, MIN_VERSION, Chromium.#CHANNELS);
|
|
220
229
|
let versionNumber = await Chromium.#getVersionForChannel(version);
|
|
@@ -248,23 +257,27 @@ class Chromium extends Browser {
|
|
|
248
257
|
await fs.promises.mkdir(path.dirname(browserDir), {recursive: true});
|
|
249
258
|
|
|
250
259
|
archive = path.join(snapshotsDir, "cache", `${base}-${fileName}`);
|
|
260
|
+
let url = `https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/${platformDir}%2F${base}%2F${fileName}?alt=media`;
|
|
251
261
|
try {
|
|
252
262
|
try {
|
|
253
263
|
await fs.promises.access(archive);
|
|
254
264
|
}
|
|
255
265
|
catch (e) {
|
|
256
|
-
await download(
|
|
257
|
-
`https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/${platformDir}%2F${base}%2F${fileName}?alt=media`,
|
|
258
|
-
archive);
|
|
266
|
+
await download(url, archive, downloadTimeout);
|
|
259
267
|
}
|
|
260
268
|
break;
|
|
261
269
|
}
|
|
262
|
-
catch (
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
270
|
+
catch (err) {
|
|
271
|
+
if (err.name == "HTTPError") {
|
|
272
|
+
// Chromium advises decrementing the branch_base_position when no
|
|
273
|
+
// matching build was found. See https://www.chromium.org/getting-involved/download-chromium
|
|
274
|
+
base--;
|
|
275
|
+
if (base <= startBase - MAX_VERSION_DECREMENTS)
|
|
276
|
+
throw new Error(`${BROWSER_DOWNLOAD_ERROR}: Chromium base ${startBase}`);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
throw new Error(`${BROWSER_DOWNLOAD_ERROR}: ${url}\n${err}`);
|
|
280
|
+
}
|
|
268
281
|
}
|
|
269
282
|
}
|
|
270
283
|
await extractZip(archive, {dir: browserDir});
|
|
@@ -302,10 +315,7 @@ class Chromium extends Browser {
|
|
|
302
315
|
|
|
303
316
|
await killDriverProcess("chromedriver");
|
|
304
317
|
let driverPath = path.join(cacheDir, zip.split(".")[0], driverBinary);
|
|
305
|
-
|
|
306
|
-
await fs.promises.rm(driverPath, {recursive: true});
|
|
307
|
-
}
|
|
308
|
-
catch (e) {} // file does not exist
|
|
318
|
+
await fs.promises.rm(driverPath, {force: true});
|
|
309
319
|
await extractZip(archive, {dir: cacheDir});
|
|
310
320
|
|
|
311
321
|
return driverPath;
|
|
@@ -315,8 +325,9 @@ class Chromium extends Browser {
|
|
|
315
325
|
static async getDriver(version = "latest", {
|
|
316
326
|
headless = true, extensionPaths = [], incognito = false, insecure = false,
|
|
317
327
|
extraArgs = []
|
|
318
|
-
} = {}) {
|
|
319
|
-
let {binary, versionNumber, base} =
|
|
328
|
+
} = {}, downloadTimeout = 0) {
|
|
329
|
+
let {binary, versionNumber, base} =
|
|
330
|
+
await Chromium.installBrowser(version, downloadTimeout);
|
|
320
331
|
let driverPath = await Chromium.#installDriver(base, versionNumber);
|
|
321
332
|
let serviceBuilder = new chrome.ServiceBuilder(driverPath);
|
|
322
333
|
let options = new chrome.Options().addArguments("no-sandbox", ...extraArgs);
|
|
@@ -414,11 +425,14 @@ class Firefox extends Browser {
|
|
|
414
425
|
* {@link snapshotsBaseDir} folder, ready to go.
|
|
415
426
|
* @param {string} version - Either "latest", "beta" or a full version
|
|
416
427
|
* number (i.e. "68.0"). Defaults to "latest".
|
|
428
|
+
* @param {number?} downloadTimeout - Allowed time in ms for the download of
|
|
429
|
+
* install files to complete. When set to 0 there is no time limit. Defaults
|
|
430
|
+
* to 0.
|
|
417
431
|
* @return {BrowserBinary}
|
|
418
432
|
* @throws {Error} Unsupported browser version, Unsupported platform, Browser
|
|
419
433
|
* download failed.
|
|
420
434
|
*/
|
|
421
|
-
static async installBrowser(version = "latest") {
|
|
435
|
+
static async installBrowser(version = "latest", downloadTimeout = 0) {
|
|
422
436
|
const MIN_VERSION = 60;
|
|
423
437
|
|
|
424
438
|
checkVersion(version, MIN_VERSION, Firefox.#CHANNELS);
|
|
@@ -450,7 +464,7 @@ class Firefox extends Browser {
|
|
|
450
464
|
catch (e) {
|
|
451
465
|
let url = `https://archive.mozilla.org/pub/firefox/releases/${versionNumber}/${buildPlatform}/en-US/${fileName}`;
|
|
452
466
|
try {
|
|
453
|
-
await download(url, archive);
|
|
467
|
+
await download(url, archive, downloadTimeout);
|
|
454
468
|
}
|
|
455
469
|
catch (err) {
|
|
456
470
|
throw new Error(`${BROWSER_DOWNLOAD_ERROR}: ${url}\n${err}`);
|
|
@@ -465,8 +479,8 @@ class Firefox extends Browser {
|
|
|
465
479
|
static async getDriver(version = "latest", {
|
|
466
480
|
headless = true, extensionPaths = [], incognito = false, insecure = false,
|
|
467
481
|
extraArgs = []
|
|
468
|
-
} = {}) {
|
|
469
|
-
let {binary} = await Firefox.installBrowser(version);
|
|
482
|
+
} = {}, downloadTimeout = 0) {
|
|
483
|
+
let {binary} = await Firefox.installBrowser(version, downloadTimeout);
|
|
470
484
|
|
|
471
485
|
let options = new firefox.Options();
|
|
472
486
|
if (headless)
|
|
@@ -601,11 +615,14 @@ class Edge extends Browser {
|
|
|
601
615
|
* app (not as a system app). Installing Edge on Windows is not supported.
|
|
602
616
|
* @param {string} version - Either "latest", "beta", "dev" or a full version
|
|
603
617
|
* number (i.e. "95.0.1020.40"). Defaults to "latest".
|
|
618
|
+
* @param {number?} downloadTimeout - Allowed time in ms for the download of
|
|
619
|
+
* install files to complete. When set to 0 there is no time limit. Defaults
|
|
620
|
+
* to 0.
|
|
604
621
|
* @return {BrowserBinary}
|
|
605
622
|
* @throws {Error} Unsupported browser version, Unsupported platform, Browser
|
|
606
623
|
* download failed.
|
|
607
624
|
*/
|
|
608
|
-
static async installBrowser(version = "latest") {
|
|
625
|
+
static async installBrowser(version = "latest", downloadTimeout = 0) {
|
|
609
626
|
if (platform == "win32")
|
|
610
627
|
// Edge is mandatory on Windows, can't be uninstalled or downgraded
|
|
611
628
|
// https://support.microsoft.com/en-us/microsoft-edge/why-can-t-i-uninstall-microsoft-edge-ee150b3b-7d7a-9984-6d83-eb36683d526d
|
|
@@ -642,7 +659,7 @@ class Edge extends Browser {
|
|
|
642
659
|
catch (e) {}
|
|
643
660
|
|
|
644
661
|
try {
|
|
645
|
-
await download(url, archive);
|
|
662
|
+
await download(url, archive, downloadTimeout);
|
|
646
663
|
}
|
|
647
664
|
catch (err) {
|
|
648
665
|
throw new Error(`${BROWSER_DOWNLOAD_ERROR}: ${url}\n${err}`);
|
|
@@ -653,10 +670,7 @@ class Edge extends Browser {
|
|
|
653
670
|
}
|
|
654
671
|
else if (platform == "darwin") {
|
|
655
672
|
let appName = Edge.#getDarwinAppName(channel);
|
|
656
|
-
|
|
657
|
-
await fs.promises.rm(`${process.env.HOME}/Applications/${appName}.app`, {recursive: true});
|
|
658
|
-
}
|
|
659
|
-
catch (e) {}
|
|
673
|
+
await fs.promises.rm(`${process.env.HOME}/Applications/${appName}.app`, {force: true, recursive: true});
|
|
660
674
|
await promisify(exec)(`installer -pkg ${archive} -target CurrentUserHomeDirectory`);
|
|
661
675
|
}
|
|
662
676
|
|
|
@@ -673,10 +687,7 @@ class Edge extends Browser {
|
|
|
673
687
|
static async #installDriver() {
|
|
674
688
|
async function extractEdgeZip(archive, cacheDir, driverPath) {
|
|
675
689
|
await killDriverProcess("msedgedriver");
|
|
676
|
-
|
|
677
|
-
await fs.promises.rm(driverPath, {recursive: true});
|
|
678
|
-
}
|
|
679
|
-
catch (e) {} // file does not exist
|
|
690
|
+
await fs.promises.rm(driverPath, {force: true});
|
|
680
691
|
await extractZip(archive, {dir: cacheDir});
|
|
681
692
|
}
|
|
682
693
|
|
|
@@ -727,9 +738,9 @@ class Edge extends Browser {
|
|
|
727
738
|
static async getDriver(version = "latest", {
|
|
728
739
|
headless = true, extensionPaths = [], incognito = false, insecure = false,
|
|
729
740
|
extraArgs = []
|
|
730
|
-
} = {}) {
|
|
741
|
+
} = {}, downloadTimeout = 0) {
|
|
731
742
|
if (platform == "linux" || platform == "darwin")
|
|
732
|
-
await Edge.installBrowser(version);
|
|
743
|
+
await Edge.installBrowser(version, downloadTimeout);
|
|
733
744
|
|
|
734
745
|
let driverPath = await Edge.#installDriver();
|
|
735
746
|
let serviceBuilder = new edge.ServiceBuilder(driverPath);
|
package/src/utils.js
CHANGED
|
@@ -25,31 +25,43 @@ import got from "got";
|
|
|
25
25
|
import dmg from "dmg";
|
|
26
26
|
import Jimp from "jimp";
|
|
27
27
|
|
|
28
|
+
|
|
28
29
|
/**
|
|
29
30
|
* Downloads url resources.
|
|
30
31
|
* @param {string} url - The url of the resource to be downloaded.
|
|
31
32
|
* @param {string} destFile - The destination file path.
|
|
32
|
-
* @
|
|
33
|
+
* @param {number?} timeout - Allowed time in ms for the download to complete.
|
|
34
|
+
* When set to 0 there is no time limit. Defaults to 0.
|
|
35
|
+
* @throws {TypeError} Invalid URL, Download timeout.
|
|
33
36
|
*/
|
|
34
|
-
export async function download(url, destFile) {
|
|
37
|
+
export async function download(url, destFile, timeout = 0) {
|
|
35
38
|
let cacheDir = path.dirname(destFile);
|
|
36
|
-
|
|
37
39
|
await fs.promises.mkdir(cacheDir, {recursive: true});
|
|
38
40
|
|
|
39
41
|
let tempDest = `${destFile}-${process.pid}`;
|
|
40
42
|
let writable = fs.createWriteStream(tempDest);
|
|
41
|
-
|
|
43
|
+
let timeoutID;
|
|
42
44
|
try {
|
|
43
|
-
|
|
45
|
+
let downloading = promisify(pipeline)(got.stream(url), writable);
|
|
46
|
+
if (timeout == 0) {
|
|
47
|
+
await downloading;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
let timeoutPromise = new Promise((resolve, reject) => {
|
|
51
|
+
timeoutID = setTimeout(
|
|
52
|
+
() => reject(`Download timeout after ${timeout}ms`), timeout);
|
|
53
|
+
});
|
|
54
|
+
await Promise.race([downloading, timeoutPromise]);
|
|
55
|
+
}
|
|
44
56
|
}
|
|
45
57
|
catch (error) {
|
|
46
|
-
|
|
47
|
-
await fs.promises.rm(tempDest, {recursive: true});
|
|
48
|
-
}
|
|
49
|
-
catch (e) {}
|
|
50
|
-
|
|
58
|
+
await fs.promises.rm(tempDest, {force: true});
|
|
51
59
|
throw error;
|
|
52
60
|
}
|
|
61
|
+
finally {
|
|
62
|
+
if (timeoutID)
|
|
63
|
+
clearTimeout(timeoutID);
|
|
64
|
+
}
|
|
53
65
|
|
|
54
66
|
await fs.promises.rename(tempDest, destFile);
|
|
55
67
|
}
|
package/test/browsers.js
CHANGED
|
@@ -104,21 +104,47 @@ function getExtension(browser, version) {
|
|
|
104
104
|
return {extensionPaths, manifest};
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
async function getCachedTimes(browser) {
|
|
108
|
+
let cacheDir = path.join(snapshotsBaseDir, browser, "cache");
|
|
109
|
+
let cacheFiles = await fs.promises.readdir(cacheDir);
|
|
110
|
+
|
|
111
|
+
let browserCacheTime = null;
|
|
112
|
+
// Edge gets installed at OS level, that's why it's not tested here
|
|
113
|
+
if (browser != "edge") {
|
|
114
|
+
let installTypes = [".zip", ".dmg", ".bz2"];
|
|
115
|
+
let browserZip =
|
|
116
|
+
cacheFiles.find(elem => installTypes.some(type => elem.includes(type)));
|
|
117
|
+
let browserStat = await fs.promises.stat(path.join(cacheDir, browserZip));
|
|
118
|
+
browserCacheTime = browserStat.ctimeMs;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let driverCacheTime = null;
|
|
122
|
+
// Firefox install file includes the driver, that's why it's not tested here
|
|
123
|
+
if (browser != "firefox") {
|
|
124
|
+
let driverDir = cacheFiles.find(elem => !elem.endsWith(".zip"));
|
|
125
|
+
let driverFiles = await fs.promises.readdir(path.join(cacheDir, driverDir));
|
|
126
|
+
let driverZip = driverFiles.find(elem => elem.endsWith(".zip"));
|
|
127
|
+
let driverStat =
|
|
128
|
+
await fs.promises.stat(path.join(cacheDir, driverDir, driverZip));
|
|
129
|
+
driverCacheTime = driverStat.ctimeMs;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {browserCTime: browserCacheTime, driverCTime: driverCacheTime};
|
|
133
|
+
}
|
|
134
|
+
|
|
107
135
|
for (let browser of Object.keys(BROWSERS)) {
|
|
108
136
|
describe(`Browser: ${browser}`, () => {
|
|
109
137
|
before(async() => {
|
|
110
138
|
if (process.env.TEST_KEEP_SNAPSHOTS == "true")
|
|
111
139
|
return;
|
|
112
140
|
|
|
113
|
-
|
|
114
|
-
await fs.promises.rm(snapshotsBaseDir, {recursive: true});
|
|
115
|
-
}
|
|
116
|
-
catch (e) {}
|
|
141
|
+
await fs.promises.rm(snapshotsBaseDir, {force: true, recursive: true});
|
|
117
142
|
});
|
|
118
143
|
|
|
119
144
|
for (let version of VERSIONS[browser]) {
|
|
120
145
|
describe(`Version: ${version}`, () => {
|
|
121
146
|
let driver = null;
|
|
147
|
+
let emptyCacheTimes = null;
|
|
122
148
|
|
|
123
149
|
async function quitDriver() {
|
|
124
150
|
if (!driver)
|
|
@@ -140,7 +166,7 @@ for (let browser of Object.keys(BROWSERS)) {
|
|
|
140
166
|
this.skip();
|
|
141
167
|
|
|
142
168
|
let {binary, versionNumber} =
|
|
143
|
-
await BROWSERS[browser].installBrowser(version);
|
|
169
|
+
await BROWSERS[browser].installBrowser(version, 60000);
|
|
144
170
|
let browserName = browser == "edge" ? /(edge|Edge)/ : browser;
|
|
145
171
|
expect(binary).toEqual(expect.stringMatching(browserName));
|
|
146
172
|
|
|
@@ -165,6 +191,23 @@ for (let browser of Object.keys(BROWSERS)) {
|
|
|
165
191
|
|
|
166
192
|
expect((await driver.getCapabilities()).getBrowserName())
|
|
167
193
|
.toEqual(expect.stringMatching(names[browser]));
|
|
194
|
+
|
|
195
|
+
// When running all tests, this saves time on the cache test
|
|
196
|
+
emptyCacheTimes = await getCachedTimes(browser);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("uses cached install files", async() => {
|
|
200
|
+
if (emptyCacheTimes == null) { // Single test case run
|
|
201
|
+
driver = await BROWSERS[browser].getDriver(version);
|
|
202
|
+
emptyCacheTimes = await getCachedTimes(browser);
|
|
203
|
+
await quitDriver();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// assigning `driver` to allow the afterEach hook quit the driver
|
|
207
|
+
driver = await BROWSERS[browser].getDriver(version);
|
|
208
|
+
let existingCacheTimes = await getCachedTimes(browser);
|
|
209
|
+
|
|
210
|
+
expect(existingCacheTimes).toEqual(emptyCacheTimes);
|
|
168
211
|
});
|
|
169
212
|
|
|
170
213
|
it("supports extra args", async() => {
|
package/test/utils.js
CHANGED
|
@@ -25,18 +25,34 @@ describe("Utils", () => {
|
|
|
25
25
|
it("defines a browser snapshots folder", () => expect(snapshotsBaseDir)
|
|
26
26
|
.toBe(path.join(process.cwd(), "browser-snapshots")));
|
|
27
27
|
|
|
28
|
+
let resourceUrl = "https://gitlab.com/eyeo/developer-experience/get-browser-binary/-/raw/main/package.json";
|
|
28
29
|
let destFile = path.join(snapshotsBaseDir, "download-test.txt");
|
|
30
|
+
let expectedFileContents = "\"name\": \"@eyeo/get-browser-binary\"";
|
|
29
31
|
|
|
30
32
|
it("downloads resources", async() => {
|
|
31
|
-
|
|
32
|
-
await download(
|
|
33
|
+
await fs.promises.rm(destFile, {force: true});
|
|
34
|
+
await download(resourceUrl, destFile);
|
|
33
35
|
let contents = await fs.promises.readFile(destFile, {encoding: "utf8"});
|
|
34
|
-
expect(contents).toEqual(
|
|
35
|
-
expect.stringContaining("\"name\": \"@eyeo/get-browser-binary\""));
|
|
36
|
+
expect(contents).toEqual(expect.stringContaining(expectedFileContents));
|
|
36
37
|
});
|
|
37
38
|
|
|
38
|
-
it("
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
it("downloads resources on long timeout", async() => {
|
|
40
|
+
await fs.promises.rm(destFile, {force: true});
|
|
41
|
+
await download(resourceUrl, destFile, 10000);
|
|
42
|
+
let contents = await fs.promises.readFile(destFile, {encoding: "utf8"});
|
|
43
|
+
expect(contents).toEqual(expect.stringContaining(expectedFileContents));
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("does not download on short timeout", async() => {
|
|
47
|
+
try {
|
|
48
|
+
await download(resourceUrl, destFile, 10);
|
|
49
|
+
throw new Error("Download timeout didn't throw");
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
expect(err).toBe("Download timeout after 10ms");
|
|
53
|
+
}
|
|
41
54
|
});
|
|
55
|
+
|
|
56
|
+
it("does not download invalid resources", () =>
|
|
57
|
+
expect(download("invalid", destFile)).rejects.toThrow("Invalid URL"));
|
|
42
58
|
});
|