@spscommerce/e2e-core 2.2.16 → 2.3.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/README.md CHANGED
@@ -77,9 +77,7 @@ If CI is set to true, the forbidOnly and maxFailures options are applied.
77
77
  - maxFailures: Stop test suite execution after reaching 5 failed tests and skip any tests that were not executed yet.
78
78
 
79
79
  ### Authentication
80
- Authentication flow was implemented in the e2e-core library. When tests are laucnhed for the first time, it takes some time for the authentication state to be invoked. If ENV variable is not set, the storageState is created for the test environment, otherwise set URL to 'prod'. After auth state is invoked, it appears in the results-e2e/auth folder. All the next test runs will use an already created storageState.json file.
81
- > Attention:
82
- > While local debugging, the storageState might get expired. User will be redirected to the login page. If it happens, please delete an auth folder in order to invoke an auth state again.
80
+ Authentication flow was implemented in the e2e-core library. When tests are launnhed for the first time, it takes some time for the authentication state to be invoked. If ENV variable is not set, the storageState is created for the test environment, otherwise set URL to 'prod'. After auth state is invoked, it appears in the results-e2e/auth folder. All the next test runs will use an already created storageState.json file.
83
81
 
84
82
  ### Global setup
85
83
  To set something up once before running all tests, create a JS file and link it via SETUP_PATH variable in the `package.json`. Global setup file must export a single function that runs once before all the tests.
@@ -30,7 +30,14 @@ const fs_1 = __importDefault(require("fs"));
30
30
  const path_1 = __importDefault(require("path"));
31
31
  const test_1 = require("@playwright/test");
32
32
  const domain = 'commerce.spscommerce.com';
33
- const baseUrl = process.env.ENV && process.env.ENV.includes('prod') ? 'https://' + domain : 'https://test.' + domain;
33
+ let baseUrl = 'https://test.' + domain;
34
+ let storageFile = path_1.default.join(process.cwd(), `results-e2e/auth/storageStateTest.json`);
35
+ let traceFile = path_1.default.join(process.cwd(), 'results-e2e/auth/globalSetupTest.zip');
36
+ if (process.env.ENV && process.env.ENV.includes('prod')) {
37
+ baseUrl = 'https://' + domain;
38
+ storageFile = path_1.default.join(process.cwd(), `results-e2e/auth/storageStateProd.json`);
39
+ traceFile = path_1.default.join(process.cwd(), 'results-e2e/auth/globalSetupProd.zip');
40
+ }
34
41
  async function globalSetup() {
35
42
  // Remove custom sub-folders for test artifacts
36
43
  const resultsFolder = path_1.default.join(process.cwd(), 'results-e2e/');
@@ -41,10 +48,11 @@ async function globalSetup() {
41
48
  }
42
49
  }
43
50
  }
44
- // Launch browser and log in if storageState.json does not exist
45
- const storageFile = path_1.default.join(process.cwd(), 'results-e2e/auth/storageState.json');
46
- const traceFile = path_1.default.join(process.cwd(), 'results-e2e/auth/globalSetup.zip');
47
- if (!fs_1.default.existsSync(storageFile)) {
51
+ // Launch browser and log in if storageState.json does not exist OR auth expires soon
52
+ const currentTS = new Date().getTime();
53
+ if (!fs_1.default.existsSync(storageFile) ||
54
+ (fs_1.default.existsSync(storageFile) &&
55
+ ((JSON.parse(fs_1.default.readFileSync(storageFile, 'utf8')).origins[0].localStorage.find(o => o.name === 'expires_at').value - currentTS) / 60000) < 30)) {
48
56
  const browser = await test_1.chromium.launch({ headless: false }); // { headless: false }
49
57
  const context = await browser.newContext();
50
58
  await context.tracing.start({ screenshots: true, snapshots: true });
@@ -1 +1 @@
1
- {"version":3,"file":"globalSetup.js","sourceRoot":"","sources":["../src/globalSetup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,2CAA4C;AAE5C,MAAM,MAAM,GAAG,0BAA0B,CAAC;AAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,eAAe,GAAG,MAAM,CAAC;AAEtG,KAAK,UAAU,WAAW;IACrC,+CAA+C;IAC/C,MAAM,aAAa,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;IAC/D,IAAI,YAAE,CAAC,U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,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;aAC7C;YACD,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YACnC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;SAC5D;QAAC,OAAO,CAAC,EAAE;YACR,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACf,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;YAChD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;SACxE;QACD,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;KACzB;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE;QACxB,IAAI,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YACvC,wDAAa,OAAO,CAAC,GAAG,CAAC,UAAU,GAAC,CAAC;SACxC;aAAM;YACH,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,aAAa,CAAC,CAAC;SAC3D;KACJ;IACD,OAAO;AACX,CAAC;AA9CD,8BA8CC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spscommerce/e2e-core",
3
- "version": "2.2.16",
3
+ "version": "2.3.0",
4
4
  "description": "An automation test framework which is based on Playwright.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -55,6 +55,10 @@ switch (process.env.BROWSER) {
55
55
  break;
56
56
  }
57
57
 
58
+ const storageStatePath = process.env.ENV && process.env.ENV.includes('prod')
59
+ ? path.join(process.cwd(), 'results-e2e/auth/storageStateProd.json')
60
+ : path.join(process.cwd(), 'results-e2e/auth/storageStateTest.json');
61
+
58
62
  /**
59
63
  * See https://playwright.dev/docs/test-configuration.
60
64
  */
@@ -89,7 +93,7 @@ const config = {
89
93
  globalTeardown: require.resolve('./lib/globalTeardown'),
90
94
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
91
95
  use: {
92
- storageState: path.join(process.cwd(), 'results-e2e/auth/storageState.json'),
96
+ storageState: storageStatePath,//path.join(process.cwd(), 'results-e2e/auth/storageState.json'),
93
97
  /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
94
98
  actionTimeout: +process.env.ACTION_TIMEOUT || 30000,
95
99
  /* Collect screenshot after each test failure. See https://playwright.dev/docs/test-configuration#automatic-screenshots */
@@ -3,7 +3,15 @@ import path from 'path';
3
3
  import { chromium } from '@playwright/test';
4
4
 
5
5
  const domain = 'commerce.spscommerce.com';
6
- const baseUrl = process.env.ENV && process.env.ENV.includes('prod') ? 'https://' + domain : 'https://test.' + domain;
6
+ let baseUrl = 'https://test.' + domain;
7
+ let storageFile = path.join(process.cwd(), `results-e2e/auth/storageStateTest.json`);
8
+ let traceFile = path.join(process.cwd(), 'results-e2e/auth/globalSetupTest.zip');
9
+
10
+ if (process.env.ENV && process.env.ENV.includes('prod')) {
11
+ baseUrl = 'https://' + domain;
12
+ storageFile = path.join(process.cwd(), `results-e2e/auth/storageStateProd.json`);
13
+ traceFile = path.join(process.cwd(), 'results-e2e/auth/globalSetupProd.zip');
14
+ }
7
15
 
8
16
  export default async function globalSetup(): Promise<void> {
9
17
  // Remove custom sub-folders for test artifacts
@@ -13,10 +21,12 @@ export default async function globalSetup(): Promise<void> {
13
21
  if (!subFolder.includes('auth')) { fs.rmSync(resultsFolder + subFolder, { recursive: true, force: true }); }
14
22
  }
15
23
  }
16
- // Launch browser and log in if storageState.json does not exist
17
- const storageFile = path.join(process.cwd(), 'results-e2e/auth/storageState.json');
18
- const traceFile = path.join(process.cwd(), 'results-e2e/auth/globalSetup.zip');
19
- if (!fs.existsSync(storageFile)) {
24
+ // Launch browser and log in if storageState.json does not exist OR auth expires soon
25
+ const currentTS = new Date().getTime();
26
+ if (!fs.existsSync(storageFile) ||
27
+ (fs.existsSync(storageFile) &&
28
+ ((JSON.parse(fs.readFileSync(storageFile, 'utf8')).origins[0].localStorage.find(o => o.name === 'expires_at').value - currentTS) / 60000) < 30)
29
+ ) {
20
30
  const browser = await chromium.launch({ headless: false }); // { headless: false }
21
31
  const context = await browser.newContext();
22
32
  await context.tracing.start({ screenshots: true, snapshots: true });