Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(package): migrate to ng12 #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:10-browsers
- image: circleci/node:14-browsers
environment:
JOBS: 1
steps:
Expand Down
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged
70 changes: 35 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,62 +29,59 @@
"ci:after": "greenkeeper-lockfile-upload",
"test": "jest --runInBand --colors",
"test:ci": "jest --ci --updateSnapshot --colors",
"release": "standard-version"
"release": "standard-version",
"prepare": "husky install"
},
"devDependencies": {
"@angular/common": "^9.1.0",
"@angular/compiler": "^9.1.0",
"@angular/compiler-cli": "^9.1.0",
"@angular/core": "^9.1.0",
"@angular/platform-browser": "^9.1.0",
"@angular/platform-browser-dynamic": "^9.1.0",
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@types/jest": "^23.3.14",
"@angular/common": "^12.0.3",
"@angular/compiler": "^12.0.3",
"@angular/compiler-cli": "^12.0.3",
"@angular/core": "^12.0.3",
"@angular/platform-browser": "^12.0.3",
"@angular/platform-browser-dynamic": "^12.0.3",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@types/jest": "^26.0.23",
"@types/lodash": "^4.14.150",
"@types/node": "^10.0.0",
"@types/node": "^15.12.2",
"angular-tslint-rules": "^1.20.4",
"codelyzer": "^5.2.2",
"codelyzer": "^6.0.2",
"cz-conventional-changelog": "^3.1.0",
"husky": "^4.2.0",
"jest": "^23.6.0",
"husky": "^6.0.0",
"jest": "^27.0.4",
"jest-junit-reporter": "^1.1.0",
"jest-preset-angular": "8.1.2",
"lerna": "^3.20.2",
"lint-staged": "^10.0.0",
"jest-preset-angular": "9.0.3",
"lerna": "^4.0.0",
"lint-staged": "^11.0.0",
"lodash": "^4.17.15",
"ng-packagr": "^9.0.0",
"prettier": "1.19.1",
"ng-packagr": "^12.0.4",
"prettier": "2.3.1",
"prettier-tslint": "^0.4.2",
"reflect-metadata": "^0.1.13",
"request": "^2.88.2",
"rimraf": "^3.0.2",
"rxjs": "~6.5.4",
"ts-node": "^8.9.0",
"tsickle": "^0.38.0",
"tslint": "^5.20.1",
"rxjs": "~7.1.0",
"ts-node": "^10.0.0",
"tsickle": "^0.40.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "~3.8.3",
"zone.js": "^0.10.2"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
"typescript": "~4.2.4",
"zone.js": "^0.11.4"
},
"jest": {
"preset": "jest-preset-angular",
"setupTestFrameworkScriptFile": "./tools/test/jest.setup.ts",
"setupFilesAfterEnv": [
"./tools/test/jest.setup.ts"
],
"testResultsProcessor": "./node_modules/jest-junit-reporter",
"testMatch": [
"**/+(*.)+(spec|test).+(ts|js)?(x)"
],
"globals": {
"ts-jest": {
"tsConfigFile": "./tsconfig.json"
},
"__TRANSFORM_HTML__": true
"stringifyContentPathRegex": "\\.html?$",
"tsconfig": "./tsconfig.json"
}
},
"moduleDirectories": [
"node_modules",
Expand All @@ -108,5 +105,8 @@
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"dependencies": {
"@angular-devkit/core": "^12.0.3"
}
}
140 changes: 79 additions & 61 deletions packages/@ngx-config/core/tests/config.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { async, inject } from '@angular/core/testing';
import { inject, waitForAsync } from '@angular/core/testing';

import { ConfigLoader, ConfigService, ConfigStaticLoader } from '../src';

Expand All @@ -10,7 +10,7 @@ describe('@ngx-config/core:', () => {

testModuleConfig({
provide: ConfigLoader,
useFactory: configFactory
useFactory: configFactory,
});
});

Expand All @@ -29,68 +29,86 @@ describe('@ngx-config/core:', () => {
});
}));

it('should be able to get setting(s) using `key`', async(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(config.getSettings('system')).toEqual({
applicationName: 'Mighty Mouse',
applicationUrl: 'http://localhost:8000'
});
it(
'should be able to get setting(s) using `key`',
waitForAsync(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(config.getSettings('system')).toEqual({
applicationName: 'Mighty Mouse',
applicationUrl: 'http://localhost:8000',
});

expect(config.getSettings(['system', 'applicationName'])).toEqual('Mighty Mouse');
expect(config.getSettings('system.applicationName')).toEqual('Mighty Mouse');
expect(config.getSettings(['system', 'applicationName'])).toEqual('Mighty Mouse');
expect(config.getSettings('system.applicationName')).toEqual('Mighty Mouse');

expect(config.getSettings(['system', 'applicationUrl'])).toEqual('http://localhost:8000');
expect(config.getSettings('system.applicationUrl')).toEqual('http://localhost:8000');
expect(config.getSettings(['system', 'applicationUrl'])).toEqual('http://localhost:8000');
expect(config.getSettings('system.applicationUrl')).toEqual('http://localhost:8000');

expect(config.getSettings('i18n')).toEqual({
locale: 'en'
});
expect(config.getSettings('i18n')).toEqual({
locale: 'en',
});

expect(config.getSettings(['i18n', 'locale'])).toEqual('en');
expect(config.getSettings('i18n.locale')).toEqual('en');
});
})
));

it('should be able to get setting(s) using `key` (zero value)', async(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(config.getSettings('falsy.zero')).toEqual(0);
});
})
));

it('should be able to get setting(s) using `key` (null value)', async(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(config.getSettings('falsy.null')).toBeNull();
});
})
));

it('should be able to get setting(s) using `key` (empty string)', async(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(config.getSettings('falsy.emptyString')).toEqual('');
});
})
));

it('should be able to get `default value` w/invalid `key`', async(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(config.getSettings('layout', 'default')).toEqual('default');
});
})
));

it('should throw if you provide an invalid `key` w/o `default value`', async(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(() => config.getSettings('layout')).toThrowError('No setting found with the specified key [layout]!');
});
})
));
expect(config.getSettings(['i18n', 'locale'])).toEqual('en');
expect(config.getSettings('i18n.locale')).toEqual('en');
});
})
)
);

it(
'should be able to get setting(s) using `key` (zero value)',
waitForAsync(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(config.getSettings('falsy.zero')).toEqual(0);
});
})
)
);

it(
'should be able to get setting(s) using `key` (null value)',
waitForAsync(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(config.getSettings('falsy.null')).toBeNull();
});
})
)
);

it(
'should be able to get setting(s) using `key` (empty string)',
waitForAsync(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(config.getSettings('falsy.emptyString')).toEqual('');
});
})
)
);

it(
'should be able to get `default value` w/invalid `key`',
waitForAsync(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(config.getSettings('layout', 'default')).toEqual('default');
});
})
)
);

it(
'should throw if you provide an invalid `key` w/o `default value`',
waitForAsync(
inject([ConfigService], (config: ConfigService) => {
config.loader.loadSettings().then(() => {
expect(() => config.getSettings('layout')).toThrowError('No setting found with the specified key [layout]!');
});
})
)
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { filter, isEmpty, mergeMap, reduce, share } from 'rxjs/operators';
const errorIfEmpty = (source: Observable<any>) =>
source.pipe(
isEmpty(),
mergeMap((empty: boolean) => (empty ? throwError(new Error('No setting found at the specified loader!')) : EMPTY))
mergeMap((empty: boolean) => (empty ? throwError(() => new Error('No setting found at the specified loader!')) : EMPTY))
);

const mergeWith = (object: any) => (source: Array<any>) =>
Expand Down Expand Up @@ -38,14 +38,14 @@ export class ConfigMergeLoader implements ConfigLoader {
}

private async mergeParallel(): Promise<any> {
const loaders: Array<ConfigLoader> = [new ConfigStaticLoader(), ...this.loaders];
const loaders: Array<ConfigLoader> = [new ConfigStaticLoader()].concat(this.loaders);

const mergedSettings = onErrorResumeNext(loaders.map((loader: ConfigLoader) => fromObservable(loader.loadSettings()))).pipe(
filter((res: any) => res),
share()
);

return new Promise((resolve: () => void, reject: Function) => {
return new Promise((resolve: (value: unknown) => void, reject: Function) => {
merge(mergedSettings, errorIfEmpty(mergedSettings), mergedSettings)
.pipe(reduce((merged: any, current: any) => mergeWith(merged)(current), {}))
.subscribe(resolve, () => reject('Loaders unreachable!'));
Expand Down
2 changes: 2 additions & 0 deletions tools/test/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// tslint:disable
import 'jest-preset-angular';
import 'zone.js';
import 'zone.js/testing';

const mock = () => {
let storage = {};
Expand Down
Loading