Skip to content

Commit

Permalink
fixed app e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Manganiello committed Jan 11, 2020
1 parent 69c7036 commit d9579e7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 45 deletions.
43 changes: 22 additions & 21 deletions generators/server/templates/server/e2e/app.e2e-spec.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as request from 'supertest';
import request = require('supertest');
import { AppModule } from '../src/app.module';
import { INestApplication } from '@nestjs/common';

describe('App', () => {
let app: INestApplication;
let app: INestApplication;

beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = moduleFixture.createNestApplication();
await app.init();
});

it('/GET info up running', () => {
return request(app.getHttpServer())
.get('/management/info')
.expect(200)
.expect({
const infoService = {
'activeProfiles': 'no',
'display-ribbon-on-profiles': 'no',
});
});
};


beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = moduleFixture.createNestApplication();
await app.init();
});

it('/GET info up running', () => request(app.getHttpServer())
.get('/management/info')
.expect(200)
.expect(infoService));

afterAll(async () => {
await app.close();
});
afterAll(async () => {
await app.close();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"globals": {
"NODE_ENV": "test"
}
}
2 changes: 1 addition & 1 deletion generators/server/templates/server/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<%_ if (authenticationType === 'jwt') { _%>
"@types/passport-jwt": "3.0.1",
<%_ } _%>
"@types/supertest": "2.0.7",
"@types/supertest": "2.0.8",
"@typescript-eslint/eslint-plugin": "2.11.0",
"@typescript-eslint/eslint-plugin-tslint": "2.11.0",
"@typescript-eslint/parser": "2.11.0",
Expand Down
42 changes: 20 additions & 22 deletions generators/server/templates/server/src/orm.config.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const commonConf = {
ENTITIES: [__dirname + '/domain/*.entity{.ts,.js}'],
MIGRATIONS: [__dirname + '/migrations/**/*{.ts,.js}'],
CLI: {
migrationsDir: 'src/migrations',
migrationsDir: 'src/migrations',
},
MIGRATIONS_RUN: true,
};
};

let ormconfig: TypeOrmModuleOptions = {
let ormconfig: TypeOrmModuleOptions = {
name: 'default',
type: 'sqlite',
database: '../target/sqlite-dev-db.sql',
Expand All @@ -20,26 +20,10 @@ const commonConf = {
migrations: commonConf.MIGRATIONS,
cli: commonConf.CLI,
migrationsRun: commonConf.MIGRATIONS_RUN,
};
};

<%_ if (prodDatabaseType === 'sqlite') { _%>

if(process.env.NODE_ENV==='prod'){
ormconfig = {
name: 'default',
type: 'sqlite',
database: '../target/sqlite-prod-db.sql',
logging: false,
synchronize: commonConf.SYNCRONIZE,
entities: commonConf.ENTITIES,
migrations: commonConf.MIGRATIONS,
cli: commonConf.CLI,
migrationsRun: commonConf.MIGRATIONS_RUN,
};
}
<%_ } else { _%>
if(process.env.NODE_ENV === 'prod'){
if (process.env.NODE_ENV === 'prod') {
ormconfig = {
name: 'default',
type: '<%= prodDatabaseType %>',
Expand All @@ -54,6 +38,20 @@ if(process.env.NODE_ENV === 'prod'){
};
}

<%_ } _%>
if (process.env.NODE_ENV === 'test') {
ormconfig = {
name: 'default',
type: 'sqlite',
database: ':memory:',
logging: true,
synchronize: true,
entities: commonConf.ENTITIES,
migrations: commonConf.MIGRATIONS,
cli: commonConf.CLI,
migrationsRun: commonConf.MIGRATIONS_RUN,
};
}



export { ormconfig };
2 changes: 1 addition & 1 deletion generators/server/templates/server/tsconfig.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": ["src/**/*","test", "**/*spec.ts", "scripts"]
"include": ["src/**/*", "**/*spec.ts", "scripts"]
}

0 comments on commit d9579e7

Please sign in to comment.