Skip to content

Commit

Permalink
Merge pull request #818 from opencb/TASK-4962
Browse files Browse the repository at this point in the history
TASK-4962 - Implement a testing system in jsorolla-enterprise
  • Loading branch information
jmjuanes authored Oct 11, 2023
2 parents 3bcfe77 + 5ece941 commit b2a4ab3
Show file tree
Hide file tree
Showing 28 changed files with 130 additions and 5,117 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ jobs:
cache: "npm"
cache-dependency-path: "package.json"
- run: npm install
- uses: actions/download-artifact@v3
with:
name: build-folder
path: build
- run: npm run test:prepare
- uses: cypress-io/github-action@v5
with:
start: npm run serve
start: npm run serve:build
command: npm run test:run
browser: chrome
wait-on: 'http://localhost:3000/src/sites/test-app/'
wait-on: 'http://localhost:4000/test-app/'
- uses: actions/upload-artifact@v3
if: always()
with:
Expand Down
8 changes: 3 additions & 5 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-undef */
const {defineConfig} = require("cypress");
const cypressSplit = require("cypress-split");

module.exports = defineConfig({
chromeWebSecurity: false,
Expand All @@ -19,11 +19,9 @@ module.exports = defineConfig({
json: true,
},
e2e: {
baseUrl: "http://localhost:3000/src/sites/test-app/",
setupNodeEvents(on, config) {
baseUrl: "http://localhost:4000/test-app/",
setupNodeEvents: on => {
require("cypress-mochawesome-reporter/plugin")(on);
cypressSplit(on, config);
return config;
},
defaultCommandTimeout: 12000
},
Expand Down
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
]
},
"scripts": {
"serve": "vite",
"serve": "npm run serve:dev",
"serve:dev": "vite",
"serve:build": "vite preview",
"clean": "rm -rf build",
"build": "npm run clean && rollup -c && npm run package",
"preview": "vite preview",
"prepare": "husky install",
"test:open": "cypress open",
"test:prepare": "./prepare-test.sh",
Expand All @@ -33,10 +34,6 @@
"package": "mv build iva-$npm_package_version && tar zcvf iva-$npm_package_version.tar.gz iva-$npm_package_version && mv iva-$npm_package_version build",
"eslint": "eslint -c .eslintrc.json . --ignore-pattern '/web_modules/'",
"lint:js": "lint-staged",
"e2e": "./cypress/credentials.sh npx cypress open --config-file ./cypress/cypress.config.js",
"e2e-win": "crypress/credentials.bat npx cypress open --config-file ./cypress/cypress.json",
"e2e-report": "./cypress/e2e-runner.sh",
"e2e-report-win": "cypress/e2e-runner.bat",
"graph": "./dependency-graph.sh"
},
"license": "Apache-2.0",
Expand Down Expand Up @@ -89,13 +86,13 @@
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-terser": "^0.4.3",
"@web/rollup-plugin-html": "^1.10.1",
"babel-eslint": "^10.0.3",
"core-js": "^3.17.2",
"crisper": "~2.1.1",
"cypress": "^12.4.0",
"cypress-mochawesome-reporter": "^3.2.3",
"cypress-split": "^1.2.0",
"cypress-wait-until": "^1.7.1",
"dependency-cruiser": "^10.0.7",
"eslint": "^7.29.0",
Expand All @@ -118,7 +115,6 @@
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-eslint": "^7.0.0",
"rollup-plugin-minify-html-literals": "^1.2.6",
"rollup-plugin-terser": "^7.0.2",
"uglify-es": "~3.1.9",
"uglify-js": "^3.14.2",
"uglifycss": "0.0.29",
Expand Down
23 changes: 3 additions & 20 deletions prepare-test.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
#!/usr/bin/env bash
## #!/bin/sh

## Download test data locally
# wget http://reports.test.zettagenomics.com/iva/tests/2.7
# -r recursive
# -np no parents
# -A extensions list to download file
# -P save file to prefix ...
# -nd no directory
# wget -r -np -A .json R "index.html" http://reports.test.zettagenomics.com/iva/tests/2.7/ -P src/sites/test-app/.data-test/ -nd

## Get version from package.json
VERSION=`npm version | grep jsorolla | cut -d : -f 2 | sed "s/[ ',]//g" | cut -d - -f 1 | cut -f 1,2 -d .`

# confirm if exist folder and file
FILE_TEST="src/sites/test-app/test-data/${VERSION}"
## FILE_TEST="src/sites/test-app/test-data/${VERSION}"
FILE_TEST="test-data/${VERSION}"
if [ ! -d "$FILE_TEST" ]; then
echo "create directory"
mkdir -v -p $FILE_TEST
mkdir -p $FILE_TEST
wget -r -np -A .json R "index.html" http://reports.test.zettagenomics.com/iva/test-data/${VERSION}/ -P "$FILE_TEST"/ -nd
exit 0;
# echo "testing wget output "
# >&2 echo "error test" $?
# # if [ $? -ne 0 ];
# # then echo "Message wget" $?
# # else echo "OK" $?
# # fi
fi

40 changes: 32 additions & 8 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fs from "fs";
import path from "path";
import del from "rollup-plugin-delete";
import {babel} from "@rollup/plugin-babel";
import {terser} from "rollup-plugin-terser";
import terser from "@rollup/plugin-terser";
import {execSync} from "child_process";
import pkg from "./package.json";

Expand All @@ -21,8 +21,16 @@ const patternConfig = /(config|settings|constants|tools)/gi;
const internalCss = /(global|magic-check|style|toggle-switch|genome-browser)/gi;

// Get target sites to build
// const sites = env.npm_config_sites ? env.npm_config_sites.split(",") : ["iva"];
const sites = ["iva", "api"];
const getSitesToBuild = () => {
// Josemi 2023-09-12 NOTE: test-app has been included by default in build process
const sites = ["iva", "api", "test-app"];
// Check if we need to include the test-app site in the sites to build list
// This can be enabled using the '--include-test-app' flag when running 'npm run build' command
// if (env.npm_config_include_test_app) {
// sites.push("test-app");
// }
return sites;
};

const revision = () => {
try {
Expand All @@ -48,7 +56,8 @@ const isInternalCss = name => {
};

const getCustomSitePath = (name, from, folder) => {
if (env.npm_config_custom_site) {
// NOTE: custom sites are not allowed for 'test-app'
if (env.npm_config_custom_site && name.toUpperCase() !== "TEST-APP") {
return `${from}custom-sites/${env.npm_config_custom_site}/${name}/${folder}`;
}
return folder; // Default path configuration
Expand All @@ -69,8 +78,9 @@ const getExtensionsPath = name => {

const transformHtmlContent = (html, name) => {
const annihilator = /<!-- build:delete -->[\s\S]*?<!-- \/build -->/mg;
const configRegex = new RegExp(`{{ ${name.toUpperCase()}_CONFIG_PATH }}`, "g");
const extensionsRegex = new RegExp(`{{ ${name.toUpperCase()}_EXTENSIONS_PATH }}`, "g");
const parsedName = name.replace(/-/g, "_").toUpperCase();
const configRegex = new RegExp(`{{ ${parsedName}_CONFIG_PATH }}`, "g");
const extensionsRegex = new RegExp(`{{ ${parsedName}_EXTENSIONS_PATH }}`, "g");

return html
.replace("[build-signature]", revision())
Expand Down Expand Up @@ -119,7 +129,7 @@ const getCopyTargets = site => {
return targets;
};

export default sites.map(site => ({
export default getSitesToBuild().map(site => ({
plugins: [
del({
targets: `build/${site}`,
Expand Down Expand Up @@ -173,7 +183,21 @@ export default sites.map(site => ({
},
output: {
dir: `${buildPath}/${site}`,
manualChunks: id => { // It's only detect "import" from script type=module.. the others no.
minifyInternalExports: false,
manualChunks: id => {
// Extract opencga client mock
if (id.includes("test-app/clients/opencga-client-mock") || id.includes("api-mock")) {
return "lib/opencga-client-mock.min";
}
// Extract cellbase client mock
if (id.includes("test-app/clients/cellbase-client-mock")) {
return "lib/cellbase-client-mock.min";
}
// Josemi 2023-09-19 NOTE: 'opencga-catalog-utils' is included inside the 'clients/opencga' folder
// We need to make sure this file is not included in the opencga client bundle
if (id.includes("clients/opencga") && !id.includes("opencga-catalog-utils")) {
return "lib/opencga-client.min";
}
if (id.includes("node_modules")) {
return "vendors/js/vendors";
}
Expand Down
81 changes: 1 addition & 80 deletions src/sites/test-app/clients/api-mock/Admin.js
Original file line number Diff line number Diff line change
@@ -1,116 +1,37 @@
/**
* Copyright 2015-2020 OpenCB
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* WARNING: AUTOGENERATED CODE
*
* This code was generated by a tool.
* Autogenerated on: 2022-08-11 16:30:01
*
* Manual changes to this file may cause unexpected behavior in your application.
* Manual changes to this file will be overwritten if the code is regenerated.
*
**/



/**
* This class contains the methods for the "Admin" resource
*/

export default class Admin {

constructor(config) {

this._config = config;
}

/** Group by operation
* @param {String} fields - Comma separated list of fields by which to group by.
* @param {"AUDIT USER PROJECT STUDY FILE SAMPLE JOB INDIVIDUAL COHORT DISEASE_PANEL FAMILY CLINICAL_ANALYSIS INTERPRETATION VARIANT
* ALIGNMENT CLINICAL EXPRESSION RGA FUNCTIONAL"} entity - Entity to be grouped by.
* @param {Object} [params] - The Object containing the following optional parameters:
* @param {Boolean} [params.count] - Count the number of elements matching the group.
* @param {Number} [params.limit = "50"] - Maximum number of documents (groups) to be returned. The default value is 50.
* @param {String} [params.action] - Action performed.
* @param {String} [params.before] - Object before update.
* @param {String} [params.after] - Object after update.
* @param {String} [params.date] - Date <,<=,>,>=(Format: yyyyMMddHHmmss) and yyyyMMddHHmmss-yyyyMMddHHmmss.
* @returns {Promise} Promise object in the form of RestResponse instance.
*/
groupByAudit(fields, entity, params) {
return this._get("admin", null, "audit", null, "groupBy", {fields, entity, ...params});
}

/** Sync Catalog into the Solr
* @param {Object} [params] - The Object containing the following optional parameters:
* @param {String} [params.collection] - Collection to be indexed (file, sample, individual, family, cohort and/or job). If not provided,
* all of them will be indexed.
* @returns {Promise} Promise object in the form of RestResponse instance.
*/
indexStatsCatalog(params) {
return this._post("admin", null, "catalog", null, "indexStats", params);
}

/** Install OpenCGA database
* @param {Object} data - JSON containing the mandatory parameters.
* @returns {Promise} Promise object in the form of RestResponse instance.
*/
installCatalog(data) {
return this._post("admin", null, "catalog", null, "install", data);
}

/** Change JWT secret key
* @param {Object} data - JSON containing the parameters.
* @returns {Promise} Promise object in the form of RestResponse instance.
*/
jwtCatalog(data) {
return this._post("admin", null, "catalog", null, "jwt", data);
}

/** Create a new user
* @param {Object} data - JSON containing the parameters.
* @returns {Promise} Promise object in the form of RestResponse instance.
*/
createUsers(data) {
return this._post("admin", null, "users", null, "create", data);
}

/** Import users or a group of users from LDAP or AAD
* @param {Object} data - JSON containing the parameters.
* @returns {Promise} Promise object in the form of RestResponse instance.
*/
importUsers(data) {
return this._post("admin", null, "users", null, "import", data);
}

/** User search method
* @param {Object} [params] - The Object containing the following optional parameters:
* @param {String} [params.include] - Fields included in the response, whole JSON path must be provided.
* @param {String} [params.exclude] - Fields excluded in the response, whole JSON path must be provided.
* @param {Number} [params.limit] - Number of results to be returned.
* @param {Number} [params.skip] - Number of results to skip.
* @param {Boolean} [params.count = "false"] - Get the total number of results matching the query. Deactivated by default. The default
* value is false.
* @param {String} [params.user] - User ID.
* @param {String} [params.account] - Account type [GUEST, FULL, ADMINISTRATOR].
* @param {String} [params.authenticationId] - Authentication origin ID.
* @returns {Promise} Promise object in the form of RestResponse instance.
*/
searchUsers(params) {
return this._get("admin", null, "users", null, "search", params);
}

/** Synchronise a group of users from an authentication origin with a group in a study from catalog
* @param {Object} data - JSON containing the parameters.
* @returns {Promise} Promise object in the form of RestResponse instance.
*/
syncUsers(data) {
return this._post("admin", null, "users", null, "sync", data);
}
Expand Down
Loading

0 comments on commit b2a4ab3

Please sign in to comment.