Skip to content

Commit 036caed

Browse files
committed
Split GH actions test execution. Fix Cypress tests for running into GH Actions
1 parent 359f824 commit 036caed

File tree

15 files changed

+65
-48
lines changed

15 files changed

+65
-48
lines changed

.github/workflows/nodejs.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
node-version: [12.x, 15.x]
12-
mongodb-version: [4.0, 4.2]
12+
mongodb-version: [4.2]
1313
elasticsearch-version: ['7.9.3']
1414
rabbitmq-version: ['3.8.2-management-alpine']
1515

@@ -23,6 +23,10 @@ jobs:
2323
uses: wbari/start-mongoDB@v0.2
2424
with:
2525
mongoDBVersion: ${{ matrix.mongodb-version }}
26+
- name: Launch RabbitMQ
27+
uses: nijel/rabbitmq-action@v1.0.0
28+
with:
29+
rabbitmq version: ${{ matrix.rabbitmq-version }}
2630
- name: Configure sysctl limits
2731
run: |
2832
sudo swapoff -a
@@ -41,16 +45,17 @@ jobs:
4145
- name: npm install
4246
run: |
4347
npm install
44-
env:
45-
CI: true
4648
- name: npm run build
4749
run: |
4850
npm run build --if-present
4951
npm run lint
50-
env:
51-
CI: true
5252
- name: npm test
5353
run: |
5454
npm test
55+
- name: Cypress run
56+
uses: cypress-io/github-action@v1
5557
env:
56-
CI: true
58+
NODE_ENV: end2end
59+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
60+
with:
61+
start: npm run cypress:ci:start

cypress.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"baseUrl": "http://localhost:8032",
23
"video": false,
34
"screenshotOnRunFailure": false,
45
"testFiles": "**/*.cypress.*",

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"dev:mooc:backend": "NODE_ENV=dev ts-node-dev --ignore-watch node_modules ./src/apps/mooc/backend/start.ts",
1515
"dev:backoffice:frontend": "NODE_ENV=dev ts-node-dev --ignore-watch node_modules ./src/apps/backoffice/frontend/start.ts",
1616
"dev:backoffice:backend": "NODE_ENV=dev ts-node-dev --ignore-watch node_modules ./src/apps/backoffice/backend/start.ts",
17-
"test": "npm run test:unit && npm run test:features && npm run cypress:run",
17+
"test": "npm run test:unit && npm run test:features",
1818
"test:unit": "NODE_ENV=test jest",
1919
"test:features": "npm run test:mooc:backend:features && npm run test:backoffice:backend:features",
2020
"test:mooc:backend:features": "NODE_ENV=test cucumber-js -p mooc_backend",
@@ -28,7 +28,8 @@
2828
"build:di": "copy 'src/**/*.{json,yaml,html,png}' dist/src",
2929
"build:clean": "rm -r dist; exit 0",
3030
"cypress:open": "NODE_ENV=end2end ts-node tests/utils/cypress/open",
31-
"cypress:run": "NODE_ENV=end2end ts-node tests/utils/cypress/run"
31+
"cypress:run": "NODE_ENV=end2end ts-node tests/utils/cypress/run",
32+
"cypress:ci:start": "NODE_ENV=end2end ts-node tests/utils/cypress/startApps"
3233
},
3334
"dependencies": {
3435
"@types/amqplib": "^0.5.17",

src/Contexts/Shared/infrastructure/WinstonLogger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Logger from '../domain/Logger';
2-
import winston, { Logger as WinstonLoggerType } from 'winston';
2+
import winston, { format, Logger as WinstonLoggerType } from 'winston';
33

44
enum Levels {
55
DEBUG = 'debug',
@@ -12,6 +12,7 @@ class WinstonLogger implements Logger {
1212

1313
constructor() {
1414
this.logger = winston.createLogger({
15+
format: format.combine(format.splat(), format.simple()),
1516
transports: [
1617
new winston.transports.Console(),
1718
new winston.transports.File({ filename: `logs/${Levels.DEBUG}.log`, level: Levels.DEBUG }),

src/apps/mooc/backend/MoocBackendApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class MoocBackendApp {
1616
return this.server.listen();
1717
}
1818

19-
async close() {
19+
async stop() {
2020
return this.server?.stop();
2121
}
2222

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ describe('Create courses', () => {
66
cy.task('reset:backoffice:db');
77
});
88

9+
after(() => {
10+
cy.task('reset:mooc:db');
11+
cy.task('reset:backoffice:db');
12+
});
13+
914
beforeEach(() => {
1015
cy.visit('courses');
1116
});

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ describe('List courses', () => {
88
cy.visit('courses');
99
});
1010

11+
after(() => {
12+
cy.task('reset:mooc:db');
13+
cy.task('reset:backoffice:db');
14+
});
15+
1116
it('can list courses', () => {
1217
cy.get('input[name="name"]').type('DDD en Typescript');
1318
cy.get('input[name="duration"]').type('25 hours');

tests/apps/mooc/backend/features/step_definitions/controller.steps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ AfterAll(async () => {
4040
const environmentArranger: Promise<EnvironmentArranger> = container.get('Mooc.EnvironmentArranger');
4141
await (await environmentArranger).arrange();
4242
await (await environmentArranger).close();
43-
await application.close();
43+
await application.stop();
4444
});

tests/utils/cypress/Applications.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { BackofficeBackendApp } from '../../../src/apps/backoffice/backend/BackofficeBackendApp';
2+
import { BackofficeFrontendApp } from '../../../src/apps/backoffice/frontend/BackofficeFrontendApp';
3+
import { MoocBackendApp } from '../../../src/apps/mooc/backend/MoocBackendApp';
4+
5+
export class Applications {
6+
private static backofficeBackend: BackofficeBackendApp;
7+
private static backofficeFrontend: BackofficeFrontendApp;
8+
private static mooc: MoocBackendApp;
9+
10+
static async start() {
11+
this.backofficeBackend = new BackofficeBackendApp();
12+
this.backofficeFrontend = new BackofficeFrontendApp();
13+
this.mooc = new MoocBackendApp();
14+
15+
await this.mooc.start();
16+
await this.backofficeBackend.start();
17+
await this.backofficeFrontend.start();
18+
19+
return this.backofficeFrontend.port;
20+
}
21+
22+
static async stop() {
23+
await this.mooc.stop();
24+
await this.backofficeBackend.stop();
25+
await this.backofficeFrontend.stop();
26+
}
27+
}

tests/utils/cypress/open.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import cypress from 'cypress';
2-
import { startBackofficeFrontend } from './startBackofficeFrontend';
3-
import { startBackofficeBackend } from './startBackofficeBackend';
4-
import { startMoocBackend } from './startMoocBackend';
2+
import { Applications } from './Applications';
53

64
async function open() {
7-
const backofficeFrontend = await startBackofficeFrontend();
8-
const backofficeBackend = await startBackofficeBackend();
9-
const moockBackend = await startMoocBackend();
10-
const port = backofficeFrontend.port;
5+
const port = await Applications.start();
116
await runCypress(port);
127

13-
await Promise.all([backofficeFrontend.stop(), backofficeBackend.stop(), moockBackend]);
8+
await Applications.stop();
149
process.exit(0);
1510
}
1611

0 commit comments

Comments
 (0)