@prismicio/e2e-tests-utils 1.0.0-alpha.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.
- package/LICENSE +202 -0
- package/README.md +128 -0
- package/dist/clients/authenticationApi.cjs +36 -0
- package/dist/clients/authenticationApi.cjs.map +1 -0
- package/dist/clients/authenticationApi.d.ts +6 -0
- package/dist/clients/authenticationApi.js +36 -0
- package/dist/clients/authenticationApi.js.map +1 -0
- package/dist/clients/customTypesApi.cjs +71 -0
- package/dist/clients/customTypesApi.cjs.map +1 -0
- package/dist/clients/customTypesApi.d.ts +11 -0
- package/dist/clients/customTypesApi.js +71 -0
- package/dist/clients/customTypesApi.js.map +1 -0
- package/dist/clients/wroom.cjs +78 -0
- package/dist/clients/wroom.cjs.map +1 -0
- package/dist/clients/wroom.d.ts +25 -0
- package/dist/clients/wroom.js +78 -0
- package/dist/clients/wroom.js.map +1 -0
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/managers/repositories.cjs +130 -0
- package/dist/managers/repositories.cjs.map +1 -0
- package/dist/managers/repositories.d.ts +84 -0
- package/dist/managers/repositories.js +130 -0
- package/dist/managers/repositories.js.map +1 -0
- package/dist/managers/repository.cjs +187 -0
- package/dist/managers/repository.cjs.map +1 -0
- package/dist/managers/repository.d.ts +114 -0
- package/dist/managers/repository.js +187 -0
- package/dist/managers/repository.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/utils/cookies.cjs +20 -0
- package/dist/utils/cookies.cjs.map +1 -0
- package/dist/utils/cookies.d.ts +8 -0
- package/dist/utils/cookies.js +20 -0
- package/dist/utils/cookies.js.map +1 -0
- package/dist/utils/envVariableManager.cjs +36 -0
- package/dist/utils/envVariableManager.cjs.map +1 -0
- package/dist/utils/envVariableManager.d.ts +16 -0
- package/dist/utils/envVariableManager.js +36 -0
- package/dist/utils/envVariableManager.js.map +1 -0
- package/dist/utils/log.cjs +25 -0
- package/dist/utils/log.cjs.map +1 -0
- package/dist/utils/log.d.ts +3 -0
- package/dist/utils/log.js +25 -0
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/random.cjs +9 -0
- package/dist/utils/random.cjs.map +1 -0
- package/dist/utils/random.d.ts +8 -0
- package/dist/utils/random.js +9 -0
- package/dist/utils/random.js.map +1 -0
- package/package.json +88 -0
- package/src/clients/authenticationApi.ts +53 -0
- package/src/clients/customTypesApi.ts +145 -0
- package/src/clients/wroom.ts +91 -0
- package/src/index.ts +3 -0
- package/src/managers/repositories.ts +194 -0
- package/src/managers/repository.ts +277 -0
- package/src/types.ts +1 -0
- package/src/utils/cookies.ts +30 -0
- package/src/utils/envVariableManager.ts +35 -0
- package/src/utils/log.ts +26 -0
- package/src/utils/random.ts +14 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Credentials } from "../types";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AuthenticationClient,
|
|
5
|
+
createAuthenticationApiClient,
|
|
6
|
+
} from "../clients/authenticationApi";
|
|
7
|
+
import { createCustomTypesApiClient } from "../clients/customTypesApi";
|
|
8
|
+
import { WroomClient } from "../clients/wroom";
|
|
9
|
+
import { EnvVariableManager } from "../utils/envVariableManager";
|
|
10
|
+
import { logHttpResponse, logger } from "../utils/log";
|
|
11
|
+
import { randomString } from "../utils/random";
|
|
12
|
+
|
|
13
|
+
import { RepositoryConfig, RepositoryManager } from "./repository";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Factory method to create a RepositoriesManager to manage repositories test
|
|
17
|
+
* data.
|
|
18
|
+
*
|
|
19
|
+
* @param urlConfig - If provided as an object:
|
|
20
|
+
*
|
|
21
|
+
* - {@link UrlConfig.baseURL}: The Prismic base URL.
|
|
22
|
+
* - {@link UrlConfig.customTypesApi}: The base URL for the Custom Types API.
|
|
23
|
+
* - {@link UrlConfig.authenticationApi}: The base URL for the Authentication API.
|
|
24
|
+
*
|
|
25
|
+
* If provided as a string: It is treated as the base URL for Prismic. Other
|
|
26
|
+
* URLs (Custom Types API, Auth API) will be derived from it.
|
|
27
|
+
* @param auth - The authentication credentials
|
|
28
|
+
*
|
|
29
|
+
* @returns An instance of {@link RepositoriesManager} to manage test data.
|
|
30
|
+
*/
|
|
31
|
+
export const createRepositoriesManager = (
|
|
32
|
+
urlConfig: UrlConfig | string,
|
|
33
|
+
auth: Credentials,
|
|
34
|
+
): RepositoriesManager => {
|
|
35
|
+
return new RepositoriesManager(urlConfig, auth);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** Utility object to manage Prismic test data */
|
|
39
|
+
export class RepositoriesManager {
|
|
40
|
+
private readonly urls: UrlConfig;
|
|
41
|
+
private readonly wroomClient: WroomClient;
|
|
42
|
+
private readonly authClient: AuthenticationClient;
|
|
43
|
+
/**
|
|
44
|
+
* helper to keep track of repositories across independent test phases (setup,
|
|
45
|
+
* teardown)
|
|
46
|
+
*/
|
|
47
|
+
private readonly repositories = new EnvVariableManager(
|
|
48
|
+
"_PRISMIC_E2E_TESTS_REPOS",
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param prismicUrl - The base URL of the Wroom app.
|
|
53
|
+
* @param credentials - Authentication credentials (email and password)
|
|
54
|
+
*/
|
|
55
|
+
constructor(
|
|
56
|
+
urls: UrlConfig | string,
|
|
57
|
+
private readonly credentials: Credentials,
|
|
58
|
+
) {
|
|
59
|
+
if (typeof urls === "string") {
|
|
60
|
+
// When a string is provided, treat it as the 'base' property
|
|
61
|
+
urls = this.inferUrls(urls);
|
|
62
|
+
}
|
|
63
|
+
this.urls = urls;
|
|
64
|
+
this.wroomClient = new WroomClient(this.urls.baseURL, this.credentials);
|
|
65
|
+
this.authClient = createAuthenticationApiClient(
|
|
66
|
+
this.urls.authenticationApi,
|
|
67
|
+
this.credentials,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* If the baseURL is prismic.io, assume the other services have the format
|
|
73
|
+
* <name>.prismic.io
|
|
74
|
+
*/
|
|
75
|
+
private inferUrls(baseURL: string): UrlConfig {
|
|
76
|
+
const url = new URL(baseURL);
|
|
77
|
+
const protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
baseURL: baseURL,
|
|
81
|
+
authenticationApi: `${protocol}://auth.${url.hostname}`,
|
|
82
|
+
customTypesApi: `${protocol}://customtypes.${url.hostname}`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Generate a user token from the authentication service.
|
|
88
|
+
*
|
|
89
|
+
* @returns a JWT token
|
|
90
|
+
*/
|
|
91
|
+
async getUserApiToken(): Promise<string> {
|
|
92
|
+
return this.authClient.getToken();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Create a new repository in Wroom.
|
|
97
|
+
*
|
|
98
|
+
* @param repositoryName - The name of the repository.
|
|
99
|
+
*
|
|
100
|
+
* @throws Error if the repository creation fails.
|
|
101
|
+
*/
|
|
102
|
+
async createRepository(
|
|
103
|
+
config: {
|
|
104
|
+
prefix?: string;
|
|
105
|
+
} & RepositoryConfig = {},
|
|
106
|
+
): Promise<RepositoryManager> {
|
|
107
|
+
const profiler = logger.startTimer();
|
|
108
|
+
|
|
109
|
+
const { prefix = "e2e-tests" } = config;
|
|
110
|
+
const repositoryName = `${prefix}-${randomString()}`;
|
|
111
|
+
|
|
112
|
+
const response = await this.wroomClient.post(
|
|
113
|
+
null,
|
|
114
|
+
"/authentication/newrepository",
|
|
115
|
+
{
|
|
116
|
+
domain: repositoryName,
|
|
117
|
+
framework: "next",
|
|
118
|
+
plan: "personal",
|
|
119
|
+
isAnnual: "false",
|
|
120
|
+
role: "developer",
|
|
121
|
+
},
|
|
122
|
+
);
|
|
123
|
+
if (response.status !== 200) {
|
|
124
|
+
logHttpResponse(response);
|
|
125
|
+
throw new Error(`Could not create repository ${repositoryName}`);
|
|
126
|
+
}
|
|
127
|
+
this.repositories.add(repositoryName);
|
|
128
|
+
|
|
129
|
+
profiler.done({ message: `created repository '${repositoryName}'` });
|
|
130
|
+
|
|
131
|
+
const repository = this.getRepositoryManager(repositoryName);
|
|
132
|
+
await repository.configure(config);
|
|
133
|
+
|
|
134
|
+
return repository;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Delete a repository from Wroom.
|
|
139
|
+
*
|
|
140
|
+
* @param repository - The name of the repository.
|
|
141
|
+
*
|
|
142
|
+
* @throws Error if the repository deletion fails.
|
|
143
|
+
*/
|
|
144
|
+
async deleteRepository(repository: string): Promise<void> {
|
|
145
|
+
const profiler = logger.startTimer();
|
|
146
|
+
|
|
147
|
+
const response = await this.wroomClient.post(
|
|
148
|
+
repository,
|
|
149
|
+
"./app/settings/delete",
|
|
150
|
+
{ confirm: repository, password: this.credentials.password },
|
|
151
|
+
);
|
|
152
|
+
if (response.status !== 200) {
|
|
153
|
+
logHttpResponse(response);
|
|
154
|
+
throw new Error(`Could not delete repository ${repository}`);
|
|
155
|
+
}
|
|
156
|
+
this.repositories.remove(repository);
|
|
157
|
+
profiler.done({ message: `deleted repository '${repository}'` });
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Cleanup test data. For example, it deletes repositories created using
|
|
162
|
+
* createRepository()
|
|
163
|
+
*/
|
|
164
|
+
async tearDown(): Promise<void> {
|
|
165
|
+
const repositories = this.repositories.getAll();
|
|
166
|
+
for (const repository of repositories) {
|
|
167
|
+
await this.deleteRepository(repository);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Return a repository utilities object for a repository.
|
|
173
|
+
*
|
|
174
|
+
* @param name - The name of the repository.
|
|
175
|
+
*/
|
|
176
|
+
getRepositoryManager(name: string): RepositoryManager {
|
|
177
|
+
const customTypeClient = createCustomTypesApiClient(
|
|
178
|
+
this.urls.customTypesApi,
|
|
179
|
+
name,
|
|
180
|
+
this.authClient,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
return new RepositoryManager(name, this.wroomClient, customTypeClient);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export type UrlConfig = {
|
|
188
|
+
/** Prismic base url */
|
|
189
|
+
baseURL: string;
|
|
190
|
+
/** Custom types api base url */
|
|
191
|
+
customTypesApi: string;
|
|
192
|
+
/** Auth service api base url */
|
|
193
|
+
authenticationApi: string;
|
|
194
|
+
};
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
CustomType,
|
|
5
|
+
SharedSlice,
|
|
6
|
+
} from "@prismicio/types-internal/lib/customtypes";
|
|
7
|
+
|
|
8
|
+
import { CustomTypesClient } from "../clients/customTypesApi";
|
|
9
|
+
import { WroomClient } from "../clients/wroom";
|
|
10
|
+
import { logHttpResponse, logger } from "../utils/log";
|
|
11
|
+
|
|
12
|
+
/** Utility to manage test data for a Prismic repository */
|
|
13
|
+
export class RepositoryManager {
|
|
14
|
+
constructor(
|
|
15
|
+
readonly name: string,
|
|
16
|
+
private readonly wroomClient: WroomClient,
|
|
17
|
+
private readonly customTypesApiClient: CustomTypesClient,
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
async configure(config: RepositoryConfig): Promise<void> {
|
|
21
|
+
if (config.locales) {
|
|
22
|
+
await this.createLocales(config.locales);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (config.customLocale) {
|
|
26
|
+
await this.createCustomLocale(config.customLocale);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (config.defaultLocale) {
|
|
30
|
+
await this.setDefaultLocale(config.defaultLocale);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (config.slices) {
|
|
34
|
+
await this.createSlices(config.slices);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (config.customTypes) {
|
|
38
|
+
await this.createCustomTypes(config.customTypes);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (config.preview) {
|
|
42
|
+
await this.createPreview(config.preview);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** @returns the repository base url, like https://my-repo.prismic.io */
|
|
46
|
+
getBaseURL(): string {
|
|
47
|
+
const url = new URL(this.wroomClient.getBaseURL());
|
|
48
|
+
url.hostname = `${this.name}.${url.hostname}`;
|
|
49
|
+
|
|
50
|
+
return url.toString();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Set additional standard locales for a repository in Wroom, does not fail if
|
|
55
|
+
* the locales already exist.
|
|
56
|
+
*
|
|
57
|
+
* @param locales - An array of all locales to be added to the repository.
|
|
58
|
+
*
|
|
59
|
+
* @throws Error if setting the locales fails.
|
|
60
|
+
*/
|
|
61
|
+
async createLocales(locales: string[]): Promise<void> {
|
|
62
|
+
const profiler = logger.startTimer();
|
|
63
|
+
|
|
64
|
+
const response = await this.wroomClient.post(
|
|
65
|
+
this.name,
|
|
66
|
+
"app/settings/multilanguages",
|
|
67
|
+
{ languages: locales },
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const { data, status } = response;
|
|
71
|
+
const success =
|
|
72
|
+
status === 200 ||
|
|
73
|
+
(status === 400 &&
|
|
74
|
+
(data as string).includes("already existing languages"));
|
|
75
|
+
if (!success) {
|
|
76
|
+
logHttpResponse(response);
|
|
77
|
+
throw new Error(`Could not add locales ${locales.join(", ")}`);
|
|
78
|
+
}
|
|
79
|
+
profiler.done({ message: `standard locales '${locales}' set` });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Set additional custom locale for a repository in Wroom, does not fail if
|
|
84
|
+
* the locales already exist.
|
|
85
|
+
*
|
|
86
|
+
* @param locale - The locale to be added to the repository.
|
|
87
|
+
*
|
|
88
|
+
* @throws Error if setting the locale fails.
|
|
89
|
+
*/
|
|
90
|
+
async createCustomLocale(locale: CustomLocale): Promise<void> {
|
|
91
|
+
const profiler = logger.startTimer();
|
|
92
|
+
|
|
93
|
+
const response = await this.wroomClient.post(
|
|
94
|
+
this.name,
|
|
95
|
+
"app/settings/multilanguages/custom",
|
|
96
|
+
locale,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const { data, status } = response;
|
|
100
|
+
const success =
|
|
101
|
+
status === 200 ||
|
|
102
|
+
(status === 400 && (data as string).includes("code is already used"));
|
|
103
|
+
if (!success) {
|
|
104
|
+
logHttpResponse(response);
|
|
105
|
+
throw new Error(`Could not create custom locale ${locale}`);
|
|
106
|
+
}
|
|
107
|
+
profiler.done({
|
|
108
|
+
message: `custom locale ${JSON.stringify(locale)} created`,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private failIfNot200(response: AxiosResponse, msg: string) {
|
|
113
|
+
if (response.status !== 200) {
|
|
114
|
+
logHttpResponse(response);
|
|
115
|
+
throw new Error(msg);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Delete a locale from a repository.
|
|
121
|
+
*
|
|
122
|
+
* @param locale - locale to remove from the repository configuration.
|
|
123
|
+
*
|
|
124
|
+
* @throws Error if deleting the locale fails.
|
|
125
|
+
*/
|
|
126
|
+
async deleteLocale(locale: string): Promise<void> {
|
|
127
|
+
const profiler = logger.startTimer();
|
|
128
|
+
|
|
129
|
+
const response = await this.wroomClient.post(
|
|
130
|
+
this.name,
|
|
131
|
+
`app/settings/multilanguages/${locale}/delete`,
|
|
132
|
+
);
|
|
133
|
+
this.failIfNot200(response, `Could not delete locale ${locale}`);
|
|
134
|
+
profiler.done({ message: `locale '${locale}' deleted` });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Set the default (master) locale for a repository in Wroom, the locale needs
|
|
139
|
+
* to exist for the repository.
|
|
140
|
+
*
|
|
141
|
+
* @param locale - The locale to be set as the default.
|
|
142
|
+
*
|
|
143
|
+
* @throws Error if setting the default locale fails.
|
|
144
|
+
*/
|
|
145
|
+
async setDefaultLocale(locale: string): Promise<void> {
|
|
146
|
+
const profiler = logger.startTimer();
|
|
147
|
+
|
|
148
|
+
const response = await this.wroomClient.post(
|
|
149
|
+
this.name,
|
|
150
|
+
`/app/settings/multilanguages/${locale}/defineAsMaster`,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
this.failIfNot200(response, `Could not set default locale to ${locale}`);
|
|
154
|
+
profiler.done({ message: `default locale set to '${locale}'` });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Creates a release.
|
|
159
|
+
*
|
|
160
|
+
* @param label - The label for the release.
|
|
161
|
+
*
|
|
162
|
+
* @returns A Promise that resolves when the release is created.
|
|
163
|
+
*/
|
|
164
|
+
async createRelease(label: string): Promise<{ id: string }> {
|
|
165
|
+
const profiler = logger.startTimer();
|
|
166
|
+
|
|
167
|
+
const response = await this.wroomClient.post(this.name, "./app/releases", {
|
|
168
|
+
label,
|
|
169
|
+
});
|
|
170
|
+
this.failIfNot200(response, `Could not create release ${label}`);
|
|
171
|
+
profiler.done({ message: `release '${label}' created` });
|
|
172
|
+
|
|
173
|
+
return response.data;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Deletes a repository release.
|
|
178
|
+
*
|
|
179
|
+
* @param repository - The name of the repository.
|
|
180
|
+
* @param id - The ID of the release to be deleted.
|
|
181
|
+
*/
|
|
182
|
+
async deleteRelease(id: string): Promise<void> {
|
|
183
|
+
const profiler = logger.startTimer();
|
|
184
|
+
|
|
185
|
+
const response = await this.wroomClient.post(
|
|
186
|
+
this.name,
|
|
187
|
+
`./app/releases/${id}/delete`,
|
|
188
|
+
{},
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
this.failIfNot200(response, `Could not delete release with id ${id}`);
|
|
192
|
+
profiler.done({ message: `release '${id}' deleted` });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Creates a preview for a repository.
|
|
197
|
+
*
|
|
198
|
+
* @param data - The data for creating the preview.
|
|
199
|
+
*/
|
|
200
|
+
async createPreview(data: Preview): Promise<void> {
|
|
201
|
+
const profiler = logger.startTimer();
|
|
202
|
+
|
|
203
|
+
const response = await this.wroomClient.post(
|
|
204
|
+
this.name,
|
|
205
|
+
`./previews/new`,
|
|
206
|
+
data,
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
this.failIfNot200(response, `Could not create preview ${data.name}`);
|
|
210
|
+
profiler.done({ message: `preview '${data.name}' created` });
|
|
211
|
+
|
|
212
|
+
return response.data;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Deletes a preview from a repository.
|
|
217
|
+
*
|
|
218
|
+
* @param id - The ID of the preview to be deleted.
|
|
219
|
+
*/
|
|
220
|
+
async deletePreview(id: string): Promise<void> {
|
|
221
|
+
const profiler = logger.startTimer();
|
|
222
|
+
|
|
223
|
+
const response = await this.wroomClient.post(
|
|
224
|
+
this.name,
|
|
225
|
+
`./previews/delete/${id}`,
|
|
226
|
+
{},
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
this.failIfNot200(response, `Could not delete preview with id${id}`);
|
|
230
|
+
profiler.done({ message: `preview '${id}' deleted` });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Create Custom Types using the Custom types api.
|
|
235
|
+
*
|
|
236
|
+
* @param customTypes -
|
|
237
|
+
*/
|
|
238
|
+
async createCustomTypes(customTypes: CustomType[]): Promise<void> {
|
|
239
|
+
await this.customTypesApiClient.createCustomTypes(customTypes);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Create slices using the Custom types api.
|
|
244
|
+
*
|
|
245
|
+
* @param slices -
|
|
246
|
+
*/
|
|
247
|
+
async createSlices(slices: SharedSlice[]): Promise<void> {
|
|
248
|
+
await this.customTypesApiClient.createSlices(slices);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export type RepositoryConfig = {
|
|
253
|
+
customLocale?: CustomLocale;
|
|
254
|
+
locales?: string[];
|
|
255
|
+
defaultLocale?: string;
|
|
256
|
+
slices?: SharedSlice[];
|
|
257
|
+
customTypes?: CustomType[];
|
|
258
|
+
preview?: Preview;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
export type Preview = {
|
|
262
|
+
name: string;
|
|
263
|
+
websiteURL: string;
|
|
264
|
+
resolverPath: string;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
export type CustomLocale = {
|
|
268
|
+
lang: {
|
|
269
|
+
label: string;
|
|
270
|
+
id: string;
|
|
271
|
+
useStandardAnalyzer?: boolean;
|
|
272
|
+
};
|
|
273
|
+
region: {
|
|
274
|
+
label: string;
|
|
275
|
+
id: string;
|
|
276
|
+
};
|
|
277
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Credentials = { email: string; password: string };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AxiosHeaderValue } from "axios";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Extract the value of a specific cookie from Axios cookies.
|
|
5
|
+
*
|
|
6
|
+
* @param cookies - Axios cookies, can be a string or an array
|
|
7
|
+
* @param cookieName - The name of the cookie to extract.
|
|
8
|
+
*/
|
|
9
|
+
export const extractCookie = (
|
|
10
|
+
cookies: AxiosHeaderValue | undefined,
|
|
11
|
+
cookieName: string,
|
|
12
|
+
): string | undefined => {
|
|
13
|
+
const regex = new RegExp(`${cookieName}=([^;]+)`, "i"); // 'i' flag for case-insensitivity
|
|
14
|
+
|
|
15
|
+
if (typeof cookies === "string") {
|
|
16
|
+
const match = cookies.match(regex);
|
|
17
|
+
|
|
18
|
+
return match ? match[1] : undefined;
|
|
19
|
+
}
|
|
20
|
+
if (cookies instanceof Array) {
|
|
21
|
+
for (const cookie of cookies) {
|
|
22
|
+
const match = cookie.match(regex);
|
|
23
|
+
if (match) {
|
|
24
|
+
return match[1];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return undefined;
|
|
30
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manage a list of strings within an environment variable. This is useful to
|
|
3
|
+
* share data across different test phases (setup, teardown, test execution) as
|
|
4
|
+
* most test frameworks run these in independent states
|
|
5
|
+
*/
|
|
6
|
+
export class EnvVariableManager {
|
|
7
|
+
constructor(private variableName: string) {}
|
|
8
|
+
|
|
9
|
+
/** add a string and persist it in the environment variable */
|
|
10
|
+
add(value: string): void {
|
|
11
|
+
const existingValues = this.getAll();
|
|
12
|
+
existingValues.push(value);
|
|
13
|
+
|
|
14
|
+
this.setAll(existingValues);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** remove a string from the environment variable */
|
|
18
|
+
remove(value: string): void {
|
|
19
|
+
const existingValues = this.getAll();
|
|
20
|
+
const updatedValues = existingValues.filter((item) => item !== value);
|
|
21
|
+
|
|
22
|
+
this.setAll(updatedValues);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** return all items stored in the environment variable */
|
|
26
|
+
getAll(): string[] {
|
|
27
|
+
const value = process.env[this.variableName] || "[]";
|
|
28
|
+
|
|
29
|
+
return JSON.parse(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private setAll(values: string[]): void {
|
|
33
|
+
process.env[this.variableName] = JSON.stringify(values);
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/utils/log.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { createLogger, format, transports } from "winston";
|
|
3
|
+
|
|
4
|
+
export const logHttpResponse = (response: AxiosResponse): void => {
|
|
5
|
+
const { status, data } = response;
|
|
6
|
+
const { url = "" } = response.config;
|
|
7
|
+
logger.info(`Call to ${url} failed, received [${status}] ${data}`);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const { combine, printf } = format;
|
|
11
|
+
|
|
12
|
+
const customFormat = printf(({ message, durationMs }) => {
|
|
13
|
+
const baseMsg = `[test data] ${message}`;
|
|
14
|
+
if (durationMs) {
|
|
15
|
+
return `${baseMsg} in ${durationMs}ms`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return baseMsg;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const logger = createLogger({
|
|
22
|
+
silent: process.env["prismic_e2e_tests_utils_silent"] === "true",
|
|
23
|
+
level: process.env["prismic_e2e_tests_utils_log_level"] || "info",
|
|
24
|
+
format: combine(customFormat),
|
|
25
|
+
transports: [new transports.Console()],
|
|
26
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate a random string
|
|
5
|
+
*
|
|
6
|
+
* @param length - max 32
|
|
7
|
+
*
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export const randomString = (length = 16): string => {
|
|
11
|
+
const uniqueInput = Math.random().toString();
|
|
12
|
+
|
|
13
|
+
return createHash("md5").update(uniqueInput).digest("hex").slice(0, length);
|
|
14
|
+
};
|