@spscommerce/e2e-core 1.1.0 → 1.1.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.
- package/helpers/apiCalls.ts +10 -2
- package/helpers/authSetup.ts +16 -7
- package/jest-environment.config.js +13 -4
- package/jest.setup.js +1 -8
- package/package.json +1 -1
- package/helpers/envSetup.ts +0 -9
package/helpers/apiCalls.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
let authEndpoint = 'https://test.id.spsc.io/';
|
|
4
|
+
|
|
5
|
+
if (process.env.URL && process.env.URL.toLowerCase().includes('prod')) {
|
|
6
|
+
authEndpoint = 'https://id.spsc.io/';
|
|
7
|
+
}
|
|
3
8
|
|
|
4
9
|
export async function getAuthToken(): Promise<string> {
|
|
5
10
|
if (process.env.USER_EMAIL && process.env.USER_PASSWORD) {
|
|
@@ -56,7 +61,10 @@ export async function changePreferredOrg(orgID: string): Promise<void> {
|
|
|
56
61
|
email: userData.email,
|
|
57
62
|
first_name: userData.first_name,
|
|
58
63
|
last_name: userData.last_name,
|
|
59
|
-
preferred_org_id: orgID
|
|
64
|
+
preferred_org_id: orgID,
|
|
65
|
+
organization: {
|
|
66
|
+
id: orgID
|
|
67
|
+
}
|
|
60
68
|
}),
|
|
61
69
|
headers: {
|
|
62
70
|
'Authorization': `Bearer ${process.env.TOKEN}`,
|
package/helpers/authSetup.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import { getAuthToken,
|
|
2
|
-
import { primaryOrgID } from './envSetup';
|
|
1
|
+
import { changePreferredOrg, getAuthToken, getUserInfo } from '../helpers/apiCalls';
|
|
3
2
|
|
|
4
|
-
export async function authenticate(orgID
|
|
5
|
-
|
|
3
|
+
export async function authenticate(orgID: string): Promise<void> {
|
|
4
|
+
const testSuiteName = expect.getState().testPath.split('/').pop().split('.').reverse()[2];
|
|
5
|
+
process.env.TOKEN = await getAuthToken();
|
|
6
|
+
let userData = await getUserInfo();
|
|
7
|
+
console.log(`${testSuiteName} suite authentication flow:
|
|
8
|
+
Current preferred org: ${userData.preferred_org_id}.
|
|
9
|
+
Current org: ${userData.organization.organization_name}.`);
|
|
10
|
+
while (userData.preferred_org_id !== orgID || userData.organization.id !== orgID) {
|
|
6
11
|
await changePreferredOrg(orgID);
|
|
7
12
|
process.env.TOKEN = await getAuthToken();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
userData = await getUserInfo();
|
|
14
|
+
console.log(`${testSuiteName} suite authentication flow:
|
|
15
|
+
Preferred org was changed to: ${userData.preferred_org_id}.
|
|
16
|
+
Current org was changed to: ${userData.organization.organization_name}.`);
|
|
11
17
|
}
|
|
18
|
+
console.log(process.env.TOKEN);
|
|
12
19
|
await page.addInitScript(params => {
|
|
13
20
|
window.localStorage.setItem(params.name, params.value);
|
|
14
21
|
}, { name: "access_token", value: process.env.TOKEN });
|
|
@@ -19,5 +26,7 @@ export async function unauthenticate(): Promise<void> {
|
|
|
19
26
|
await context.clearCookies();
|
|
20
27
|
await context.addInitScript(() => window.localStorage.clear());
|
|
21
28
|
await context.addInitScript(() => window.sessionStorage.clear());
|
|
29
|
+
await page.goto(process.env.BASEURL);
|
|
30
|
+
await page.waitForURL(/https:\/\/auth.*/);
|
|
22
31
|
return;
|
|
23
32
|
}
|
|
@@ -32,6 +32,7 @@ class JestEnvironmentFailFast extends ParentEnvironment {
|
|
|
32
32
|
// https://github.com/facebook/jest/issues/10059
|
|
33
33
|
// https://github.com/facebook/jest/blob/main/packages/jest-circus/src/eventHandler.ts
|
|
34
34
|
async handleTestEvent(event, state) {
|
|
35
|
+
await super.handleTestEvent(event);
|
|
35
36
|
|
|
36
37
|
// TEST STARTED
|
|
37
38
|
// Delete already existing screenshot/trace file before test starts if it ran twice due to jest.retryTimes()
|
|
@@ -46,8 +47,17 @@ class JestEnvironmentFailFast extends ParentEnvironment {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
//
|
|
50
|
-
// Take a screenshot for each failed test
|
|
50
|
+
// HOOK FAILS
|
|
51
|
+
// Take a screenshot for each failed test
|
|
52
|
+
if (event.name === 'hook_failure') {
|
|
53
|
+
await this.global.page.screenshot({
|
|
54
|
+
fullPage: true,
|
|
55
|
+
path: process.cwd() + `/results-e2e/screenshots/${event.hook.parent.name.replace(/_$/, '')}.png`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// TEST FAILS
|
|
60
|
+
// Take a screenshot for each failed test
|
|
51
61
|
if (event.name === 'test_fn_failure' && !event.test.parent.name.includes('visual')) {
|
|
52
62
|
this.failedTest = true;
|
|
53
63
|
this.failedTestName = event.test.name;
|
|
@@ -70,14 +80,13 @@ class JestEnvironmentFailFast extends ParentEnvironment {
|
|
|
70
80
|
|
|
71
81
|
// TEST FINISHED AND VIDEO OPTION IS SET TO TRUE
|
|
72
82
|
// Save test status, test suite name and random PW video name
|
|
73
|
-
if (event.name === "test_done" && process.env.VIDEO) {
|
|
83
|
+
if (event.name === "test_done" && process.env.VIDEO && (process.env.VIDEO.toLowerCase() === 'true')) {
|
|
74
84
|
const success = event.test.errors.length === 0 ? true : false;
|
|
75
85
|
const testSuiteName = event.test.parent.name;
|
|
76
86
|
const videoName = await this.global.page.video().path();
|
|
77
87
|
this.videos.push({ testSuiteName, videoName, success });
|
|
78
88
|
}
|
|
79
89
|
|
|
80
|
-
|
|
81
90
|
// TEST FINISHES AND FAILS
|
|
82
91
|
// Skip all further tests in the suite (all tests are related to each other) if
|
|
83
92
|
// - any test is failed AND suite name includes 'FailFast'
|
package/jest.setup.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
const { authenticate } = require('./helpers/authSetup');
|
|
2
1
|
const { enableTracer, disableTracer, enableLogger, disableLogger } = require('./helpers/loggerSetup');
|
|
3
2
|
|
|
4
|
-
// Global hooks
|
|
5
|
-
// You can add additional hooks for a specific suite directly in the test file
|
|
6
|
-
beforeAll(async () => {
|
|
7
|
-
await authenticate();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
3
|
if (process.env.LOGGER || process.env.TRACER) {
|
|
11
4
|
beforeEach(async () => {
|
|
12
5
|
process.env.LOGGER && (process.env.LOGGER.toLowerCase() === 'true') && await enableLogger();
|
|
13
6
|
process.env.TRACER && (process.env.TRACER.toLowerCase() === 'true') && await enableTracer();
|
|
14
7
|
});
|
|
15
|
-
|
|
8
|
+
|
|
16
9
|
afterEach(async () => {
|
|
17
10
|
process.env.LOGGER && (process.env.LOGGER.toLowerCase() === 'true') && await disableLogger();
|
|
18
11
|
process.env.TRACER && (process.env.TRACER.toLowerCase() === 'true') && await disableTracer();
|
package/package.json
CHANGED
package/helpers/envSetup.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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 };
|