From be35e1fcb876b633bbe771c3bf31ffeb9162693d Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Wed, 8 Jan 2025 16:24:26 +0100 Subject: [PATCH 01/13] test: first commit to add cypress tests to github actions --- .github/workflows/main.yml | 11 ++++++++++- commitlint.config.js | 2 +- cypress.config.js | 9 +++++++++ cypress/e2e/spec.cy.js | 5 +++++ cypress/fixtures/example.json | 5 +++++ cypress/support/commands.ts | 37 +++++++++++++++++++++++++++++++++++ cypress/support/e2e.ts | 17 ++++++++++++++++ cypress/support/tsconfig.json | 8 ++++++++ package.json | 3 +++ 9 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 cypress.config.js create mode 100644 cypress/e2e/spec.cy.js create mode 100644 cypress/fixtures/example.json create mode 100644 cypress/support/commands.ts create mode 100644 cypress/support/e2e.ts create mode 100644 cypress/support/tsconfig.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0f87cc216..2b34fb712a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -159,4 +159,13 @@ jobs: uses: sonarsource/sonarcloud-github-action@v3.1.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + cypress-run: + needs: npm-build + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Cypress run + uses: cypress-io/github-action@v6 \ No newline at end of file diff --git a/commitlint.config.js b/commitlint.config.js index 080384a0a6..17047d8c90 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,4 +1,4 @@ -import { RuleConfigSeverity } from "@commitlint/types"; +import { RuleConfigSeverity } from "@commitlint/typSans titrees"; // Config used by 'commitlint' GitHub action. export default { diff --git a/cypress.config.js b/cypress.config.js new file mode 100644 index 0000000000..17161e32e0 --- /dev/null +++ b/cypress.config.js @@ -0,0 +1,9 @@ +import { defineConfig } from "cypress"; + +export default defineConfig({ + e2e: { + setupNodeEvents(on, config) { + // implement node event listeners here + }, + }, +}); diff --git a/cypress/e2e/spec.cy.js b/cypress/e2e/spec.cy.js new file mode 100644 index 0000000000..322992ce19 --- /dev/null +++ b/cypress/e2e/spec.cy.js @@ -0,0 +1,5 @@ +describe('template spec', () => { + it('passes', () => { + cy.visit('https://example.cypress.io') + }) +}) \ No newline at end of file diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 0000000000..02e4254378 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts new file mode 100644 index 0000000000..698b01a42c --- /dev/null +++ b/cypress/support/commands.ts @@ -0,0 +1,37 @@ +/// +// *********************************************** +// This example commands.ts shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add('login', (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This will overwrite an existing command -- +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +// +// declare global { +// namespace Cypress { +// interface Chainable { +// login(email: string, password: string): Chainable +// drag(subject: string, options?: Partial): Chainable +// dismiss(subject: string, options?: Partial): Chainable +// visit(originalFn: CommandOriginalFn, url: string, options: Partial): Chainable +// } +// } +// } \ No newline at end of file diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts new file mode 100644 index 0000000000..e4e246ec99 --- /dev/null +++ b/cypress/support/e2e.ts @@ -0,0 +1,17 @@ +// *********************************************************** +// This example support/e2e.ts is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands' \ No newline at end of file diff --git a/cypress/support/tsconfig.json b/cypress/support/tsconfig.json new file mode 100644 index 0000000000..83fb87e55f --- /dev/null +++ b/cypress/support/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": ["es5", "dom"], + "types": ["cypress", "node"] + }, + "include": ["**/*.ts"] +} \ No newline at end of file diff --git a/package.json b/package.json index affe100a23..8def5eed6c 100644 --- a/package.json +++ b/package.json @@ -3,5 +3,8 @@ "devDependencies": { "@commitlint/cli": "^19.2.1", "@commitlint/config-conventional": "^19.1.0" + }, + "dependencies": { + "cypress": "^13.17.0" } } From b8ca9234ef9c79f2b589262a15638434615be889 Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Wed, 8 Jan 2025 16:30:26 +0100 Subject: [PATCH 02/13] test: first commit to add cypress tests to github actions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2b34fb712a..8f95574b38 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -163,7 +163,7 @@ jobs: cypress-run: needs: npm-build - runs-on: ubuntu-24.04 + runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v4 From 5a3d727d351ce3604a61bde2d40cea59a0496e09 Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Wed, 8 Jan 2025 16:31:59 +0100 Subject: [PATCH 03/13] test: first commit to add cypress tests to github actions --- .github/workflows/main.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8f95574b38..c0f87cc216 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -159,13 +159,4 @@ jobs: uses: sonarsource/sonarcloud-github-action@v3.1.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - cypress-run: - needs: npm-build - runs-on: ubuntu-20.04 - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Cypress run - uses: cypress-io/github-action@v6 \ No newline at end of file + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file From 619f532fea2c93eb7e57a14811973691015759bb Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Wed, 8 Jan 2025 16:45:01 +0100 Subject: [PATCH 04/13] test: first commit to add cypress tests to github actions --- commitlint.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitlint.config.js b/commitlint.config.js index 17047d8c90..080384a0a6 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,4 +1,4 @@ -import { RuleConfigSeverity } from "@commitlint/typSans titrees"; +import { RuleConfigSeverity } from "@commitlint/types"; // Config used by 'commitlint' GitHub action. export default { From a15fdeaee943b00f3b9363f1a3c165278b5a2e16 Mon Sep 17 00:00:00 2001 From: MartinBelthle Date: Thu, 9 Jan 2025 09:51:08 +0100 Subject: [PATCH 05/13] fix(matrix): remove columns full of `NaN` inside matrices at the import (#2287) --- antarest/study/service.py | 1 + .../raw_studies_blueprint/test_fetch_raw_data.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/antarest/study/service.py b/antarest/study/service.py index d394056f95..a0b447bf20 100644 --- a/antarest/study/service.py +++ b/antarest/study/service.py @@ -1600,6 +1600,7 @@ def _create_edit_study_command( # Can happen with data with only one column. In this case, we don't care about the delimiter. delimiter = "\t" df = pd.read_csv(io.BytesIO(data), delimiter=delimiter, header=None).replace(",", ".", regex=True) + df = df.dropna(axis=1, how="all") # We want to remove columns full of NaN at the import matrix = df.to_numpy(dtype=np.float64) matrix = matrix.reshape((1, 0)) if matrix.size == 0 else matrix return ReplaceMatrix( diff --git a/tests/integration/raw_studies_blueprint/test_fetch_raw_data.py b/tests/integration/raw_studies_blueprint/test_fetch_raw_data.py index e30e929a0b..967a43b6f1 100644 --- a/tests/integration/raw_studies_blueprint/test_fetch_raw_data.py +++ b/tests/integration/raw_studies_blueprint/test_fetch_raw_data.py @@ -212,18 +212,20 @@ def test_get_study_data(self, client: TestClient, user_access_token: str, intern b"\xef\xbb\xbf1;1;1;1;1\r\n1;1;1;1;1", b"1;1;1;1;1\r1;1;1;1;1", b"0,000000;0,000000;0,000000;0,000000\n0,000000;0,000000;0,000000;0,000000", + b"1;2;3;;;\n4;5;6;;;\n", ], - ["\t", "\t", ",", "\t", ";", ";", ";"], + ["\t", "\t", ",", "\t", ";", ";", ";", ";"], ): res = client.put(raw_url, params={"path": matrix_path}, files={"file": io.BytesIO(content)}) assert res.status_code == 204, res.json() res = client.get(raw_url, params={"path": matrix_path}) written_data = res.json()["data"] if not content.decode("utf-8"): - # For some reason the `GET` returns the default matrix when it's empty + # The `GET` returns the default matrix when it's empty expected = 8760 * [[0]] if study_type == "raw" else [[]] else: df = pd.read_csv(io.BytesIO(content), delimiter=delimiter, header=None).replace(",", ".", regex=True) + df = df.dropna(axis=1, how="all") # We want to remove columns full of NaN at the import expected = df.to_numpy(dtype=np.float64).tolist() assert written_data == expected From 33084fdfe05148faa0805f14f51f15ffded0bf8f Mon Sep 17 00:00:00 2001 From: MartinBelthle Date: Thu, 9 Jan 2025 10:39:59 +0100 Subject: [PATCH 06/13] fix(matrix): return default empty matrix even when called with formatted=False (#2286) --- .../filesystem/matrix/input_series_matrix.py | 4 + .../model/filesystem/matrix/matrix.py | 26 ++++- tests/storage/integration/test_STA_mini.py | 97 +++++++------------ .../filesystem/matrix/test_matrix_node.py | 5 + 4 files changed, 68 insertions(+), 64 deletions(-) diff --git a/antarest/study/storage/rawstudy/model/filesystem/matrix/input_series_matrix.py b/antarest/study/storage/rawstudy/model/filesystem/matrix/input_series_matrix.py index d2ac83c19c..e23cb9842a 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/matrix/input_series_matrix.py +++ b/antarest/study/storage/rawstudy/model/filesystem/matrix/input_series_matrix.py @@ -150,3 +150,7 @@ def get_file_content(self) -> OriginalFile: else: content = self.config.path.read_bytes() return OriginalFile(content=content, suffix=suffix, filename=filename) + + @override + def get_default_empty_matrix(self) -> t.Optional[npt.NDArray[np.float64]]: + return self.default_empty diff --git a/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py b/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py index 7897715f92..6009fef526 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py +++ b/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py @@ -16,7 +16,9 @@ from pathlib import Path from typing import List, Optional, Union, cast +import numpy as np import pandas as pd +from numpy import typing as npt from typing_extensions import override from antarest.core.model import JSON @@ -127,16 +129,25 @@ def load( formatted: bool = True, ) -> Union[bytes, JSON]: file_path, tmp_dir = self._get_real_file_path() - if not formatted: - if file_path.exists(): - return file_path.read_bytes() + if formatted: + return self.parse_as_json(file_path) + + if not file_path.exists(): logger.warning(f"Missing file {self.config.path}") if tmp_dir: tmp_dir.cleanup() return b"" - return self.parse_as_json(file_path) + file_content = file_path.read_bytes() + if file_content != b"": + return file_content + + # If the content is empty, we should return the default matrix to do the same as `parse_as_json()` + default_matrix = self.get_default_empty_matrix() + if default_matrix is None: + return b"" + return default_matrix.tobytes() @abstractmethod def parse_as_json(self, file_path: Optional[Path] = None) -> JSON: @@ -145,6 +156,13 @@ def parse_as_json(self, file_path: Optional[Path] = None) -> JSON: """ raise NotImplementedError() + @abstractmethod + def get_default_empty_matrix(self) -> Optional[npt.NDArray[np.float64]]: + """ + Returns the default matrix to return when the existing one is empty + """ + raise NotImplementedError() + @override def dump( self, diff --git a/tests/storage/integration/test_STA_mini.py b/tests/storage/integration/test_STA_mini.py index 7b1c1ee690..a7b36555e8 100644 --- a/tests/storage/integration/test_STA_mini.py +++ b/tests/storage/integration/test_STA_mini.py @@ -18,6 +18,7 @@ from typing import Union from unittest.mock import Mock +import numpy as np import pytest from fastapi import FastAPI from starlette.testclient import TestClient @@ -172,12 +173,9 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str) @pytest.mark.integration_test @pytest.mark.parametrize( - "url, expected_output", + "url, expected_output, formatted", [ - ( - f"/v1/studies/{UUID}/raw?path=input/bindingconstraints/bindingconstraints", - {}, - ), + (f"/v1/studies/{UUID}/raw?path=input/bindingconstraints/bindingconstraints", {}, True), ( f"/v1/studies/{UUID}/raw?path=input/hydro/series/de/mod", { @@ -185,24 +183,17 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str) "index": list(range(365)), "data": [[0.0]] * 365, }, + True, ), - ( - f"/v1/studies/{UUID}/raw?path=input/areas/list", - ["DE", "ES", "FR", "IT"], - ), - ( - f"/v1/studies/{UUID}/raw?path=input/areas/sets/all areas/output", - False, - ), + (f"/v1/studies/{UUID}/raw?path=input/areas/list", ["DE", "ES", "FR", "IT"], True), + (f"/v1/studies/{UUID}/raw?path=input/areas/sets/all areas/output", False, True), ( f"/v1/studies/{UUID}/raw?path=input/areas/de/optimization/nodal optimization/spread-spilled-energy-cost", 0, + True, ), - (f"/v1/studies/{UUID}/raw?path=input/areas/de/ui/layerX/0", 1), - ( - f"/v1/studies/{UUID}/raw?path=input/hydro/allocation/de/[allocation]/de", - 1, - ), + (f"/v1/studies/{UUID}/raw?path=input/areas/de/ui/layerX/0", 1, True), + (f"/v1/studies/{UUID}/raw?path=input/hydro/allocation/de/[allocation]/de", 1, True), ( f"/v1/studies/{UUID}/raw?path=input/hydro/common/capacity/reservoir_fr", { @@ -210,6 +201,7 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str) "index": list(range(365)), "data": [[0, 0.5, 1]] * 365, }, + True, ), ( f"/v1/studies/{UUID}/raw?path=input/thermal/series/fr/05_nuclear/series", @@ -218,35 +210,19 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str) "index": list(range(8760)), "data": [[2000]] * 8760, }, + True, ), - ( - f"/v1/studies/{UUID}/raw?path=input/hydro/prepro/correlation/general/mode", - "annual", - ), - ( - f"/v1/studies/{UUID}/raw?path=input/hydro/prepro/fr/prepro/prepro/intermonthly-correlation", - 0.5, - ), + (f"/v1/studies/{UUID}/raw?path=input/hydro/prepro/correlation/general/mode", "annual", True), + (f"/v1/studies/{UUID}/raw?path=input/hydro/prepro/fr/prepro/prepro/intermonthly-correlation", 0.5, True), ( f"/v1/studies/{UUID}/raw?path=input/hydro/prepro/fr/energy", {"data": [[]], "index": [0], "columns": []}, - ), - ( - f"/v1/studies/{UUID}/raw?path=input/hydro/hydro/inter-monthly-breakdown/fr", - 1, - ), - ( - f"/v1/studies/{UUID}/raw?path=input/thermal/areas/unserverdenergycost/de", - 3000.0, - ), - ( - f"/v1/studies/{UUID}/raw?path=input/thermal/clusters/fr/list/05_nuclear/marginal-cost", - 50, - ), - ( - f"/v1/studies/{UUID}/raw?path=input/links/fr/properties/it/hurdles-cost", True, ), + (f"/v1/studies/{UUID}/raw?path=input/hydro/hydro/inter-monthly-breakdown/fr", 1, True), + (f"/v1/studies/{UUID}/raw?path=input/thermal/areas/unserverdenergycost/de", 3000.0, True), + (f"/v1/studies/{UUID}/raw?path=input/thermal/clusters/fr/list/05_nuclear/marginal-cost", 50, True), + (f"/v1/studies/{UUID}/raw?path=input/links/fr/properties/it/hurdles-cost", True, True), ( f"/v1/studies/{UUID}/raw?path=input/links/fr/it", { @@ -254,11 +230,9 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str) "index": list(range(8760)), "data": [[100000, 100000, 0.01, 0.01, 0, 0, 0, 0]] * 8760, }, + True, ), - ( - f"/v1/studies/{UUID}/raw?path=input/load/prepro/fr/k", - {"data": [[]], "index": [0], "columns": []}, - ), + (f"/v1/studies/{UUID}/raw?path=input/load/prepro/fr/k", {"data": [[]], "index": [0], "columns": []}, True), ( f"/v1/studies/{UUID}/raw?path=input/load/series", { @@ -267,6 +241,7 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str) "load_fr": "matrixfile://load_fr.txt", "load_it": "matrixfile://load_it.txt", }, + True, ), ( f"/v1/studies/{UUID}/raw?path=input/load/series/load_fr", @@ -275,14 +250,23 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str) "index": list(range(8760)), "data": [[i % 168 * 100] for i in range(8760)], }, + True, ), - ( + pytest.param( f"/v1/studies/{UUID}/raw?path=input/misc-gen/miscgen-fr", { "columns": [0, 1, 2, 3, 4, 5, 6, 7], "index": list(range(8760)), "data": [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]] * 8760, }, + True, + id="empty_matrix_formatted", + ), + pytest.param( + f"/v1/studies/{UUID}/raw?path=input/misc-gen/miscgen-fr", + np.array([[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]] * 8760).tobytes(), + False, + id="empty_matrix_unformatted", ), ( f"/v1/studies/{UUID}/raw?path=input/reserves/fr", @@ -291,11 +275,9 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str) "index": list(range(8760)), "data": [[0.0]] * 8760, }, + True, ), - ( - f"/v1/studies/{UUID}/raw?path=input/solar/prepro/fr/k", - {"data": [[]], "index": [0], "columns": []}, - ), + (f"/v1/studies/{UUID}/raw?path=input/solar/prepro/fr/k", {"data": [[]], "index": [0], "columns": []}, True), ( f"/v1/studies/{UUID}/raw?path=input/solar/series/solar_fr", { @@ -303,11 +285,9 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str) "index": list(range(8760)), "data": [[0.0]] * 8760, }, + True, ), - ( - f"/v1/studies/{UUID}/raw?path=input/wind/prepro/fr/k", - {"data": [[]], "index": [0], "columns": []}, - ), + (f"/v1/studies/{UUID}/raw?path=input/wind/prepro/fr/k", {"data": [[]], "index": [0], "columns": []}, True), ( f"/v1/studies/{UUID}/raw?path=input/wind/series/wind_fr", { @@ -315,15 +295,12 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str) "index": list(range(8760)), "data": [[0.0]] * 8760, }, + True, ), ], ) -def test_sta_mini_input(storage_service, url: str, expected_output: dict): - assert_with_errors( - storage_service=storage_service, - url=url, - expected_output=expected_output, - ) +def test_sta_mini_input(storage_service, url: str, expected_output: dict, formatted: bool): + assert_with_errors(storage_service=storage_service, url=url, expected_output=expected_output, formatted=formatted) @pytest.mark.integration_test diff --git a/tests/storage/repository/filesystem/matrix/test_matrix_node.py b/tests/storage/repository/filesystem/matrix/test_matrix_node.py index 38dce45486..936a54b6ea 100644 --- a/tests/storage/repository/filesystem/matrix/test_matrix_node.py +++ b/tests/storage/repository/filesystem/matrix/test_matrix_node.py @@ -14,7 +14,9 @@ from typing import List, Optional from unittest.mock import Mock +import numpy as np import pandas as pd # type: ignore +from numpy import typing as npt from antarest.core.model import JSON from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig @@ -41,6 +43,9 @@ def __init__(self, context: ContextServer, config: FileStudyTreeConfig) -> None: def parse_as_json(self, file_path: Optional[Path] = None) -> JSON: return MOCK_MATRIX_JSON + def get_default_empty_matrix(self) -> Optional[npt.NDArray[np.float64]]: + pass + def check_errors(self, data: str, url: Optional[List[str]] = None, raising: bool = False) -> List[str]: pass # not used From 7173b741836c4bb0182922e08ecfce19dea43c63 Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Thu, 9 Jan 2025 13:42:03 +0100 Subject: [PATCH 07/13] test: first commit to add cypress tests to github actions --- .github/workflows/main.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0f87cc216..4a6a2d5cbc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -159,4 +159,14 @@ jobs: uses: sonarsource/sonarcloud-github-action@v3.1.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + + cypress-run: + needs: npm-build + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Cypress run + uses: cypress-io/github-action@v6 \ No newline at end of file From 4ad2c94ac95fbe12aa2f4efca137a153def9c708 Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Wed, 8 Jan 2025 16:24:26 +0100 Subject: [PATCH 08/13] test: first commit to add cypress tests to github actions --- .github/workflows/main.yml | 11 ++++++++++- commitlint.config.js | 2 +- cypress.config.js | 9 +++++++++ cypress/e2e/spec.cy.js | 5 +++++ cypress/fixtures/example.json | 5 +++++ cypress/support/commands.ts | 37 +++++++++++++++++++++++++++++++++++ cypress/support/e2e.ts | 17 ++++++++++++++++ cypress/support/tsconfig.json | 8 ++++++++ package.json | 3 +++ 9 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 cypress.config.js create mode 100644 cypress/e2e/spec.cy.js create mode 100644 cypress/fixtures/example.json create mode 100644 cypress/support/commands.ts create mode 100644 cypress/support/e2e.ts create mode 100644 cypress/support/tsconfig.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0f87cc216..2b34fb712a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -159,4 +159,13 @@ jobs: uses: sonarsource/sonarcloud-github-action@v3.1.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + cypress-run: + needs: npm-build + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Cypress run + uses: cypress-io/github-action@v6 \ No newline at end of file diff --git a/commitlint.config.js b/commitlint.config.js index 080384a0a6..17047d8c90 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,4 +1,4 @@ -import { RuleConfigSeverity } from "@commitlint/types"; +import { RuleConfigSeverity } from "@commitlint/typSans titrees"; // Config used by 'commitlint' GitHub action. export default { diff --git a/cypress.config.js b/cypress.config.js new file mode 100644 index 0000000000..17161e32e0 --- /dev/null +++ b/cypress.config.js @@ -0,0 +1,9 @@ +import { defineConfig } from "cypress"; + +export default defineConfig({ + e2e: { + setupNodeEvents(on, config) { + // implement node event listeners here + }, + }, +}); diff --git a/cypress/e2e/spec.cy.js b/cypress/e2e/spec.cy.js new file mode 100644 index 0000000000..322992ce19 --- /dev/null +++ b/cypress/e2e/spec.cy.js @@ -0,0 +1,5 @@ +describe('template spec', () => { + it('passes', () => { + cy.visit('https://example.cypress.io') + }) +}) \ No newline at end of file diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 0000000000..02e4254378 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts new file mode 100644 index 0000000000..698b01a42c --- /dev/null +++ b/cypress/support/commands.ts @@ -0,0 +1,37 @@ +/// +// *********************************************** +// This example commands.ts shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add('login', (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This will overwrite an existing command -- +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +// +// declare global { +// namespace Cypress { +// interface Chainable { +// login(email: string, password: string): Chainable +// drag(subject: string, options?: Partial): Chainable +// dismiss(subject: string, options?: Partial): Chainable +// visit(originalFn: CommandOriginalFn, url: string, options: Partial): Chainable +// } +// } +// } \ No newline at end of file diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts new file mode 100644 index 0000000000..e4e246ec99 --- /dev/null +++ b/cypress/support/e2e.ts @@ -0,0 +1,17 @@ +// *********************************************************** +// This example support/e2e.ts is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands' \ No newline at end of file diff --git a/cypress/support/tsconfig.json b/cypress/support/tsconfig.json new file mode 100644 index 0000000000..83fb87e55f --- /dev/null +++ b/cypress/support/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": ["es5", "dom"], + "types": ["cypress", "node"] + }, + "include": ["**/*.ts"] +} \ No newline at end of file diff --git a/package.json b/package.json index affe100a23..8def5eed6c 100644 --- a/package.json +++ b/package.json @@ -3,5 +3,8 @@ "devDependencies": { "@commitlint/cli": "^19.2.1", "@commitlint/config-conventional": "^19.1.0" + }, + "dependencies": { + "cypress": "^13.17.0" } } From 3066c2dd5877da89210a36bff441f19e78b76e9e Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Wed, 8 Jan 2025 16:30:26 +0100 Subject: [PATCH 09/13] test: first commit to add cypress tests to github actions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2b34fb712a..8f95574b38 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -163,7 +163,7 @@ jobs: cypress-run: needs: npm-build - runs-on: ubuntu-24.04 + runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v4 From 0d01a7ecafbad97d72162ec98559cc6a2642fbe3 Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Wed, 8 Jan 2025 16:31:59 +0100 Subject: [PATCH 10/13] test: first commit to add cypress tests to github actions --- .github/workflows/main.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8f95574b38..c0f87cc216 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -159,13 +159,4 @@ jobs: uses: sonarsource/sonarcloud-github-action@v3.1.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - cypress-run: - needs: npm-build - runs-on: ubuntu-20.04 - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Cypress run - uses: cypress-io/github-action@v6 \ No newline at end of file + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file From 22327e671b8714d41b715fd4fd5f82eaf36fa0c5 Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Wed, 8 Jan 2025 16:45:01 +0100 Subject: [PATCH 11/13] test: first commit to add cypress tests to github actions --- commitlint.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitlint.config.js b/commitlint.config.js index 17047d8c90..080384a0a6 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,4 +1,4 @@ -import { RuleConfigSeverity } from "@commitlint/typSans titrees"; +import { RuleConfigSeverity } from "@commitlint/types"; // Config used by 'commitlint' GitHub action. export default { From 7438c873c396420493261e6cd33b4507b95d18cc Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Thu, 9 Jan 2025 13:42:03 +0100 Subject: [PATCH 12/13] test: first commit to add cypress tests to github actions --- .github/workflows/main.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0f87cc216..4a6a2d5cbc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -159,4 +159,14 @@ jobs: uses: sonarsource/sonarcloud-github-action@v3.1.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + + cypress-run: + needs: npm-build + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Cypress run + uses: cypress-io/github-action@v6 \ No newline at end of file From b0bfeeeeef4f64edd1c46b2accecb7e1ee0b638c Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Thu, 9 Jan 2025 13:46:25 +0100 Subject: [PATCH 13/13] test: first commit to add cypress tests to github actions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4a6a2d5cbc..533a0cc65b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -164,7 +164,7 @@ jobs: cypress-run: needs: npm-build - runs-on: ubuntu-24.04 + runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v4