@spscommerce/e2e-core 1.0.5 → 1.1.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/.dockerignore CHANGED
@@ -1,7 +1,7 @@
1
1
  # Ignore all files by default
2
2
  *
3
3
  # White list the required files
4
- !env.config.ts
4
+ !helpers/
5
5
  !credentials.sh
6
6
  !jest-environment.config.js
7
7
  !jest-playwright.config.js
package/Dockerfile CHANGED
@@ -3,7 +3,8 @@ FROM mcr.microsoft.com/playwright:bionic
3
3
  # We need to install Edge manually since it does not exist in the official PW image
4
4
  # https://github.com/microsoft/playwright/blob/07fb81a4efdcc4c2169a61a16b513b9d91be6c49/src/server/chromium/findChromiumChannel.ts#L38
5
5
 
6
- RUN apt-get install wget \
6
+ RUN apt-get update \
7
+ && apt-get install --reinstall wget \
7
8
  && wget -q -O - https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
8
9
  && echo "deb https://packages.microsoft.com/repos/edge stable main" >> /etc/apt/sources.list.d/microsoft-edge.list \
9
10
  && apt-get update -qqy \
package/README.md CHANGED
@@ -39,7 +39,7 @@ HEADLESS=false BROWSER=chromium npm run test
39
39
  | ------------------: | -------------------------------------------------- | ------------------------------ | ------------------------------------ |
40
40
  | HEADLESS | launch browser in headless/headful mode | true | true, false |
41
41
  | BROWSER | use + as a separator, e.g edge+firefox | chromium | chromium, firefox, webkit, edge |
42
- | ENV | auth state is invoked for the defined env | test | test, prod |
42
+ | URL | auth state is invoked for the defined env | test | test, prod etc. |
43
43
  | SLOWMO | slow down an execution for debugging | 0 | [number_in_ms] |
44
44
  | TIMEOUT | global timeout for each test | 30000 | [number_in_ms] |
45
45
  | WORKERS | number of workers (test threads) | number of CPUs minus 1 | [number] |
@@ -0,0 +1,75 @@
1
+ import fetch from 'node-fetch';
2
+ import { authEndpoint } from './envSetup';
3
+
4
+ export async function getAuthToken(): Promise<string> {
5
+ if (process.env.USER_EMAIL && process.env.USER_PASSWORD) {
6
+ const requestOptions = {
7
+ method: 'POST',
8
+ body: JSON.stringify({
9
+ username: process.env.USER_EMAIL,
10
+ password: process.env.USER_PASSWORD,
11
+ client_id: "595",
12
+ grant_type: "password"
13
+ }),
14
+ headers: {
15
+ 'Accept': 'application/json',
16
+ 'Content-Type': 'application/json'
17
+ }
18
+ }
19
+ try {
20
+ const fetchResponse = await fetch(authEndpoint + 'identity/token/', requestOptions);
21
+ const data = await fetchResponse.json();
22
+ return data.access_token;
23
+ } catch (e) {
24
+ console.log(e);
25
+ return process.exit(1);
26
+ }
27
+ } else {
28
+ throw new Error(`Set up process environment variables: USER_EMAIL and USER_PASSWORD.`);
29
+ }
30
+ }
31
+
32
+ export async function getUserInfo(): Promise<any> {
33
+ const requestOptions = {
34
+ method: 'GET',
35
+ headers: {
36
+ 'Authorization': `Bearer ${process.env.TOKEN}`,
37
+ 'Accept': 'application/json',
38
+ 'Content-Type': 'application/json'
39
+ }
40
+ }
41
+ try {
42
+ const fetchResponse = await fetch(authEndpoint + `identity/users/me/`, requestOptions);
43
+ const data = await fetchResponse.json();
44
+ return data;
45
+ } catch (e) {
46
+ console.log(e);
47
+ return process.exit(1);
48
+ }
49
+ }
50
+
51
+ export async function changePreferredOrg(orgID: string): Promise<void> {
52
+ const userData = await getUserInfo();
53
+ const requestOptions = {
54
+ method: 'PUT',
55
+ body: JSON.stringify({
56
+ email: userData.email,
57
+ first_name: userData.first_name,
58
+ last_name: userData.last_name,
59
+ preferred_org_id: orgID
60
+ }),
61
+ headers: {
62
+ 'Authorization': `Bearer ${process.env.TOKEN}`,
63
+ 'Accept': 'application/json',
64
+ 'Content-Type': 'application/json'
65
+ }
66
+ }
67
+ try {
68
+ const fetchResponse = await fetch(authEndpoint + `identity/users/${userData.id}/`, requestOptions);
69
+ const data = await fetchResponse.json();
70
+ return data;
71
+ } catch (e) {
72
+ console.log(e);
73
+ return process.exit(1);
74
+ }
75
+ }
@@ -1,7 +1,17 @@
1
- export async function authenticate(token?: string): Promise<void> {
2
- await page.addInitScript((params: { name: string; value: string; }) => {
1
+ import { getAuthToken, changePreferredOrg } from './apiCalls';
2
+ import { primaryOrgID } from './envSetup';
3
+
4
+ export async function authenticate(orgID?: string): Promise<void> {
5
+ if (orgID) {
6
+ await changePreferredOrg(orgID);
7
+ process.env.TOKEN = await getAuthToken();
8
+ } else {
9
+ await changePreferredOrg(primaryOrgID);
10
+ process.env.TOKEN = await getAuthToken();
11
+ }
12
+ await page.addInitScript(params => {
3
13
  window.localStorage.setItem(params.name, params.value);
4
- }, { name: "access_token", value: token || process.env.TOKEN });
14
+ }, { name: "access_token", value: process.env.TOKEN });
5
15
  return;
6
16
  }
7
17
 
@@ -0,0 +1,9 @@
1
+ let authEndpoint = 'https://test.id.spsc.io/';
2
+ let primaryOrgID = '209098808305562446811265341033453015703'; // SPS Commerce org id on test env
3
+
4
+ if (process.env.URL && process.env.URL.toLowerCase().includes('prod')) {
5
+ authEndpoint = 'https://id.spsc.io/';
6
+ primaryOrgID = '157627141979612915626333577105111854232'; // SPS Commerce org id on prod env
7
+ }
8
+
9
+ export { authEndpoint, primaryOrgID };
@@ -18,7 +18,6 @@ class JestEnvironmentFailFast extends ParentEnvironment {
18
18
  await super.teardown();
19
19
  if (this.videos.length !== 0) {
20
20
  const { recordVideo } = pwConfig.contextOptions;
21
- console.log(this.videos)
22
21
  const anyTestFailed = this.videos.find(element => element.success !== true);
23
22
  if (anyTestFailed) {
24
23
  const newVideoName = `${recordVideo.dir}/${anyTestFailed.testSuiteName}.webm`;
@@ -81,7 +80,7 @@ class JestEnvironmentFailFast extends ParentEnvironment {
81
80
 
82
81
  // TEST FINISHES AND FAILS
83
82
  // Skip all further tests in the suite (all tests are related to each other) if
84
- // - any test is failed AND suite name includes 'long_scenario'
83
+ // - any test is failed AND suite name includes 'FailFast'
85
84
  if (this.failedTest && event.name === 'test_start' && event.test.parent.name.includes('FailFast')) {
86
85
  event.test.mode = 'skip';
87
86
  }
@@ -1,3 +1,8 @@
1
+ const customViewport = {
2
+ width: 1920,
3
+ height: 1080,
4
+ }
5
+
1
6
  let runModeBrowser = [];
2
7
 
3
8
  // Run in chromium browser by default (if process.env.BROWSER is not specified)
@@ -19,13 +24,10 @@ if (!process.env.BROWSER) {
19
24
  case 'webkit':
20
25
  runModeBrowser.push('webkit');
21
26
  break;
22
- // Pay attention: browserName is 'chromium' for Edge browser (mentioned in describe)
23
- // https://support.microsoft.com/en-us/microsoft-edge/download-the-new-microsoft-edge-based-on-chromium-0f4a3dd7-55df-60f5-739f-00010dba52cf
24
27
  case 'edge':
25
28
  case 'msedge':
26
- // Channel is 'msedge-dev' since only it is available in linux
27
- // https://github.com/microsoft/playwright/blob/07fb81a4efdcc4c2169a61a16b513b9d91be6c49/src/server/chromium/findChromiumChannel.ts#L38
28
29
  runModeBrowser.push({ displayName: 'edge', name: 'chromium', launchOptions: { channel: 'msedge-dev' } });
30
+ // https://github.com/microsoft/playwright/blob/07fb81a4efdcc4c2169a61a16b513b9d91be6c49/src/server/chromium/findChromiumChannel.ts#L38
29
31
  break;
30
32
  default:
31
33
  runModeBrowser.push('chromium');
@@ -38,20 +40,27 @@ if (!process.env.BROWSER) {
38
40
  // Run in headless mode by default (if process.env.HEADLESS is not specified)
39
41
  const runModeHead = !process.env.HEADLESS || process.env.HEADLESS === 'true' ? true : false;
40
42
 
43
+ // Apply customViewport while running in headless mode
44
+ const runModeViewport = runModeHead ? customViewport : null;
45
+
46
+ let runModeArgs = [];
47
+
48
+ if (runModeBrowser === ['chromium'] && runModeHead === false) {
49
+ runModeArgs = ['--window-size=1920,1080'];
50
+ }
51
+
41
52
  module.exports = {
42
53
  exitOnPageError: false,
43
54
  launchOptions: {
55
+ args: runModeArgs,
44
56
  headless: runModeHead,
45
57
  slowMo: process.env.SLOWMO ? +process.env.SLOWMO : 0,
46
58
  },
47
59
  launchType: "LAUNCH",
48
60
  contextOptions: {
49
61
  acceptDownloads: true,
50
- viewport: {
51
- width: 1920,
52
- height: 1080
53
- },
54
- recordVideo: process.env.VIDEO ? { dir: process.cwd() + '/results-e2e/video' } : undefined
62
+ viewport: runModeViewport,
63
+ ...(process.env.VIDEO && {recordVideo: { dir: process.cwd() + '/results/video' } }),
55
64
  },
56
65
  browsers: runModeBrowser
57
66
  }
package/jest.auth.js CHANGED
@@ -1,36 +1,5 @@
1
- const fetch = require('node-fetch');
2
-
3
- let authEndpoint = 'https://test.id.spsc.io/identity/token/';
4
-
5
- if (process.env.ENV && process.env.ENV.toLowerCase() === 'prod') {
6
- authEndpoint = 'https://id.spsc.io/identity/token/';
7
- }
1
+ const { getAuthToken } = require('./helpers/apiCalls');
8
2
 
9
3
  module.exports = async () => {
10
- if (process.env.USER_EMAIL && process.env.USER_PASSWORD) {
11
- const requestOptions = {
12
- method: 'POST',
13
- body: JSON.stringify({
14
- username: process.env.USER_EMAIL,
15
- password: process.env.USER_PASSWORD,
16
- client_id: "595",
17
- grant_type: "password"
18
- }),
19
- headers: {
20
- 'Accept': 'application/json',
21
- 'Content-Type': 'application/json'
22
- }
23
- }
24
- try {
25
- const fetchResponse = await fetch(authEndpoint, requestOptions);
26
- const data = await fetchResponse.json();
27
- process.env.TOKEN = data.access_token;
28
- return;
29
- } catch (e) {
30
- console.log(e);
31
- return process.exit(1);
32
- }
33
- } else {
34
- throw new Error(`Set up process environment variables: USER_EMAIL and USER_PASSWORD.`);
35
- }
4
+ process.env.TOKEN = await getAuthToken();
36
5
  }
package/jest.config.js CHANGED
@@ -17,6 +17,7 @@ module.exports = {
17
17
  ],
18
18
  setupFilesAfterEnv: [
19
19
  "./jest.setup.js",
20
+ "jest-extended/all",
20
21
  // https://github.com/mattphillips/jest-expect-message/issues/39
21
22
  // "jest-expect-message",
22
23
  "@alex_neo/jest-expect-message"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spscommerce/e2e-core",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "description": "An automation test framework which is based on playwright, jest and ts",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -34,10 +34,12 @@
34
34
  "jest": "^27.3.1",
35
35
  "jest-circus": "^27.3.1",
36
36
  "jest-expect-message": "^1.0.2",
37
+ "jest-extended": "^1.2.0",
37
38
  "jest-junit": "^13.0.0",
38
39
  "jest-playwright-preset": "^1.7.0",
39
- "node-fetch": "^2.6.5",
40
+ "node-fetch": "^2.6.6",
40
41
  "playwright": "^1.16.1",
42
+ "playwright-core": "^1.17.1",
41
43
  "ts-jest": "^27.0.7",
42
44
  "typescript": "^4.4.4"
43
45
  }