@jahia/cypress 1.1.4 → 1.1.5

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.
@@ -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(options);
48
+ cy.apolloClient().apollo(optionsWithDefaultCache);
48
49
  }
49
50
  else {
50
- if (isQueryFile(options)) {
51
- var queryFile = options.queryFile, apolloOptions_1 = __rest(options, ["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(options)) {
57
- var mutationFile = options.mutationFile, apolloOptions_2 = __rest(options, ["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 = options.log, log = _a === void 0 ? true : _a, apolloOptions_3 = __rest(options, ["log"]);
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(options) ? apollo.query(options) : apollo.mutate(options))
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();
@@ -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
- cy.request({
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
- }).then(function (res) {
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.4",
3
+ "version": "1.1.5",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "lint": "eslint src -c .eslintrc.json --ext .ts"
@@ -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(options)
44
+ cy.apolloClient().apollo(optionsWithDefaultCache)
44
45
  } else {
45
- if (isQueryFile(options)) {
46
- const {queryFile, ...apolloOptions} = options
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(options)) {
51
- const {mutationFile, ...apolloOptions} = options
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} = options
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(options) ? apollo.query(options) : apollo.mutate(options))
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,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
- cy.request({
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
- }).then(res => {
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 {