regressify 1.8.3 → 1.8.5

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 cookies = [];
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,34 @@ 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
- cookies = JSON.parse(content);
15
+ cookiesFromFile = JSON.parse(content);
16
16
  } else if (cookiePath.endsWith('.yaml') || cookiePath.endsWith('.yml')) {
17
- cookies = YAML.load(content);
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, domain };
29
+
30
+ if (!cookie.expirationDate) {
31
+ cookie.expirationDate = Date.now() / 1000 + 31536000; // 1 year from now
32
+ }
33
+
34
+ cookies.push(cookie);
35
+ });
36
+ });
37
+
38
+ if (process.env.DEBUG_COOKIES === 'true') {
39
+ console.log('Restoring cookies from:', cookiePath);
40
+ console.log(JSON.stringify(cookies, null, 2));
41
+ }
42
+
21
43
  // Add cookies to browser
22
44
  await browserContext.addCookies(cookies);
23
45
 
@@ -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 cookies = [];
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
- cookies = JSON.parse(content);
12
+ cookiesFromFile = JSON.parse(content);
13
13
  } else if (cookiePath.endsWith('.yaml') || cookiePath.endsWith('.yml')) {
14
- cookies = YAML.load(content);
14
+ cookiesFromFile = YAML.load(content);
15
15
  }
16
16
  }
17
17
 
18
- const parsedCookies = [];
18
+ const cookies = [];
19
19
 
20
20
  // MUNGE COOKIE DOMAIN
21
- [].forEach.call(cookies, (c) => {
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
- parsedCookies.push(cookie);
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(parsedCookies, null, 2));
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
- parsedCookies.map(async (cookie) => {
51
+ cookies.map(async (cookie) => {
52
52
  await page.setCookie(cookie);
53
53
  })
54
54
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "regressify",
3
- "version": "1.8.3",
3
+ "version": "1.8.5",
4
4
  "description": "Visual regression tests support",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",