@jahia/cypress 1.1.5 → 2.0.0

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/README.md CHANGED
@@ -82,9 +82,8 @@ Add typings in your tsconfig.json :
82
82
  ```
83
83
 
84
84
  This project provides a plugin for settings environment variable based on system env ( `JAHIA_URL` and `SUPER_USER_PASSWORD` )
85
- It also embeds `cypress-terminal-report` for better output.
86
85
 
87
- To set-up : in `plugins/index.js`, calls the module in `@jahia/cypress/dist/plugins/registerPlugins` :
86
+ Set up your plugins: in `plugins/index.js`, calls the module in `@jahia/cypress/dist/plugins/registerPlugins` :
88
87
 
89
88
  ```js
90
89
  module.exports = (on, config) => {
@@ -5,9 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  exports.__esModule = true;
6
6
  exports.registerPlugins = void 0;
7
7
  var env_1 = __importDefault(require("./env"));
8
- var installLogsPrinter_1 = __importDefault(require("cypress-terminal-report/src/installLogsPrinter"));
9
8
  var registerPlugins = function (on, config) {
10
9
  env_1["default"](on, config);
11
- installLogsPrinter_1["default"](on);
12
10
  };
13
11
  exports.registerPlugins = registerPlugins;
@@ -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: new core_1.HttpLink({
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,3 @@
1
+ import { HttpLink } from '@apollo/client/link/http';
2
+ export declare const FormDataHttpLink: (baseUrl: string, headers: Object) => HttpLink;
3
+ export declare const uploadLink: import("@apollo/client/core").ApolloLink;
@@ -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
+ });
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  exports.__esModule = true;
6
3
  exports.registerSupport = void 0;
7
4
  var apollo_1 = require("./apollo");
8
5
  var provisioning_1 = require("./provisioning");
9
6
  var login_1 = require("./login");
10
7
  var logout_1 = require("./logout");
11
- var installLogsCollector_1 = __importDefault(require("cypress-terminal-report/src/installLogsCollector"));
12
8
  var fixture_1 = require("./fixture");
13
9
  var repeatUntil_1 = require("./repeatUntil");
14
10
  var registerSupport = function () {
@@ -21,6 +17,5 @@ var registerSupport = function () {
21
17
  Cypress.Commands.add('logout', logout_1.logout);
22
18
  Cypress.Commands.add('repeatUntil', repeatUntil_1.repeatUntil);
23
19
  Cypress.Commands.overwrite('fixture', fixture_1.fixture);
24
- installLogsCollector_1["default"]();
25
20
  };
26
21
  exports.registerSupport = registerSupport;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahia/cypress",
3
- "version": "1.1.5",
3
+ "version": "2.0.0",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "lint": "eslint src -c .eslintrc.json --ext .ts"
@@ -11,14 +11,14 @@
11
11
  "devDependencies": {
12
12
  "@typescript-eslint/eslint-plugin": "^4.29.3",
13
13
  "@typescript-eslint/parser": "^4.29.3",
14
- "cypress": "^8.3.1",
14
+ "cypress": "^12.2.0",
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": {
20
21
  "@apollo/client": "^3.4.9",
21
- "cypress-terminal-report": "^3.4.2",
22
22
  "graphql": "^15.5.0",
23
23
  "graphql-tag": "^2.11.0"
24
24
  }
@@ -1,7 +1,5 @@
1
1
  import env from "./env"
2
- import installLogsPrinter from 'cypress-terminal-report/src/installLogsPrinter'
3
2
 
4
3
  export const registerPlugins = (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions): void => {
5
4
  env(on, config)
6
- installLogsPrinter(on)
7
5
  }
@@ -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: new HttpLink({
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
+ })
@@ -2,7 +2,6 @@ import {apollo, apolloClient} from "./apollo"
2
2
  import {executeGroovy, runProvisioningScript, installBundle} from "./provisioning"
3
3
  import {login} from "./login"
4
4
  import {logout} from "./logout"
5
- import installLogsCollector from 'cypress-terminal-report/src/installLogsCollector'
6
5
  import {fixture} from "./fixture";
7
6
  import {repeatUntil} from "./repeatUntil";
8
7
 
@@ -19,6 +18,4 @@ export const registerSupport = (): void => {
19
18
  Cypress.Commands.add('repeatUntil', repeatUntil)
20
19
 
21
20
  Cypress.Commands.overwrite('fixture', fixture)
22
-
23
- installLogsCollector()
24
21
  }