@jahia/cypress 1.1.4 → 1.1.6
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/dist/support/apollo/apollo.js +14 -7
- package/dist/support/apollo/apolloClient.js +3 -4
- package/dist/support/apollo/links.d.ts +3 -0
- package/dist/support/apollo/links.js +73 -0
- package/dist/support/provisioning/runProvisioningScript.d.ts +1 -1
- package/dist/support/provisioning/runProvisioningScript.js +7 -5
- package/package.json +2 -1
- package/src/support/apollo/apollo.ts +14 -7
- package/src/support/apollo/apolloClient.ts +5 -5
- package/src/support/apollo/links.ts +64 -0
- package/src/support/provisioning/runProvisioningScript.ts +11 -3
|
@@ -43,24 +43,25 @@ var apollo = function (apollo, options) {
|
|
|
43
43
|
}
|
|
44
44
|
var result;
|
|
45
45
|
var logger;
|
|
46
|
+
var optionsWithDefaultCache = __assign({ fetchPolicy: "no-cache" }, options);
|
|
46
47
|
if (!apollo) {
|
|
47
|
-
cy.apolloClient().apollo(
|
|
48
|
+
cy.apolloClient().apollo(optionsWithDefaultCache);
|
|
48
49
|
}
|
|
49
50
|
else {
|
|
50
|
-
if (isQueryFile(
|
|
51
|
-
var queryFile =
|
|
51
|
+
if (isQueryFile(optionsWithDefaultCache)) {
|
|
52
|
+
var queryFile = optionsWithDefaultCache.queryFile, apolloOptions_1 = __rest(optionsWithDefaultCache, ["queryFile"]);
|
|
52
53
|
cy.fixture(queryFile).then(function (content) {
|
|
53
54
|
cy.apollo(__assign({ query: graphql_tag_1["default"](content) }, apolloOptions_1));
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
|
-
else if (isMutationFile(
|
|
57
|
-
var mutationFile =
|
|
57
|
+
else if (isMutationFile(optionsWithDefaultCache)) {
|
|
58
|
+
var mutationFile = optionsWithDefaultCache.mutationFile, apolloOptions_2 = __rest(optionsWithDefaultCache, ["mutationFile"]);
|
|
58
59
|
cy.fixture(mutationFile).then(function (content) {
|
|
59
60
|
cy.apollo(__assign({ mutation: graphql_tag_1["default"](content) }, apolloOptions_2));
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
else {
|
|
63
|
-
var _a =
|
|
64
|
+
var _a = optionsWithDefaultCache.log, log = _a === void 0 ? true : _a, apolloOptions_3 = __rest(optionsWithDefaultCache, ["log"]);
|
|
64
65
|
if (log) {
|
|
65
66
|
logger = Cypress.log({
|
|
66
67
|
autoEnd: false,
|
|
@@ -76,7 +77,13 @@ var apollo = function (apollo, options) {
|
|
|
76
77
|
});
|
|
77
78
|
}
|
|
78
79
|
cy.wrap({}, { log: false })
|
|
79
|
-
.then(function () { return (isQuery(
|
|
80
|
+
.then(function () { return (isQuery(optionsWithDefaultCache) ? apollo.query(optionsWithDefaultCache)["catch"](function (error) {
|
|
81
|
+
cy.log("Caught Graphql Query Error: " + JSON.stringify(error));
|
|
82
|
+
return error;
|
|
83
|
+
}) : apollo.mutate(optionsWithDefaultCache)["catch"](function (error) {
|
|
84
|
+
cy.log("Caught Graphql Mutation Error: " + JSON.stringify(error));
|
|
85
|
+
return error;
|
|
86
|
+
}))
|
|
80
87
|
.then(function (r) {
|
|
81
88
|
result = r;
|
|
82
89
|
logger === null || logger === void 0 ? void 0 : logger.end();
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.apolloClient = void 0;
|
|
5
5
|
var core_1 = require("@apollo/client/core");
|
|
6
|
+
var links_1 = require("./links");
|
|
6
7
|
var apolloClient = function (authMethod, options) {
|
|
7
8
|
if (options === void 0) { options = {
|
|
8
9
|
log: true,
|
|
@@ -18,11 +19,9 @@ var apolloClient = function (authMethod, options) {
|
|
|
18
19
|
else if (authMethod.username !== undefined && authMethod.password !== undefined) {
|
|
19
20
|
headers.authorization = "Basic " + btoa(authMethod.username + ':' + authMethod.password);
|
|
20
21
|
}
|
|
22
|
+
var links = [links_1.uploadLink, links_1.FormDataHttpLink(Cypress.config().baseUrl, headers)];
|
|
21
23
|
var client = new core_1.ApolloClient({
|
|
22
|
-
link:
|
|
23
|
-
uri: Cypress.config().baseUrl + "/modules/graphql",
|
|
24
|
-
headers: headers
|
|
25
|
-
}),
|
|
24
|
+
link: core_1.from(links),
|
|
26
25
|
cache: new core_1.InMemoryCache(),
|
|
27
26
|
defaultOptions: {
|
|
28
27
|
query: {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
exports.__esModule = true;
|
|
17
|
+
exports.uploadLink = exports.FormDataHttpLink = void 0;
|
|
18
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
19
|
+
var http_1 = require("@apollo/client/link/http");
|
|
20
|
+
var cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
21
|
+
var context_1 = require("@apollo/client/link/context");
|
|
22
|
+
var FormDataHttpLink = function (baseUrl, headers) {
|
|
23
|
+
return new http_1.HttpLink({
|
|
24
|
+
uri: baseUrl + "/modules/graphql",
|
|
25
|
+
headers: headers,
|
|
26
|
+
fetch: function (uri, fetcherOptions) {
|
|
27
|
+
var options = __assign({}, fetcherOptions);
|
|
28
|
+
if (options.formData) {
|
|
29
|
+
var formData_1 = options.formData;
|
|
30
|
+
var body_1 = JSON.parse(options.body.toString());
|
|
31
|
+
if (Array.isArray(body_1)) {
|
|
32
|
+
formData_1.append('query', options.body.toString());
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
Object.keys(body_1).forEach(function (k) {
|
|
36
|
+
return formData_1.append(k, typeof body_1[k] === 'string' ? body_1[k] : JSON.stringify(body_1[k]));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
fetcherOptions.body = formData_1;
|
|
40
|
+
delete fetcherOptions.headers['content-type'];
|
|
41
|
+
return cross_fetch_1["default"](uri, fetcherOptions);
|
|
42
|
+
}
|
|
43
|
+
return cross_fetch_1["default"](uri, fetcherOptions);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
exports.FormDataHttpLink = FormDataHttpLink;
|
|
48
|
+
exports.uploadLink = context_1.setContext(function (operation, _a) {
|
|
49
|
+
var fetchOptions = _a.fetchOptions;
|
|
50
|
+
var variables = operation.variables;
|
|
51
|
+
var fileFound = false;
|
|
52
|
+
var formData = new FormData();
|
|
53
|
+
var id = Math.random().toString(36);
|
|
54
|
+
// Search for File objects on the request and set it as formData
|
|
55
|
+
Object.keys(variables).forEach(function (k) {
|
|
56
|
+
var variable = variables[k];
|
|
57
|
+
if (variable instanceof File) {
|
|
58
|
+
formData.append(id, variable);
|
|
59
|
+
variables[k] = id;
|
|
60
|
+
fileFound = true;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (fileFound) {
|
|
64
|
+
return {
|
|
65
|
+
fetchOptions: __assign(__assign({}, fetchOptions), { formData: formData })
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return {
|
|
70
|
+
fetchOptions: __assign({}, fetchOptions)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
@@ -21,4 +21,4 @@ export declare type JahiaServer = {
|
|
|
21
21
|
username: string;
|
|
22
22
|
password: string;
|
|
23
23
|
};
|
|
24
|
-
export declare const runProvisioningScript: (script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer?: JahiaServer, options?: Cypress.Loggable) => void;
|
|
24
|
+
export declare const runProvisioningScript: (script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer?: JahiaServer, options?: Cypress.Loggable, timeout?: number) => void;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
|
|
3
2
|
exports.__esModule = true;
|
|
4
3
|
exports.runProvisioningScript = void 0;
|
|
5
|
-
/// <reference types="cypress" />
|
|
6
4
|
function processContent(formFile) {
|
|
7
5
|
var content = formFile.fileContent;
|
|
8
6
|
if (formFile.replacements) {
|
|
@@ -35,7 +33,7 @@ var serverDefaults = {
|
|
|
35
33
|
function isFormFile(script) {
|
|
36
34
|
return Boolean(script.fileContent || script.fileName);
|
|
37
35
|
}
|
|
38
|
-
var runProvisioningScript = function (script, files, jahiaServer, options) {
|
|
36
|
+
var runProvisioningScript = function (script, files, jahiaServer, options, timeout) {
|
|
39
37
|
if (jahiaServer === void 0) { jahiaServer = serverDefaults; }
|
|
40
38
|
if (options === void 0) { options = { log: true }; }
|
|
41
39
|
var formData = new FormData();
|
|
@@ -72,7 +70,7 @@ var runProvisioningScript = function (script, files, jahiaServer, options) {
|
|
|
72
70
|
}
|
|
73
71
|
});
|
|
74
72
|
}
|
|
75
|
-
|
|
73
|
+
var request = {
|
|
76
74
|
url: jahiaServer.url + "/modules/api/provisioning",
|
|
77
75
|
method: 'POST',
|
|
78
76
|
auth: {
|
|
@@ -82,7 +80,11 @@ var runProvisioningScript = function (script, files, jahiaServer, options) {
|
|
|
82
80
|
},
|
|
83
81
|
body: formData,
|
|
84
82
|
log: false
|
|
85
|
-
}
|
|
83
|
+
};
|
|
84
|
+
if (typeof timeout !== 'undefined') {
|
|
85
|
+
request.timeout = timeout;
|
|
86
|
+
}
|
|
87
|
+
cy.request(request).then(function (res) {
|
|
86
88
|
response = res;
|
|
87
89
|
expect(res.status, 'Script result').to.eq(200);
|
|
88
90
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jahia/cypress",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "tsc",
|
|
6
6
|
"lint": "eslint src -c .eslintrc.json --ext .ts"
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"cypress": "^8.3.1",
|
|
15
15
|
"eslint": "^7.32.0",
|
|
16
16
|
"eslint-plugin-cypress": "^2.11.3",
|
|
17
|
+
"cross-fetch": "^3.1.5",
|
|
17
18
|
"typescript": "^4.3.5"
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
@@ -38,22 +38,23 @@ export const apollo = function (apollo: ApolloClient<any>, options: ApolloOption
|
|
|
38
38
|
|
|
39
39
|
let result : ApolloQueryResult<any> | FetchResult
|
|
40
40
|
let logger : Cypress.Log
|
|
41
|
+
const optionsWithDefaultCache: ApolloOptions = {fetchPolicy: "no-cache", ...options}
|
|
41
42
|
|
|
42
43
|
if (!apollo) {
|
|
43
|
-
cy.apolloClient().apollo(
|
|
44
|
+
cy.apolloClient().apollo(optionsWithDefaultCache)
|
|
44
45
|
} else {
|
|
45
|
-
if (isQueryFile(
|
|
46
|
-
const {queryFile, ...apolloOptions} =
|
|
46
|
+
if (isQueryFile(optionsWithDefaultCache)) {
|
|
47
|
+
const {queryFile, ...apolloOptions} = optionsWithDefaultCache
|
|
47
48
|
cy.fixture(queryFile).then(content => {
|
|
48
49
|
cy.apollo({query: gql(content), ...apolloOptions})
|
|
49
50
|
})
|
|
50
|
-
} else if (isMutationFile(
|
|
51
|
-
const {mutationFile, ...apolloOptions} =
|
|
51
|
+
} else if (isMutationFile(optionsWithDefaultCache)) {
|
|
52
|
+
const {mutationFile, ...apolloOptions} = optionsWithDefaultCache
|
|
52
53
|
cy.fixture(mutationFile).then(content => {
|
|
53
54
|
cy.apollo({mutation: gql(content), ...apolloOptions})
|
|
54
55
|
})
|
|
55
56
|
} else {
|
|
56
|
-
const {log = true, ...apolloOptions} =
|
|
57
|
+
const {log = true, ...apolloOptions} = optionsWithDefaultCache
|
|
57
58
|
if (log) {
|
|
58
59
|
logger = Cypress.log({
|
|
59
60
|
autoEnd: false,
|
|
@@ -70,7 +71,13 @@ export const apollo = function (apollo: ApolloClient<any>, options: ApolloOption
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
cy.wrap({}, {log: false})
|
|
73
|
-
.then(() => (isQuery(
|
|
74
|
+
.then(() => (isQuery(optionsWithDefaultCache) ? apollo.query(optionsWithDefaultCache).catch(error => {
|
|
75
|
+
cy.log(`Caught Graphql Query Error: ${JSON.stringify(error)}`);
|
|
76
|
+
return error;
|
|
77
|
+
}) : apollo.mutate(optionsWithDefaultCache).catch(error => {
|
|
78
|
+
cy.log(`Caught Graphql Mutation Error: ${JSON.stringify(error)}`);
|
|
79
|
+
return error;
|
|
80
|
+
}))
|
|
74
81
|
.then(r => {
|
|
75
82
|
result = r
|
|
76
83
|
logger?.end()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
|
|
2
2
|
|
|
3
|
-
import {ApolloClient, HttpLink, InMemoryCache, NormalizedCacheObject} from '@apollo/client/core'
|
|
3
|
+
import {ApolloClient, from, HttpLink, InMemoryCache, NormalizedCacheObject} from '@apollo/client/core'
|
|
4
|
+
import {FormDataHttpLink, uploadLink} from './links'
|
|
4
5
|
|
|
5
6
|
interface AuthMethod {
|
|
6
7
|
token?: string
|
|
@@ -34,11 +35,10 @@ export const apolloClient = function (authMethod?: AuthMethod, options: ApolloCl
|
|
|
34
35
|
headers.authorization = `Basic ${btoa(authMethod.username + ':' + authMethod.password)}`
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
const links = [ uploadLink, FormDataHttpLink(Cypress.config().baseUrl, headers)]
|
|
39
|
+
|
|
37
40
|
const client = new ApolloClient({
|
|
38
|
-
link:
|
|
39
|
-
uri: `${Cypress.config().baseUrl}/modules/graphql`,
|
|
40
|
-
headers,
|
|
41
|
-
}),
|
|
41
|
+
link: from(links),
|
|
42
42
|
cache: new InMemoryCache(),
|
|
43
43
|
defaultOptions: {
|
|
44
44
|
query: {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
|
+
import { HttpLink } from '@apollo/client/link/http'
|
|
3
|
+
import fetch from 'cross-fetch'
|
|
4
|
+
import { setContext } from '@apollo/client/link/context'
|
|
5
|
+
|
|
6
|
+
interface ApolloRequestInit extends RequestInit {
|
|
7
|
+
formData?: FormData
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const FormDataHttpLink = (baseUrl: string, headers: Object) => {
|
|
11
|
+
return new HttpLink({
|
|
12
|
+
uri: `${baseUrl}/modules/graphql`,
|
|
13
|
+
headers,
|
|
14
|
+
fetch: (uri, fetcherOptions) => {
|
|
15
|
+
const options: ApolloRequestInit = { ...fetcherOptions }
|
|
16
|
+
if (options.formData) {
|
|
17
|
+
const formData = options.formData
|
|
18
|
+
const body = JSON.parse(options.body.toString())
|
|
19
|
+
if (Array.isArray(body)) {
|
|
20
|
+
formData.append('query', options.body.toString())
|
|
21
|
+
} else {
|
|
22
|
+
Object.keys(body).forEach((k) =>
|
|
23
|
+
formData.append(k, typeof body[k] === 'string' ? body[k] : JSON.stringify(body[k])),
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fetcherOptions.body = formData
|
|
28
|
+
delete fetcherOptions.headers['content-type']
|
|
29
|
+
return fetch(uri, fetcherOptions)
|
|
30
|
+
}
|
|
31
|
+
return fetch(uri, fetcherOptions)
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const uploadLink = setContext((operation, { fetchOptions }) => {
|
|
37
|
+
const { variables } = operation
|
|
38
|
+
let fileFound = false
|
|
39
|
+
const formData = new FormData()
|
|
40
|
+
const id = Math.random().toString(36)
|
|
41
|
+
// Search for File objects on the request and set it as formData
|
|
42
|
+
Object.keys(variables).forEach(function (k) {
|
|
43
|
+
const variable = variables[k]
|
|
44
|
+
if (variable instanceof File) {
|
|
45
|
+
formData.append(id, variable)
|
|
46
|
+
variables[k] = id
|
|
47
|
+
fileFound = true
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
if (fileFound) {
|
|
51
|
+
return {
|
|
52
|
+
fetchOptions: {
|
|
53
|
+
...fetchOptions,
|
|
54
|
+
formData: formData,
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
return {
|
|
59
|
+
fetchOptions: {
|
|
60
|
+
...fetchOptions,
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
|
|
2
|
+
import RequestOptions = Cypress.RequestOptions;
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
// Load type definitions that come with Cypress module
|
|
4
6
|
/// <reference types="cypress" />
|
|
@@ -64,7 +66,7 @@ function isFormFile(script: FormFile | StringDictionary[]): script is FormFile {
|
|
|
64
66
|
return Boolean((script as FormFile).fileContent || (script as FormFile).fileName);
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
export const runProvisioningScript = (script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer: JahiaServer = serverDefaults, options: Cypress.Loggable = {log:true}): void => {
|
|
69
|
+
export const runProvisioningScript = (script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer: JahiaServer = serverDefaults, options: Cypress.Loggable = {log:true}, timeout?: number): void => {
|
|
68
70
|
const formData = new FormData()
|
|
69
71
|
|
|
70
72
|
if (isFormFile(script)) {
|
|
@@ -103,7 +105,7 @@ export const runProvisioningScript = (script: FormFile | StringDictionary[], fil
|
|
|
103
105
|
})
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
const request: Partial<RequestOptions> = {
|
|
107
109
|
url: `${jahiaServer.url}/modules/api/provisioning`,
|
|
108
110
|
method: 'POST',
|
|
109
111
|
auth: {
|
|
@@ -113,7 +115,13 @@ export const runProvisioningScript = (script: FormFile | StringDictionary[], fil
|
|
|
113
115
|
},
|
|
114
116
|
body: formData,
|
|
115
117
|
log: false
|
|
116
|
-
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if(typeof timeout !== 'undefined'){
|
|
121
|
+
request.timeout = timeout
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
cy.request(request).then(res => {
|
|
117
125
|
response = res
|
|
118
126
|
expect(res.status, 'Script result').to.eq(200)
|
|
119
127
|
try {
|