Skip to content

Commit 6e038d5

Browse files
Feature/ng libs helper (#14)
* Changed lib scripts to an external npm package * Renamed component model to library model * Updated karma conf to hopefully fix build for #13 * Removed double ampersand from package script * forgot the name * Fixed failingmock-api test * fix prod build issue * Added build libs to github pipeline * Fixed stupid tsconfig path mixup - dooohhh * Reverted build_libs from pipeline as it needs to update the paths to work with linux
1 parent 4dd010c commit 6e038d5

File tree

13 files changed

+335
-545
lines changed

13 files changed

+335
-545
lines changed

angular.json

Lines changed: 213 additions & 213 deletions
Large diffs are not rendered by default.

build-scripts/library-scripts.js

Lines changed: 0 additions & 221 deletions
This file was deleted.

karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ module.exports = function (config) {
2525
colors: true,
2626
logLevel: config.LOG_INFO,
2727
autoWatch: true,
28-
browsers: ['Chrome'],
28+
browsers: ['ChromeHeadlessNoSandbox'],
2929
singleRun: false,
3030
restartOnFileChange: true,
3131
customLaunchers: {
32-
ChromeHeadlessCustom: {
32+
ChromeHeadlessNoSandbox: {
3333
base: 'ChromeHeadless',
3434
flags: ['--no-sandbox', '--disable-gpu']
3535
}

libs.config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/chapi-chapi/ng-libs-helper/master/config.schema.json",
3+
"scopeName": "@chapichapi",
4+
"libraryNamePrefix": "ngx-",
5+
"isPublicScope": true,
6+
"karmaConfigPath": "./karma.conf.js"
7+
}

package-lock.json

Lines changed: 16 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@
77
"start:mock": "ng serve --configuration=mock",
88
"ng": "ng",
99
"clean": "rimraf ./dist",
10-
"libs:serve": "node -e \"require('./build-scripts/library-scripts').buildAndServe()\"",
11-
"libs:add": "node -e \"require('./build-scripts/library-scripts').add()\"",
12-
"libs:remove": "node -e \"require('./build-scripts/library-scripts').remove()\"",
13-
"libs:build": "node -e \"require('./build-scripts/library-scripts').build()\"",
14-
"libs:build:watch": "node -e \"require('./build-scripts/library-scripts').build(true)\"",
15-
"start": "node -e \"require('./build-scripts/library-scripts').buildAndServe()\"",
16-
"libs:tidyAngularJson": "node -e \"require('./build-scripts/library-scripts').tidyAngularJson()\"",
10+
"add_libs": "chapichapi-ng-libs add",
11+
"remove_libs": "chapichapi-ng-libs remove",
12+
"build_libs": "chapichapi-ng-libs build",
13+
"configs_libs": "chapichapi-ng-libs configs",
14+
"serve_libs": "chapichapi-ng-libs serve",
15+
"start": "npm run serve_libs",
1716
"build": "ng build",
1817
"build:prod": "ng build --prod",
19-
"test": "ng test --watch=false --browsers=ChromeHeadlessCustom",
18+
"test": "ng test --watch=false --browsers=ChromeHeadlessNoSandbox",
2019
"test:watch": "ng test",
2120
"lint": "ng lint",
2221
"e2e": "ng e2e",
23-
"build:ci": "npm run clean && npm run test && npm run build:prod",
22+
"build:ci": "npm run clean && npm install && npm rebuild && npm run test && npm run build:prod",
2423
"deploy:github-pages": "ng deploy --base-href=/angular-component-library/ --name=\"rogue-elephant\" [email protected]",
2524
"start:proxy:mock:server": "concurrently --kill-others \"npm run mock:server\" \"npm run start:proxy\""
2625
},
@@ -50,6 +49,7 @@
5049
"@angular/cli": "~9.0.3",
5150
"@angular/compiler-cli": "~9.0.2",
5251
"@angular/language-service": "~9.0.2",
52+
"@chapichapi/ngx-libs-helper": "0.0.8",
5353
"@types/jasmine": "~3.5.0",
5454
"@types/jasminewd2": "~2.0.3",
5555
"@types/node": "^12.11.1",
Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,54 @@
1-
import { TestBed } from '@angular/core/testing';
1+
import { TestBed, inject } from "@angular/core/testing";
2+
import {
3+
HttpClientTestingModule,
4+
HttpTestingController,
5+
} from "@angular/common/http/testing";
6+
import { HTTP_INTERCEPTORS, HttpClient } from "@angular/common/http";
7+
import { MockApiInterceptor } from "./mock-api.interceptor";
8+
import { MockApiModule } from "../mock-api.module";
9+
import { IMockInterceptorData } from "../models/IMockInterceptorData";
210

3-
import { MockApiInterceptor } from './mock-api.interceptor';
11+
const mockData = {
12+
fieldA: "Fish",
13+
fieldB: "Chips",
14+
};
15+
const mockURL = "/api/fishandchipsservice";
16+
const mockApi: IMockInterceptorData[] = [
17+
{
18+
url: mockURL,
19+
httpVerb: "GET",
20+
data: mockData,
21+
},
22+
];
423

5-
describe('MockApiInterceptor', () => {
6-
beforeEach(() => TestBed.configureTestingModule({
7-
providers: [
8-
MockApiInterceptor
9-
]
10-
}));
24+
describe("MockApiInterceptor", () => {
25+
beforeEach(() =>
26+
TestBed.configureTestingModule({
27+
imports: [HttpClientTestingModule, MockApiModule.forRoot(mockApi)],
28+
providers: [
29+
{
30+
provide: HTTP_INTERCEPTORS,
31+
useClass: MockApiInterceptor,
32+
multi: true,
33+
},
34+
],
35+
})
36+
);
37+
38+
describe("intercept HTTP GET requests", () => {
39+
it("should add Mock Data", inject(
40+
[HttpClient, HttpTestingController],
41+
(http: HttpClient, mock: HttpTestingController) => {
42+
http.get("/api/fishandchipsservice").subscribe((response) => {
43+
expect(response).toBeTruthy();
44+
expect(response).toEqual(mockData);
45+
});
46+
mock.verify();
47+
}
48+
));
49+
});
1150

12-
// it('should be created', () => {
13-
// const interceptor: MockApiInterceptor = TestBed.inject(MockApiInterceptor);
14-
// expect(interceptor).toBeTruthy();
15-
// });
51+
afterEach(inject([HttpTestingController], (mock: HttpTestingController) => {
52+
mock.verify();
53+
}));
1654
});

0 commit comments

Comments
 (0)