cypress run server inline test

This commit is contained in:
SPRINX0\prochazka
2024-12-09 16:32:56 +01:00
parent 75f75d95a6
commit 5405b9bf72
5 changed files with 54 additions and 12 deletions

View File

@@ -1,9 +1,35 @@
const { defineConfig } = require("cypress");
const { defineConfig } = require('cypress');
const { clearDataWithBackup } = require('./e2eTestTools');
const { exec } = require('child_process');
const waitOn = require('wait-on');
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
let serverProcess;
on('before:spec', async details => {
console.log('******** BEFORE RUN ****************');
clearDataWithBackup();
serverProcess = exec('yarn start');
await waitOn({ resources: ['http://localhost:3000'] });
serverProcess.stdout.on('data', data => {
console.log(data.toString());
});
serverProcess.stderr.on('data', data => {
console.error(data.toString());
});
});
on('after:spec', () => {
console.log('******** AFTER RUN ****************', serverProcess);
if (serverProcess) {
console.log('Stopping local server...');
serverProcess.kill();
}
});
},
},
});

View File

@@ -14,7 +14,15 @@ describe('Initialization', () => {
if (process.env.CI) {
cy.get('[data-testid=ConnectionDriverFields_server]').clear().type('mysql');
}
cy.get('[data-testid=ConnectionDriverFields_displayName]').clear().type('test-mysql-1');
cy.get('[data-testid=ConnectionTab_buttonSave]').click();
cy.get('[data-testid=ConnectionTab_buttonConnect]').click();
cy.contains('performance_schema');
});
// it('import chinook DB', () => {
// cy.visit('http://localhost:3000');
// cy.findByText('test-mysql-1').dblclick();
// });
});

32
e2e-tests/e2eTestTools.js Normal file
View File

@@ -0,0 +1,32 @@
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;
}
function clearDataWithBackup() {
if (fs.existsSync(path.join(baseDir, 'connections.jsonl'))) {
fs.renameSync(
path.join(baseDir, 'connections.jsonl'),
path.join(baseDir, `connections-${createTimeStamp()}.jsonl.bak`)
);
}
}
module.exports = {
clearDataWithBackup,
};

View File

@@ -9,11 +9,11 @@
"start-server-and-test": "^2.0.8"
},
"scripts": {
"cy:open": "cypress open",
"cy:open": "cypress open --config experimentalInteractiveRunEvents=true",
"cy:run": "cypress run",
"start:ci": "cd .. && cross-env CI=true node packer/build/bundle.js --listen-api --run-packer-build",
"start:local": "cd .. && node common/clearDataWithBackup.js && 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"
"cy:run:ci": "cross-env CI=true cypress run",
"start": "cd .. && node packer/build/bundle.js --listen-api --run-packer-build",
"test:ci": "start-server-and-test start http://localhost:3000 cy:run:ci",
"test": "start-server-and-test start http://localhost:3000 cy:run"
}
}