@jahia/cypress 3.13.0 → 3.14.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/ci.build.sh ADDED
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+ # This script can be used to manually build the docker images necessary to run the tests
3
+ # It should be executed from the tests folder
4
+
5
+ echo " ci.build.sh == Build test image"
6
+
7
+ BASEDIR=$(dirname $(readlink -f $0))
8
+
9
+ source $BASEDIR/set-env.sh
10
+
11
+ # It assumes that you previously built the module you're going to be testing
12
+ # and that the modules artifacts are located one level up
13
+
14
+ if [ ! -d ./artifacts ]; then
15
+ mkdir -p ./artifacts
16
+ fi
17
+
18
+ if [[ -e ../target ]]; then
19
+ cp ../target/*-SNAPSHOT.jar ./artifacts/
20
+ fi
21
+
22
+ if [ -d ./jahia-module ]; then
23
+ cd jahia-module
24
+ mvn clean install
25
+ cp target/*-SNAPSHOT.jar ../artifacts/
26
+ cd ..
27
+ fi
28
+
29
+
30
+ docker build -t ${TESTS_IMAGE} .
package/ci.startup.sh ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This script controls the startup of the container environment
4
+ # It can be used as an alternative to having docker-compose up started by the CI environment
5
+
6
+ BASEDIR=$(dirname $(readlink -f $0))
7
+
8
+ source $BASEDIR/set-env.sh
9
+
10
+ echo " ci.startup.sh == Printing the most important environment variables"
11
+ echo " MANIFEST: ${MANIFEST}"
12
+ echo " TESTS_IMAGE: ${TESTS_IMAGE}"
13
+ echo " JAHIA_IMAGE: ${JAHIA_IMAGE}"
14
+ echo " JAHIA_CLUSTER_ENABLED: ${JAHIA_CLUSTER_ENABLED}"
15
+
16
+ echo "$(date +'%d %B %Y - %k:%M') [LICENSE] == Check if license exists in env variable (JAHIA_LICENSE) =="
17
+ if [[ -z ${JAHIA_LICENSE} ]]; then
18
+ echo "$(date +'%d %B %Y - %k:%M') [LICENSE] == Jahia license does not exist, checking if there is a license file in /tmp/license.xml =="
19
+ if [[ -f /tmp/license.xml ]]; then
20
+ echo "$(date +'%d %B %Y - %k:%M') [LICENSE] == License found in /tmp/license.xml, base64ing it"
21
+ export JAHIA_LICENSE=$(base64 -i /tmp/license.xml)
22
+ else
23
+ echo "$(date +'%d %B %Y - %k:%M') [LICENSE] == STARTUP FAILURE, unable to find license =="
24
+ exit 1
25
+ fi
26
+ fi
27
+
28
+ echo "$(date +'%d %B %Y - %k:%M') == Cluster enabled: ${JAHIA_CLUSTER_ENABLED} =="
29
+ if [[ "${JAHIA_CLUSTER_ENABLED}" == "true" ]]; then
30
+ export CLUSTER_PROFILE="--profile cluster"
31
+ fi
32
+
33
+ echo "$(date +'%d %B %Y - %k:%M') == Starting environment =="
34
+ docker-compose up -d --renew-anon-volumes ${CLUSTER_PROFILE}
35
+ if [[ "$1" != "notests" ]]; then
36
+ docker ps -a
37
+ docker stats --no-stream
38
+ docker-compose up --abort-on-container-exit cypress
39
+ fi
@@ -1,5 +1,6 @@
1
1
  /// <reference types="cypress" />
2
2
  import Chainable = Cypress.Chainable;
3
+ import Chainer = Cypress.Chainer;
3
4
  export declare type ComponentType<Component> = {
4
5
  new (p: Chainable<JQuery>, assertion?: (s: JQuery) => void): Component;
5
6
  defaultSelector: string;
@@ -12,5 +13,5 @@ export declare class BaseComponent {
12
13
  assertion?: (s: JQuery) => void;
13
14
  constructor(element: Chainable<JQuery>, assertion?: (s: JQuery) => void);
14
15
  get(): Chainable<JQuery>;
15
- should(arg: any, ...others: any[]): Chainable<JQuery<HTMLElement>>;
16
+ should: Chainer<JQuery>;
16
17
  }
@@ -8,6 +8,15 @@ exports.__esModule = true;
8
8
  exports.BaseComponent = void 0;
9
9
  var BaseComponent = /** @class */ (function () {
10
10
  function BaseComponent(element, assertion) {
11
+ var _this = this;
12
+ this.should = function (arg) {
13
+ var _a;
14
+ var others = [];
15
+ for (var _i = 1; _i < arguments.length; _i++) {
16
+ others[_i - 1] = arguments[_i];
17
+ }
18
+ return (_a = cy.get('@component' + _this.id, { log: false })).should.apply(_a, __spreadArray([arg], others));
19
+ };
11
20
  this.id = BaseComponent.count++;
12
21
  this.element = element.as('component' + this.id);
13
22
  this.assertion = assertion;
@@ -18,15 +27,6 @@ var BaseComponent = /** @class */ (function () {
18
27
  }
19
28
  return cy.get('@component' + this.id, { log: false });
20
29
  };
21
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
22
- BaseComponent.prototype.should = function (arg) {
23
- var _a;
24
- var others = [];
25
- for (var _i = 1; _i < arguments.length; _i++) {
26
- others[_i - 1] = arguments[_i];
27
- }
28
- return (_a = cy.get('@component' + this.id, { log: false })).should.apply(_a, __spreadArray([arg], others));
29
- };
30
30
  BaseComponent.defaultSelector = '';
31
31
  BaseComponent.count = 0;
32
32
  return BaseComponent;
@@ -3,7 +3,9 @@ declare global {
3
3
  namespace Cypress {
4
4
  interface Chainable<Subject> {
5
5
  login(username?: string, password?: string): Chainable<Cypress.Response<any>>;
6
+ loginAndStoreSession(username?: string, password?: string): Chainable<Cypress.Response<any>>;
6
7
  }
7
8
  }
8
9
  }
9
10
  export declare const login: (username?: string, password?: string) => void;
11
+ export declare const loginAndStoreSession: (username?: string, password?: string) => void;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
3
3
  exports.__esModule = true;
4
- exports.login = void 0;
4
+ exports.loginAndStoreSession = exports.login = void 0;
5
5
  /// <reference types="cypress" />
6
6
  var login = function (username, password) {
7
7
  if (username === void 0) { username = 'root'; }
@@ -27,3 +27,15 @@ var login = function (username, password) {
27
27
  });
28
28
  };
29
29
  exports.login = login;
30
+ var loginAndStoreSession = function (username, password) {
31
+ if (username === void 0) { username = 'root'; }
32
+ if (password === void 0) { password = Cypress.env('SUPER_USER_PASSWORD'); }
33
+ cy.session('session-' + username, function () {
34
+ cy.login(username, password); // Edit in chief
35
+ }, {
36
+ validate: function () {
37
+ cy.request('/start').its('status').should('eq', 200);
38
+ }
39
+ });
40
+ };
41
+ exports.loginAndStoreSession = loginAndStoreSession;
package/env.debug.sh ADDED
@@ -0,0 +1,15 @@
1
+ #!/bin/bash
2
+ # This script can be used to warmup the environment and execute the tests
3
+ # It is used by the docker image at startup
4
+
5
+ BASEDIR=$(dirname $(readlink -f $0))
6
+
7
+ bash $BASEDIR/env.provision.sh
8
+
9
+ source $BASEDIR/set-env.sh
10
+
11
+ if [[ -z "${CYPRESS_CONFIGURATION_FILE}" ]]; then
12
+ CYPRESS_CONFIGURATION_FILE=cypress.config.ts
13
+ fi
14
+
15
+ yarn e2e:debug --config-file "${CYPRESS_CONFIGURATION_FILE}"
@@ -0,0 +1,92 @@
1
+ #!/bin/bash
2
+ # This script can be used to warmup the environment and execute the tests
3
+ # It is used by the docker image at startup
4
+
5
+ BASEDIR=$(dirname $(readlink -f $0))
6
+
7
+ source $BASEDIR/set-env.sh
8
+
9
+ #!/usr/bin/env bash
10
+ START_TIME=$SECONDS
11
+
12
+ echo "$(date +'%d %B %Y - %k:%M') == Printing the most important environment variables"
13
+ echo " MANIFEST: ${MANIFEST}"
14
+ echo " TESTS_IMAGE: ${TESTS_IMAGE}"
15
+ echo " JAHIA_IMAGE: ${JAHIA_IMAGE}"
16
+ echo " JAHIA_CLUSTER_ENABLED: ${JAHIA_CLUSTER_ENABLED}"
17
+ echo " MODULE_ID: ${MODULE_ID}"
18
+ echo " JAHIA_URL: ${JAHIA_URL}"
19
+ echo " JAHIA_HOST: ${JAHIA_HOST}"
20
+ echo " JAHIA_PORT: ${JAHIA_PORT}"
21
+ echo " JAHIA_USERNAME: ${JAHIA_USERNAME}"
22
+ echo " JAHIA_PASSWORD: ${JAHIA_PASSWORD}"
23
+ echo " JAHIA_USERNAME_TOOLS: ${JAHIA_USERNAME_TOOLS}"
24
+ echo " JAHIA_PASSWORD_TOOLS: ${JAHIA_PASSWORD_TOOLS}"
25
+ echo " SUPER_USER_PASSWORD: ${SUPER_USER_PASSWORD}"
26
+ echo " TIMEZONE: ${TIMEZONE}"
27
+ echo "$(date +'%d %B %Y - %k:%M') == Using Node version: $(node -v)"
28
+ echo "$(date +'%d %B %Y - %k:%M') == Using yarn version: $(yarn -v)"
29
+
30
+ echo "$(date +'%d %B %Y - %k:%M') == Waiting for Jahia to startup"
31
+
32
+ while [[ $(curl -s -o /dev/null -w ''%{http_code}'' ${JAHIA_URL}/cms/login) -ne 200 ]];
33
+ do
34
+ echo "$(date +'%d %B %Y - %k:%M') == Jahia is not available at ${JAHIA_URL}/cms/login, will try in 5 seconds"
35
+ ELAPSED_TIME=$(($SECONDS - $START_TIME))
36
+ if [[ ELAPSED_TIME -gt 300 ]]; then
37
+ echo "$(date +'%d %B %Y - %k:%M') == Exiting, Jahia failed to start after 300 seconds"
38
+ exit 1
39
+ fi
40
+ sleep 5;
41
+ done
42
+
43
+ ELAPSED_TIME=$(($SECONDS - $START_TIME))
44
+ echo "$(date +'%d %B %Y - %k:%M') == Jahia became alive in ${ELAPSED_TIME} seconds"
45
+
46
+ mkdir -p ./run-artifacts
47
+ mkdir -p ./results
48
+
49
+ # Copy manifest file
50
+ # If the file doesn't exist, we assume it is a URL and we download it locally
51
+ if [[ -e ${MANIFEST} ]]; then
52
+ cp ${MANIFEST} ./run-artifacts
53
+ else
54
+ echo "$(date +'%d %B %Y - %k:%M') == Downloading: ${MANIFEST}"
55
+ curl ${MANIFEST} --output ./run-artifacts/curl-manifest
56
+ MANIFEST="curl-manifest"
57
+ fi
58
+
59
+ echo "$(date +'%d %B %Y - %k:%M') == Executing manifest: ${MANIFEST} =="
60
+ curl -u root:${SUPER_USER_PASSWORD} -X POST ${JAHIA_URL}/modules/api/provisioning --form script="@./run-artifacts/${MANIFEST};type=text/yaml" $(find assets -type f | sed -E 's/^(.+)$/--form file=\"@\1\"/' | xargs)
61
+ echo
62
+ if [[ $? -eq 1 ]]; then
63
+ echo "$(date +'%d %B %Y - %k:%M') == PROVISIONING FAILURE - EXITING SCRIPT, NOT RUNNING THE TESTS"
64
+ echo "failure" > ./results/test_failure
65
+ exit 1
66
+ fi
67
+
68
+ if [[ -d artifacts/ ]]; then
69
+ cd artifacts/
70
+ echo "$(date +'%d %B %Y - %k:%M') == Content of the artifacts/ folder"
71
+ ls -lah
72
+ echo "$(date +'%d %B %Y - %k:%M') [MODULE_INSTALL] == Will start submitting files"
73
+ for file in $(ls -1 *-SNAPSHOT.jar | sort -n)
74
+ do
75
+ echo "$(date +'%d %B %Y - %k:%M') [MODULE_INSTALL] == Submitting module from: $file =="
76
+ curl -u root:${SUPER_USER_PASSWORD} -X POST ${JAHIA_URL}/modules/api/provisioning --form script='[{"installAndStartBundle":"'"$file"'", "forceUpdate":true}]' --form file=@$file
77
+ echo
78
+ echo "$(date +'%d %B %Y - %k:%M') [MODULE_INSTALL] == Module submitted =="
79
+ done
80
+ cd ..
81
+ fi
82
+
83
+ if [[ -d scripts/ ]]; then
84
+ cd ./scripts
85
+ for file in $(ls -1 script-* | sort -n)
86
+ do
87
+ echo "$(date +'%d %B %Y - %k:%M') [SCRIPT] == Submitting script: $file =="
88
+ curl -u root:${SUPER_USER_PASSWORD} -X POST ${JAHIA_URL}/modules/api/provisioning --form script='[{"executeScript":"'"$file"'"}]' --form file=@$file
89
+ echo "$(date +'%d %B %Y - %k:%M') [SCRIPT] == Script executed =="
90
+ done
91
+ cd ..
92
+ fi
package/env.run.sh ADDED
@@ -0,0 +1,49 @@
1
+ #!/bin/bash
2
+ # This script can be used to warmup the environment and execute the tests
3
+ # It is used by the docker image at startup
4
+
5
+ BASEDIR=$(dirname $(readlink -f $0))
6
+
7
+ bash $BASEDIR/env.provision.sh
8
+
9
+ source $BASEDIR/set-env.sh
10
+
11
+ echo "$(date +'%d %B %Y - %k:%M') == Fetching the list of installed modules =="
12
+ npx --yes @jahia/jahia-reporter@latest utils:modules \
13
+ --moduleId="${MODULE_ID}" \
14
+ --jahiaUrl="${JAHIA_URL}" \
15
+ --jahiaPassword="${SUPER_USER_PASSWORD}" \
16
+ --filepath="results/installed-jahia-modules.json"
17
+ echo "$(date +'%d %B %Y - %k:%M') == Modules fetched =="
18
+ INSTALLED_MODULE_VERSION=$(cat results/installed-jahia-modules.json | jq '.module.version')
19
+ if [[ $INSTALLED_MODULE_VERSION == "UNKNOWN" ]]; then
20
+ echo "$(date +'%d %B %Y - %k:%M') ERROR: Unable to detect module: ${MODULE_ID} on the remote system "
21
+ echo "$(date +'%d %B %Y - %k:%M') ERROR: The Script will exit"
22
+ echo "$(date +'%d %B %Y - %k:%M') ERROR: Tests will NOT run"
23
+ echo "failure" > ./results/test_failure
24
+ exit 1
25
+ fi
26
+
27
+ echo "$(date +'%d %B %Y - %k:%M') == Run tests =="
28
+ mkdir -p ./results/reports
29
+ rm -rf ./results/reports
30
+
31
+ if [[ -z "${CYPRESS_CONFIGURATION_FILE}" ]]; then
32
+ CYPRESS_CONFIGURATION_FILE=cypress.config.ts
33
+ fi
34
+
35
+ echo "$(date +'%d %B %Y - %k:%M') == Running Cypress with configuration file ${CYPRESS_CONFIGURATION_FILE} =="
36
+
37
+ yarn e2e:ci --config-file "${CYPRESS_CONFIGURATION_FILE}"
38
+
39
+ if [[ $? -eq 0 ]]; then
40
+ echo "$(date +'%d %B %Y - %k:%M') == Full execution successful =="
41
+ echo "success" > ./results/test_success
42
+ yarn report:merge; yarn report:html
43
+ exit 0
44
+ else
45
+ echo "$(date +'%d %B %Y - %k:%M') == One or more failed tests =="
46
+ echo "failure" > ./results/test_failure
47
+ yarn report:merge; yarn report:html
48
+ exit 1
49
+ fi
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "@jahia/cypress",
3
- "version": "3.13.0",
3
+ "version": "3.14.1",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "lint": "eslint src -c .eslintrc.json --ext .ts"
7
7
  },
8
+ "bin": {
9
+ "ci.build": "./ci.build.sh",
10
+ "ci.startup": "./ci.startup.sh",
11
+ "env.run": "./env.run.sh",
12
+ "env.debug": "./env.debug.sh"
13
+ },
8
14
  "main": "dist/index.js",
9
15
  "types": "dist/index.d.ts",
10
16
  "license": "MIT",
package/set-env.sh ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+
3
+ if [[ -f .env ]]; then
4
+ source .env
5
+ export $(cat .env | sed 's/=.*//g'| xargs)
6
+ else
7
+ source .env.example
8
+ export $(cat .env.example | sed 's/=.*//g'| xargs)
9
+ fi
package/src/custom.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  interface String {
2
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
- replaceAll(input: string, output : string): any;
2
+ replaceAll(input: string, output : string): string;
4
3
  }
@@ -1,4 +1,5 @@
1
1
  import Chainable = Cypress.Chainable;
2
+ import Chainer = Cypress.Chainer;
2
3
 
3
4
  export type ComponentType<Component> = { new(p: Chainable<JQuery>, assertion?: (s: JQuery) => void): Component, defaultSelector: string };
4
5
 
@@ -24,8 +25,7 @@ export class BaseComponent {
24
25
  return cy.get('@component' + this.id, {log: false});
25
26
  }
26
27
 
27
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
28
- should(arg, ...others) {
28
+ should: Chainer<JQuery> = (arg, ...others) => {
29
29
  return cy.get('@component' + this.id, {log: false}).should(arg, ...others);
30
30
  }
31
31
  }
@@ -8,6 +8,7 @@ declare global {
8
8
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
9
  interface Chainable<Subject> {
10
10
  login(username?: string, password?: string): Chainable<Cypress.Response<any>>
11
+ loginAndStoreSession(username?: string, password?: string): Chainable<Cypress.Response<any>>
11
12
  }
12
13
  }
13
14
  }
@@ -35,3 +36,12 @@ export const login = (username = 'root', password: string = Cypress.env('SUPER_U
35
36
  });
36
37
  };
37
38
 
39
+ export const loginAndStoreSession = (username = 'root', password: string = Cypress.env('SUPER_USER_PASSWORD')): void => {
40
+ cy.session('session-' + username, () => {
41
+ cy.login(username, password); // Edit in chief
42
+ }, {
43
+ validate() {
44
+ cy.request('/start').its('status').should('eq', 200);
45
+ }
46
+ });
47
+ };