From ae5c539e31e508b2652a1eef2b6618027fd7a535 Mon Sep 17 00:00:00 2001 From: "SPRINX0\\prochazka" Date: Mon, 9 Dec 2024 15:33:45 +0100 Subject: [PATCH] UI tests --- .github/workflows/e2e-tests.yaml | 2 -- common/clearDataWithBackup.js | 26 ++++++++++++++++++++++++++ e2e-tests/package.json | 8 +++++--- e2e-tests/yarn.lock | 9 ++++++++- 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 common/clearDataWithBackup.js diff --git a/.github/workflows/e2e-tests.yaml b/.github/workflows/e2e-tests.yaml index f5c88b16f..db791f96d 100644 --- a/.github/workflows/e2e-tests.yaml +++ b/.github/workflows/e2e-tests.yaml @@ -33,8 +33,6 @@ jobs: run: | cd e2e-tests yarn ci - env: - CI: true services: mysql: diff --git a/common/clearDataWithBackup.js b/common/clearDataWithBackup.js new file mode 100644 index 000000000..f8e7e2bc6 --- /dev/null +++ b/common/clearDataWithBackup.js @@ -0,0 +1,26 @@ +const path = require('path'); +const os = require('os'); +const fs = require('fs'); + +const baseDir = path.join(os.homedir(), '.dbgate'); + +function createTimeStamp() { + const now = new Date(); + const year = now.getFullYear(); + const month = String(now.getMonth() + 1).padStart(2, '0'); // měsíc je 0-indexovaný + const day = String(now.getDate()).padStart(2, '0'); + const hours = String(now.getHours()).padStart(2, '0'); + const minutes = String(now.getMinutes()).padStart(2, '0'); + const seconds = String(now.getSeconds()).padStart(2, '0'); + + // Poskládáme datum a čas do názvu souboru + const ts = `${year}-${month}-${day}_${hours}-${minutes}-${seconds}`; + return ts; +} + +if (fs.existsSync(path.join(baseDir, 'connections.jsonl'))) { + fs.renameSync( + path.join(baseDir, 'connections.jsonl'), + path.join(baseDir, `connections-${createTimeStamp()}.jsonl.bak`) + ); +} diff --git a/e2e-tests/package.json b/e2e-tests/package.json index bdec4ff39..636ca3313 100644 --- a/e2e-tests/package.json +++ b/e2e-tests/package.json @@ -4,14 +4,16 @@ "main": "index.js", "license": "GPL", "devDependencies": { + "cross-env": "^7.0.3", "cypress": "^13.16.1", "start-server-and-test": "^2.0.8" }, "scripts": { "cy:open": "cypress open", "cy:run": "cypress run", - "start": "cd .. && node packer/build/bundle.js --listen-api --run-packer-build", - "test": "yarn cy:run", - "ci": "start-server-and-test http://localhost:3000" + "start:ci": "cd .. && cross-env CI=true node packer/build/bundle.js --listen-api --run-packer-build", + "start:local": "cd .. && node common/clearDataWithBackup.js && cross-env CI=true node packer/build/bundle.js --listen-api --run-packer-build", + "test:ci": "start-server-and-test start:ci http://localhost:3000 cy:run", + "test:local": "start-server-and-test start:local http://localhost:3000 cy:run" } } diff --git a/e2e-tests/yarn.lock b/e2e-tests/yarn.lock index 19e506a80..316dbd90f 100644 --- a/e2e-tests/yarn.lock +++ b/e2e-tests/yarn.lock @@ -334,7 +334,14 @@ core-util-is@1.0.2: resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" integrity sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ== -cross-spawn@^7.0.0, cross-spawn@^7.0.3: +cross-env@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf" + integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw== + dependencies: + cross-spawn "^7.0.1" + +cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.3: version "7.0.6" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==