diff --git a/angular.json b/angular.json index 5c914ae5..18392b7b 100644 --- a/angular.json +++ b/angular.json @@ -180,6 +180,32 @@ } } }, + "pmp-api-e2e": { + "root": "apps/pmp-api-e2e", + "sourceRoot": "apps/pmp-api-e2e/src", + "projectType": "application", + "prefix": "pmp-api-e2e", + "schematics": {}, + "architect": { + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "apps/pmp-api-e2e/tsconfig.app.json", + "apps/pmp-api-e2e/tsconfig.spec.json" + ], + "exclude": ["**/node_modules/**", "!apps/pmp-api-e2e/**"] + } + }, + "e2e": { + "builder": "@nrwl/jest:jest", + "options": { + "jestConfig": "apps/pmp-api-e2e/jest.config.js", + "tsConfig": "apps/pmp-api-e2e/tsconfig.spec.json" + } + } + } + }, "pmp-web-shell": { "projectType": "library", "root": "libs/pmp-web/shell", diff --git a/apps/pmp-api-e2e/integration/app.spec.ts b/apps/pmp-api-e2e/integration/app.spec.ts new file mode 100644 index 00000000..5225e40f --- /dev/null +++ b/apps/pmp-api-e2e/integration/app.spec.ts @@ -0,0 +1,28 @@ +import * as request from 'supertest'; +import { Test } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +// tslint:disable-next-line TODO to remove, disable only to show proposal of usage +import { AppModule } from '../../pmp-api/src/app/app.module'; + +describe('Application', () => { + let app: INestApplication; + + beforeAll(async () => { + const module = await Test.createTestingModule({ + imports: [AppModule] + }).compile(); + + app = module.createNestApplication(); + await app.init(); + }); + + it(`/GET hello`, () => { + return request(app.getHttpServer()) + .get('/hello') + .expect(200, 'Welcome to api!'); + }); + + afterAll(async () => { + await app.close(); + }); +}); diff --git a/apps/pmp-api-e2e/jest.config.js b/apps/pmp-api-e2e/jest.config.js new file mode 100644 index 00000000..87454295 --- /dev/null +++ b/apps/pmp-api-e2e/jest.config.js @@ -0,0 +1,5 @@ +module.exports = { + name: 'pmp-api-e2e', + preset: '../../jest.config.js', + coverageDirectory: '../../coverage/apps/pmp-api-e2e' +}; diff --git a/apps/pmp-api-e2e/tsconfig.app.json b/apps/pmp-api-e2e/tsconfig.app.json new file mode 100644 index 00000000..bb717c5e --- /dev/null +++ b/apps/pmp-api-e2e/tsconfig.app.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": ["node"] + }, + "exclude": ["**/*.spec.ts"], + "include": ["**/*.ts"] +} diff --git a/apps/pmp-api-e2e/tsconfig.json b/apps/pmp-api-e2e/tsconfig.json new file mode 100644 index 00000000..e5decd5e --- /dev/null +++ b/apps/pmp-api-e2e/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "types": ["node", "jest"] + }, + "include": ["**/*.ts"] +} diff --git a/apps/pmp-api-e2e/tsconfig.spec.json b/apps/pmp-api-e2e/tsconfig.spec.json new file mode 100644 index 00000000..29efa430 --- /dev/null +++ b/apps/pmp-api-e2e/tsconfig.spec.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": ["**/*.spec.ts", "**/*.d.ts"] +} diff --git a/apps/pmp-api-e2e/tslint.json b/apps/pmp-api-e2e/tslint.json new file mode 100644 index 00000000..04809f83 --- /dev/null +++ b/apps/pmp-api-e2e/tslint.json @@ -0,0 +1 @@ +{ "extends": "../../tslint.json", "rules": [] } diff --git a/nx.json b/nx.json index 5a55f2b9..510d87c9 100644 --- a/nx.json +++ b/nx.json @@ -17,6 +17,9 @@ "pmp-api": { "tags": ["type:application", "scope:pmp-api"] }, + "pmp-api-e2e": { + "tags": ["type:application", "scope:pmp-api"] + }, "pmp-web-shell": { "tags": ["scope:pmp-web", "type:shell"] } diff --git a/package-lock.json b/package-lock.json index 6a6fdb87..7d70a9e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3275,6 +3275,12 @@ "@babel/types": "^7.3.0" } }, + "@types/cookiejar": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.1.tgz", + "integrity": "sha512-aRnpPa7ysx3aNW60hTiCtLHlQaIFsXFCgQlpakNgDNVFzbtusSY8PwjAQgRWfSk0ekNoBjO51eQRB6upA9uuyw==", + "dev": true + }, "@types/events": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", @@ -3370,6 +3376,25 @@ "integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==", "dev": true }, + "@types/superagent": { + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-4.1.4.tgz", + "integrity": "sha512-SRH2q6/5/nhOkAuLXm3azRGjBYpoKCZWh138Rt1AxSIyE6/1b9uClIH2V+JfyDtjIvgr5yQqYgNUmdpbneJoZQ==", + "dev": true, + "requires": { + "@types/cookiejar": "*", + "@types/node": "*" + } + }, + "@types/supertest": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-2.0.8.tgz", + "integrity": "sha512-wcax7/ip4XSSJRLbNzEIUVy2xjcBIZZAuSd2vtltQfRK7kxhx5WMHbLHkYdxN3wuQCrwpYrg86/9byDjPXoGMA==", + "dev": true, + "requires": { + "@types/superagent": "*" + } + }, "@types/webpack-sources": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.5.tgz", @@ -5512,6 +5537,12 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, + "cookiejar": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.2.tgz", + "integrity": "sha512-Mw+adcfzPxcPeI+0WlvRrr/3lGVO0bD75SxX6811cxSh1Wbxx7xZBGK1eVtDf6si8rg2lhnUjsVLMFMfbRIuwA==", + "dev": true + }, "copy-concurrently": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz", @@ -7586,6 +7617,12 @@ "mime-types": "^2.1.12" } }, + "formidable": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.1.tgz", + "integrity": "sha512-Fs9VRguL0gqGHkXS5GQiMCr1VhZBxz0JnJs4JmMp/2jL18Fmbzvv7vOFRU+U8TBkHEE/CX1qDXzJplVULgsLeg==", + "dev": true + }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -14945,6 +14982,45 @@ "when": "~3.6.x" } }, + "superagent": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-3.8.3.tgz", + "integrity": "sha512-GLQtLMCoEIK4eDv6OGtkOoSMt3D+oq0y3dsxMuYuDvaNUvuT8eFBuLmfR0iYYzHC1e8hpzC6ZsxbuP6DIalMFA==", + "dev": true, + "requires": { + "component-emitter": "^1.2.0", + "cookiejar": "^2.1.0", + "debug": "^3.1.0", + "extend": "^3.0.0", + "form-data": "^2.3.1", + "formidable": "^1.2.0", + "methods": "^1.1.1", + "mime": "^1.4.1", + "qs": "^6.5.1", + "readable-stream": "^2.3.5" + }, + "dependencies": { + "debug": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", + "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + } + } + }, + "supertest": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/supertest/-/supertest-4.0.2.tgz", + "integrity": "sha512-1BAbvrOZsGA3YTCWqbmh14L0YEq0EGICX/nBnfkfVJn7SrxQV1I3pMYjSzG9y/7ZU2V9dWqyqk2POwxlb09duQ==", + "dev": true, + "requires": { + "methods": "^1.1.2", + "superagent": "^3.8.3" + } + }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", diff --git a/package.json b/package.json index 3bd3ef7f..4845860b 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "@nrwl/workspace": "8.7.1", "@types/jest": "24.0.9", "@types/node": "~8.9.4", + "@types/supertest": "^2.0.8", "@valueadd/dev": "^4.0.0", "codelyzer": "~5.0.1", "cypress": "3.4.1", @@ -71,6 +72,7 @@ "jest": "24.1.0", "jest-preset-angular": "7.0.0", "prettier": "1.18.2", + "supertest": "latest", "ts-jest": "24.0.0", "ts-node": "~7.0.0", "tslint": "~5.11.0",