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({ module.exports = defineConfig({
e2e: { e2e: {
setupNodeEvents(on, config) { setupNodeEvents(on, config) {
// implement node event listeners here // 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) { if (process.env.CI) {
cy.get('[data-testid=ConnectionDriverFields_server]').clear().type('mysql'); 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.get('[data-testid=ConnectionTab_buttonConnect]').click();
cy.contains('performance_schema'); cy.contains('performance_schema');
}); });
// it('import chinook DB', () => {
// cy.visit('http://localhost:3000');
// cy.findByText('test-mysql-1').dblclick();
// });
}); });

View File

@@ -18,9 +18,15 @@ function createTimeStamp() {
return ts; return ts;
} }
if (fs.existsSync(path.join(baseDir, 'connections.jsonl'))) { function clearDataWithBackup() {
fs.renameSync( if (fs.existsSync(path.join(baseDir, 'connections.jsonl'))) {
path.join(baseDir, 'connections.jsonl'), fs.renameSync(
path.join(baseDir, `connections-${createTimeStamp()}.jsonl.bak`) 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" "start-server-and-test": "^2.0.8"
}, },
"scripts": { "scripts": {
"cy:open": "cypress open", "cy:open": "cypress open --config experimentalInteractiveRunEvents=true",
"cy:run": "cypress run", "cy:run": "cypress run",
"start:ci": "cd .. && cross-env CI=true node packer/build/bundle.js --listen-api --run-packer-build", "cy:run:ci": "cross-env CI=true cypress run",
"start:local": "cd .. && node common/clearDataWithBackup.js && node packer/build/bundle.js --listen-api --run-packer-build", "start": "cd .. && node packer/build/bundle.js --listen-api --run-packer-build",
"test:ci": "start-server-and-test start:ci http://localhost:3000 cy:run", "test:ci": "start-server-and-test start http://localhost:3000 cy:run:ci",
"test:local": "start-server-and-test start:local http://localhost:3000 cy:run" "test": "start-server-and-test start http://localhost:3000 cy:run"
} }
} }

View File

@@ -411,7 +411,8 @@
name="displayName" name="displayName"
templateProps={{ noMargin: true }} templateProps={{ noMargin: true }}
disabled={isConnected} disabled={isConnected}
/> data-testid="ConnectionDriverFields_displayName"
/>
</div> </div>
<div class="col-6 mr-1"> <div class="col-6 mr-1">
<FormColorField <FormColorField
@@ -421,6 +422,7 @@
emptyLabel="(not selected)" emptyLabel="(not selected)"
templateProps={{ noMargin: true }} templateProps={{ noMargin: true }}
disabled={isConnected} disabled={isConnected}
data-testid="ConnectionDriverFields_connectionColor"
/> />
</div> </div>
</div> </div>