Skip to content

Commit 4aefd93

Browse files
committed
Launch backend backoffice when running Cypress
1 parent 9d16fe5 commit 4aefd93

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

tests/apps/backoffice/frontend/features/courses/create_course.cypress.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import faker from 'faker';
22

3-
describe('Courses', () => {
3+
describe('Create courses', () => {
44
before(() => {
5-
cy.task('reset:db');
5+
cy.task('reset:mooc:db');
66
});
77

88
beforeEach(() => {

tests/utils/cypress/open.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import cypress from 'cypress';
22
import { startBackofficeFrontend } from './startBackofficeFrontend';
3-
import app from '../../../src/apps/backoffice/frontend/app';
3+
import frontendApp from '../../../src/apps/backoffice/frontend/app';
4+
import { startBackofficeBackend } from './startBackofficeBackend';
45

56
async function open() {
6-
const server = await startBackofficeFrontend();
7+
const backofficeFrontendServer = await startBackofficeFrontend();
8+
const backofficeBackendServer = await startBackofficeBackend();
79
await openCypress();
8-
server.close(() => {
10+
backofficeFrontendServer.close(() => {
11+
process.exit(0);
12+
});
13+
backofficeBackendServer.close(() => {
914
process.exit(0);
1015
});
1116
}
@@ -14,7 +19,7 @@ async function openCypress() {
1419
return cypress.open({
1520
config: {
1621
supportFile: false,
17-
baseUrl: `http://localhost:${app.get('port')}`
22+
baseUrl: `http://localhost:${frontendApp.get('port')}`
1823
}
1924
});
2025
}

tests/utils/cypress/run.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import app from '../../../src/apps/backoffice/frontend/app';
1+
import frontendApp from '../../../src/apps/backoffice/frontend/app';
22
import cypress from 'cypress';
33
import cypressConfig from '../../../cypress.json';
44
import { startBackofficeFrontend } from './startBackofficeFrontend';
5+
import { startBackofficeBackend } from './startBackofficeBackend';
56

67
async function run() {
7-
const server = await startBackofficeFrontend();
8+
const backofficeFrontendServer = await startBackofficeFrontend();
9+
const backofficeBackendServer = await startBackofficeBackend();
810
await runCypress();
9-
server.close(() => {
11+
backofficeFrontendServer.close(() => {
12+
process.exit(0);
13+
});
14+
backofficeBackendServer.close(() => {
1015
process.exit(0);
1116
});
1217
}
@@ -19,7 +24,7 @@ async function runCypress() {
1924
config: {
2025
...cypressConfig,
2126
supportFile: false,
22-
baseUrl: `http://localhost:${app.get('port')}`
27+
baseUrl: `http://localhost:${frontendApp.get('port')}`
2328
}
2429
});
2530
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import app from '../../../src/apps/backoffice/backend/app';
2+
import { Server } from 'http';
3+
4+
export async function startBackofficeBackend(): Promise<Server> {
5+
let server: Server;
6+
7+
return new Promise((resolve, reject) => {
8+
server = app.listen(app.get('port'), async () => {
9+
console.log(` Backoffice backend is running at http://localhost:${app.get('port')} in ${app.get('env')} mode`);
10+
console.log(' Press CTRL-C to stop\n');
11+
resolve(server);
12+
});
13+
});
14+
}

0 commit comments

Comments
 (0)