@prismicio/e2e-tests-utils 1.5.1-alpha.1 → 1.5.1
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.
|
@@ -8,6 +8,7 @@ var __publicField = (obj, key, value) => {
|
|
|
8
8
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
9
|
const test = require("@playwright/test");
|
|
10
10
|
const log = require("../utils/log.cjs");
|
|
11
|
+
const urls = require("../utils/urls.cjs");
|
|
11
12
|
class AuthenticationApiClient {
|
|
12
13
|
constructor(baseURL, auth) {
|
|
13
14
|
__publicField(this, "baseURL");
|
|
@@ -20,7 +21,7 @@ class AuthenticationApiClient {
|
|
|
20
21
|
async getContext() {
|
|
21
22
|
if (!this._context) {
|
|
22
23
|
this._context = await test.request.newContext({
|
|
23
|
-
baseURL: this.baseURL
|
|
24
|
+
baseURL: urls.appendTrailingSlash(this.baseURL)
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
return this._context;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticationApi.cjs","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\n/** Client for interacting with the authentication service to manage tokens */\nexport class AuthenticationApiClient {\n\tprivate authToken?: string;\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t) {}\n\n\tprivate async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: this.baseURL,\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n\n\tprivate async login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"login\", {\n\t\t\tdata: {\n\t\t\t\temail: this.auth.email,\n\t\t\t\tpassword: this.auth.password,\n\t\t\t},\n\t\t});\n\n\t\tconst token = await result.text();\n\t\tif (!result.ok() || !token) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `generated user token for ${this.auth.email} from auth service`,\n\t\t});\n\n\t\treturn token;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getToken(): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\treturn this.authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"machine2machine\", {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.authToken}`,\n\t\t\t\trepository,\n\t\t\t},\n\t\t});\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\t\tconst token = (await result.json()).token;\n\n\t\treturn token;\n\t}\n}\n"],"names":["request","logger","logPlaywrightApiResponse"],"mappings":"
|
|
1
|
+
{"version":3,"file":"authenticationApi.cjs","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\nimport { appendTrailingSlash } from \"../utils/urls\";\n\n/** Client for interacting with the authentication service to manage tokens */\nexport class AuthenticationApiClient {\n\tprivate authToken?: string;\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t) {}\n\n\tprivate async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: appendTrailingSlash(this.baseURL),\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n\n\tprivate async login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"login\", {\n\t\t\tdata: {\n\t\t\t\temail: this.auth.email,\n\t\t\t\tpassword: this.auth.password,\n\t\t\t},\n\t\t});\n\n\t\tconst token = await result.text();\n\t\tif (!result.ok() || !token) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `generated user token for ${this.auth.email} from auth service`,\n\t\t});\n\n\t\treturn token;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getToken(): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\treturn this.authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"machine2machine\", {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.authToken}`,\n\t\t\t\trepository,\n\t\t\t},\n\t\t});\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\t\tconst token = (await result.json()).token;\n\n\t\treturn token;\n\t}\n}\n"],"names":["request","appendTrailingSlash","logger","logPlaywrightApiResponse"],"mappings":";;;;;;;;;;;MAQa,wBAAuB;AAAA,EAInC,YACkB,SACA,MAAgB;AADhB;AACA;AALV;AACA;AAGU,SAAO,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AM,SAAS,MAAM,OAAO,KAAA,GAAQ;AAE7B,WAAA;AAAA,EACR;AACA;;"}
|
|
@@ -6,6 +6,7 @@ var __publicField = (obj, key, value) => {
|
|
|
6
6
|
};
|
|
7
7
|
import { request } from "@playwright/test";
|
|
8
8
|
import { logger, logPlaywrightApiResponse } from "../utils/log.js";
|
|
9
|
+
import { appendTrailingSlash } from "../utils/urls.js";
|
|
9
10
|
class AuthenticationApiClient {
|
|
10
11
|
constructor(baseURL, auth) {
|
|
11
12
|
__publicField(this, "baseURL");
|
|
@@ -18,7 +19,7 @@ class AuthenticationApiClient {
|
|
|
18
19
|
async getContext() {
|
|
19
20
|
if (!this._context) {
|
|
20
21
|
this._context = await request.newContext({
|
|
21
|
-
baseURL: this.baseURL
|
|
22
|
+
baseURL: appendTrailingSlash(this.baseURL)
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
25
|
return this._context;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticationApi.js","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\n/** Client for interacting with the authentication service to manage tokens */\nexport class AuthenticationApiClient {\n\tprivate authToken?: string;\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t) {}\n\n\tprivate async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: this.baseURL,\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n\n\tprivate async login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"login\", {\n\t\t\tdata: {\n\t\t\t\temail: this.auth.email,\n\t\t\t\tpassword: this.auth.password,\n\t\t\t},\n\t\t});\n\n\t\tconst token = await result.text();\n\t\tif (!result.ok() || !token) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `generated user token for ${this.auth.email} from auth service`,\n\t\t});\n\n\t\treturn token;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getToken(): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\treturn this.authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"machine2machine\", {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.authToken}`,\n\t\t\t\trepository,\n\t\t\t},\n\t\t});\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\t\tconst token = (await result.json()).token;\n\n\t\treturn token;\n\t}\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authenticationApi.js","sources":["../../../src/clients/authenticationApi.ts"],"sourcesContent":["import { APIRequestContext, request } from \"@playwright/test\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\nimport { appendTrailingSlash } from \"../utils/urls\";\n\n/** Client for interacting with the authentication service to manage tokens */\nexport class AuthenticationApiClient {\n\tprivate authToken?: string;\n\tprivate _context?: APIRequestContext;\n\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t) {}\n\n\tprivate async getContext(): Promise<APIRequestContext> {\n\t\tif (!this._context) {\n\t\t\tthis._context = await request.newContext({\n\t\t\t\tbaseURL: appendTrailingSlash(this.baseURL),\n\t\t\t});\n\t\t}\n\n\t\treturn this._context;\n\t}\n\n\tprivate async login(): Promise<string> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(\"login\", {\n\t\t\tdata: {\n\t\t\t\temail: this.auth.email,\n\t\t\t\tpassword: this.auth.password,\n\t\t\t},\n\t\t});\n\n\t\tconst token = await result.text();\n\t\tif (!result.ok() || !token) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Authentication failed, no token received.\");\n\t\t}\n\n\t\tprofiler.done({\n\t\t\tmessage: `generated user token for ${this.auth.email} from auth service`,\n\t\t});\n\n\t\treturn token;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getToken(): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\treturn this.authToken;\n\t}\n\n\t/** Return an api user token. Creates one if needed. */\n\tasync getMachine2MachineToken(repository: string): Promise<string> {\n\t\tif (!this.authToken) {\n\t\t\tthis.authToken = await this.login();\n\t\t}\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(\"machine2machine\", {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.authToken}`,\n\t\t\t\trepository,\n\t\t\t},\n\t\t});\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t\"Machine2Machine token generation failed, no token received.\",\n\t\t\t);\n\t\t}\n\t\tconst token = (await result.json()).token;\n\n\t\treturn token;\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;MAQa,wBAAuB;AAAA,EAInC,YACkB,SACA,MAAgB;AADhB;AACA;AALV;AACA;AAGU,SAAO,UAAP;AACA,SAAI,OAAJ;AAAA,EACf;AAAA,EAEK,MAAM,aAAU;AACnB,QAAA,CAAC,KAAK,UAAU;AACd,WAAA,WAAW,MAAM,QAAQ,WAAW;AAAA,QACxC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
|
-
"version": "1.5.1
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "A collection of utilities for to manage Prismic test data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -54,19 +54,14 @@
|
|
|
54
54
|
"test": "npm run lint && npm run types && npm run unit && npm run build && npm run size"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
+
"@prismicio/types-internal": "^2.3.1",
|
|
57
58
|
"axios": "^1.6.2",
|
|
58
59
|
"jsonwebtoken": "^9.0.2",
|
|
59
60
|
"lodash.isequal": "^4.5.0",
|
|
60
61
|
"winston": "^3.11.0"
|
|
61
62
|
},
|
|
62
63
|
"peerDependencies": {
|
|
63
|
-
"@playwright/test": ">= 1.16"
|
|
64
|
-
"@prismicio/types-internal": ">= 2.3.1"
|
|
65
|
-
},
|
|
66
|
-
"peerDependenciesMeta": {
|
|
67
|
-
"@prismicio/types-internal": {
|
|
68
|
-
"optional": true
|
|
69
|
-
}
|
|
64
|
+
"@playwright/test": ">= 1.16"
|
|
70
65
|
},
|
|
71
66
|
"devDependencies": {
|
|
72
67
|
"@size-limit/preset-small-lib": "^11.0.1",
|
|
@@ -3,6 +3,7 @@ import { APIRequestContext, request } from "@playwright/test";
|
|
|
3
3
|
import { AuthConfig } from "../types";
|
|
4
4
|
|
|
5
5
|
import { logPlaywrightApiResponse, logger } from "../utils/log";
|
|
6
|
+
import { appendTrailingSlash } from "../utils/urls";
|
|
6
7
|
|
|
7
8
|
/** Client for interacting with the authentication service to manage tokens */
|
|
8
9
|
export class AuthenticationApiClient {
|
|
@@ -17,7 +18,7 @@ export class AuthenticationApiClient {
|
|
|
17
18
|
private async getContext(): Promise<APIRequestContext> {
|
|
18
19
|
if (!this._context) {
|
|
19
20
|
this._context = await request.newContext({
|
|
20
|
-
baseURL: this.baseURL,
|
|
21
|
+
baseURL: appendTrailingSlash(this.baseURL),
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
|