regressify 1.8.3 → 1.8.4
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.
|
@@ -3,7 +3,7 @@ const YAML = require('js-yaml');
|
|
|
3
3
|
const chalkImport = import('chalk').then((m) => m.default);
|
|
4
4
|
|
|
5
5
|
module.exports = async (browserContext, scenario) => {
|
|
6
|
-
let
|
|
6
|
+
let cookiesFromFile = [];
|
|
7
7
|
const cookiePath = scenario.cookiePath;
|
|
8
8
|
const chalk = await chalkImport;
|
|
9
9
|
const logPrefix = chalk.yellow(`[${scenario.index} of ${scenario.total}] `);
|
|
@@ -12,12 +12,42 @@ module.exports = async (browserContext, scenario) => {
|
|
|
12
12
|
if (!!cookiePath && fs.existsSync(cookiePath)) {
|
|
13
13
|
let content = fs.readFileSync(cookiePath);
|
|
14
14
|
if (cookiePath.endsWith('.json')) {
|
|
15
|
-
|
|
15
|
+
cookiesFromFile = JSON.parse(content);
|
|
16
16
|
} else if (cookiePath.endsWith('.yaml') || cookiePath.endsWith('.yml')) {
|
|
17
|
-
|
|
17
|
+
cookiesFromFile = YAML.load(content);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
const cookies = [];
|
|
22
|
+
|
|
23
|
+
// MUNGE COOKIE DOMAIN
|
|
24
|
+
[].forEach.call(cookiesFromFile, (c) => {
|
|
25
|
+
let domains = typeof c.domain === 'string' ? [c.domain] : c.domain;
|
|
26
|
+
|
|
27
|
+
[].forEach.call(domains, (domain) => {
|
|
28
|
+
const cookie = { ...c };
|
|
29
|
+
if (domain.startsWith('http://') || domain.startsWith('https://')) {
|
|
30
|
+
cookie.url = domain;
|
|
31
|
+
} else {
|
|
32
|
+
cookie.url = 'https://' + domain;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!cookie.expirationDate) {
|
|
36
|
+
cookie.expirationDate = Date.now() / 1000 + 31536000; // 1 year from now
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cookie.domain = undefined;
|
|
40
|
+
delete cookie.domain;
|
|
41
|
+
|
|
42
|
+
cookies.push(cookie);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (process.env.DEBUG_COOKIES === 'true') {
|
|
47
|
+
console.log('Restoring cookies from:', cookiePath);
|
|
48
|
+
console.log(JSON.stringify(cookies, null, 2));
|
|
49
|
+
}
|
|
50
|
+
|
|
21
51
|
// Add cookies to browser
|
|
22
52
|
await browserContext.addCookies(cookies);
|
|
23
53
|
|
|
@@ -2,23 +2,23 @@ const fs = require('fs');
|
|
|
2
2
|
const YAML = require('js-yaml');
|
|
3
3
|
|
|
4
4
|
module.exports = async (page, scenario) => {
|
|
5
|
-
let
|
|
5
|
+
let cookiesFromFile = [];
|
|
6
6
|
const cookiePath = scenario.cookiePath;
|
|
7
7
|
|
|
8
8
|
// READ COOKIES FROM FILE IF EXISTS
|
|
9
9
|
if (!!cookiePath && fs.existsSync(cookiePath)) {
|
|
10
10
|
let content = fs.readFileSync(cookiePath);
|
|
11
11
|
if (cookiePath.endsWith('.json')) {
|
|
12
|
-
|
|
12
|
+
cookiesFromFile = JSON.parse(content);
|
|
13
13
|
} else if (cookiePath.endsWith('.yaml') || cookiePath.endsWith('.yml')) {
|
|
14
|
-
|
|
14
|
+
cookiesFromFile = YAML.load(content);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const cookies = [];
|
|
19
19
|
|
|
20
20
|
// MUNGE COOKIE DOMAIN
|
|
21
|
-
[].forEach.call(
|
|
21
|
+
[].forEach.call(cookiesFromFile, (c) => {
|
|
22
22
|
let domains = typeof c.domain === 'string' ? [c.domain] : c.domain;
|
|
23
23
|
|
|
24
24
|
[].forEach.call(domains, (domain) => {
|
|
@@ -36,19 +36,19 @@ module.exports = async (page, scenario) => {
|
|
|
36
36
|
cookie.domain = undefined;
|
|
37
37
|
delete cookie.domain;
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
cookies.push(cookie);
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
if (process.env.DEBUG_COOKIES === 'true') {
|
|
44
44
|
console.log('Restoring cookies from:', cookiePath);
|
|
45
|
-
console.log(JSON.stringify(
|
|
45
|
+
console.log(JSON.stringify(cookies, null, 2));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// SET COOKIES
|
|
49
49
|
const setCookies = async () => {
|
|
50
50
|
return Promise.all(
|
|
51
|
-
|
|
51
|
+
cookies.map(async (cookie) => {
|
|
52
52
|
await page.setCookie(cookie);
|
|
53
53
|
})
|
|
54
54
|
);
|