Skip to content

Commit 97fa71d

Browse files
NachoVazqueznacho-vazquezLayZeeDK
authored
Add unit tests (#7)
* test: 💍 start unit testing angular-version-actions * test: 💍 add test suite for override-angular-versions * chore: 🤖 exclude tests from typescript compilation * test: make missing angular version unreachable on tests Co-authored-by: Lars Gyrup Brink Nielsen <[email protected]> * test: 💍 resolve PR suggestions * chore: 🤖 add latest builds to repo Co-authored-by: Nacho Vazquez <[email protected]> Co-authored-by: Lars Gyrup Brink Nielsen <[email protected]>
1 parent d0b9cb1 commit 97fa71d

16 files changed

+811
-13
lines changed

__tests__/get-angular-version.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {getAngularVersions} from '../src/get-angular-versions';
2+
import {versions} from '../src/angular-versions';
3+
4+
describe(getAngularVersions.name, () => {
5+
versions.forEach((expectedVersion, key) => {
6+
test('returns the right Angular versions for a given key', () => {
7+
const actualVersion = getAngularVersions(key);
8+
9+
expect(actualVersion).toEqual(expectedVersion);
10+
});
11+
});
12+
13+
test('returns new instances of Angular version for each call', () => {
14+
const firstVersion = getAngularVersions('8.0.x');
15+
const secondVersion = getAngularVersions('8.0.x');
16+
17+
expect(firstVersion).toEqual(secondVersion);
18+
expect(firstVersion).not.toBe(secondVersion);
19+
});
20+
21+
test('throws error when the version is not supported', () => {
22+
try {
23+
getAngularVersions('3.0.x');
24+
} catch (error) {
25+
expect(error.message).toBe('Angular version 3.0.x is not supported');
26+
}
27+
});
28+
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {
2+
packageJsonWithV8Dependencies,
3+
packageJsonWithV8DevDependencies,
4+
packageJsonWithV8All,
5+
fullPackageJson,
6+
packageUnmatching,
7+
packageJsonWithoutNgPackagr,
8+
packageJsonWithV8AllWithoutNgPackagr
9+
} from './package-json-versions';
10+
import {overrideAngularVersions} from '../src/override-angular-versions';
11+
import {getAngularVersions} from '../src/get-angular-versions';
12+
13+
describe(overrideAngularVersions.name, () => {
14+
describe('replaces versions existing in both sources', () => {
15+
test('replace ONLY Angular versions in dependencies', () => {
16+
const v8 = getAngularVersions('8.0.x');
17+
(v8.devDependencies as any) = {};
18+
19+
const actualPackageJson = overrideAngularVersions({
20+
projectVersions: fullPackageJson,
21+
angularVersions: v8
22+
});
23+
24+
expect(actualPackageJson).toEqual(packageJsonWithV8Dependencies);
25+
});
26+
27+
test('replace ONLY Angular versions in devDependencies', () => {
28+
const v8 = getAngularVersions('8.0.x');
29+
(v8.dependencies as any) = {};
30+
31+
const actualPackageJson = overrideAngularVersions({
32+
projectVersions: fullPackageJson,
33+
angularVersions: v8
34+
});
35+
36+
expect(actualPackageJson).toEqual(packageJsonWithV8DevDependencies);
37+
});
38+
39+
test('replace Angular versions in devDependencies and dependencies', () => {
40+
const v8 = getAngularVersions('8.0.x');
41+
42+
const actualPackageJson = overrideAngularVersions({
43+
projectVersions: fullPackageJson,
44+
angularVersions: v8
45+
});
46+
47+
expect(actualPackageJson).toEqual(packageJsonWithV8All);
48+
});
49+
50+
test('no override package with unmatching versions', () => {
51+
const v8 = getAngularVersions('8.0.x');
52+
53+
const actualPackageJson = overrideAngularVersions({
54+
projectVersions: packageUnmatching as any,
55+
angularVersions: v8
56+
});
57+
58+
expect(actualPackageJson).toEqual(packageUnmatching);
59+
});
60+
61+
test('no add ng-packagr dependency when it is not present in the package', () => {
62+
const v8 = getAngularVersions('8.0.x');
63+
64+
const actualPackageJson = overrideAngularVersions({
65+
projectVersions: packageJsonWithoutNgPackagr as any,
66+
angularVersions: v8
67+
});
68+
69+
expect(actualPackageJson).toEqual(packageJsonWithV8AllWithoutNgPackagr);
70+
});
71+
});
72+
});
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
export const fullPackageJson = {
2+
name: 'lumberjack',
3+
version: '0.0.0',
4+
scripts: {
5+
ng: 'ng',
6+
start: 'ng serve lumberjack-app',
7+
build: 'ng build lumberjack-app --prod',
8+
test: 'ng test lumberjack-app',
9+
'test:ci': 'yarn test --configuration=ci',
10+
lint: 'ng lint',
11+
e2e: 'ng e2e lumberjack-app-e2e',
12+
'contributors:add': 'all-contributors add',
13+
'hooks:pre-commit': 'node hooks/pre-commit.js',
14+
commit: 'git-cz',
15+
'release:first': 'yarn release -- --first-release',
16+
'build:lib':
17+
'ng build ngworker-lumberjack --prod && npx copy README.md ./dist/ngworker/lumberjack',
18+
'test:lib': 'ng test ngworker-lumberjack',
19+
'test:lib:ci': 'yarn test:lib --configuration=ci',
20+
'test:internal':
21+
'ng test internal-test-util && ng test internal-console-driver-test-util',
22+
'test:internal:ci':
23+
'ng test internal-test-util --configuration=ci && ng test internal-console-driver-test-util --configuration=ci',
24+
release:
25+
'cd libs/ngworker/lumberjack && standard-version --infile ../../../CHANGELOG.md',
26+
publish: 'cd dist/ngworker/lumberjack && npm publish',
27+
ci:
28+
'yarn install && yarn lint && yarn build:lib && yarn test:internal:ci && yarn test:lib:ci && yarn build && yarn test:ci && yarn e2e',
29+
format:
30+
'npx prettier --config prettier.config.js --write "**/*.*" "!dist/**" "!yarn.lock"',
31+
'delete-path-alias': 'node tools/delete-path-alias.js'
32+
},
33+
private: true,
34+
dependencies: {
35+
'@angular/animations': '~10.1.6',
36+
'@angular/common': '~10.1.6',
37+
'@angular/compiler': '~10.1.6',
38+
'@angular/core': '~10.1.6',
39+
'@angular/forms': '~10.1.6',
40+
'@angular/platform-browser': '~10.1.6',
41+
'@angular/platform-browser-dynamic': '~10.1.6',
42+
'@angular/router': '~10.1.6',
43+
rxjs: '~6.6.3',
44+
tslib: '^2.0.0',
45+
'zone.js': '~0.10.3'
46+
},
47+
devDependencies: {
48+
'@angular-devkit/build-angular': '~0.1001.7',
49+
'@angular-devkit/build-ng-packagr': '~0.1001.7',
50+
'@angular/cli': '~10.1.7',
51+
'@angular/compiler-cli': '~10.1.6',
52+
'@commitlint/cli': '8.1.0',
53+
'@commitlint/config-angular': '^8.3.4',
54+
'@commitlint/config-conventional': '^8.3.4',
55+
'@ngneat/spectator': '^6.0.0',
56+
'@types/jasmine': '~3.5.0',
57+
'@types/jasminewd2': '~2.0.3',
58+
'@types/node': '^12.12.62',
59+
'all-contributors-cli': '^6.8.1',
60+
codelyzer: '^6.0.0',
61+
copy: '~0.3.2',
62+
'git-cz': '^3.3.0',
63+
husky: '^3.1.0',
64+
'jasmine-core': '~3.5.0',
65+
'jasmine-spec-reporter': '~5.0.2',
66+
json: '^10.0.0',
67+
karma: '~5.0.9',
68+
'karma-chrome-launcher': '~3.1.0',
69+
'karma-coverage-istanbul-reporter': '~3.0.2',
70+
'karma-jasmine': '~3.3.1',
71+
'karma-jasmine-html-reporter': '^1.5.0',
72+
'lint-staged': '^9.5.0',
73+
'ng-packagr': '^10.0.0',
74+
prettier: '^2.0.5',
75+
protractor: '~7.0.0',
76+
'standard-version': '^6.0.1',
77+
'ts-node': '~8.3.0',
78+
tslint: '~6.1.0',
79+
'tslint-config-prettier': '^1.18.0',
80+
'tslint-plugin-prettier': '^2.3.0',
81+
typescript: '~3.9.7'
82+
},
83+
config: {
84+
commitizen: {
85+
path: 'cz-conventional-changelog'
86+
}
87+
},
88+
'lint-staged': {
89+
'*.{js,json,css,scss,ts,html,component.html}': [
90+
'prettier --write',
91+
'git add'
92+
]
93+
},
94+
husky: {
95+
hooks: {
96+
'commit-msg': 'commitlint -e $HUSKY_GIT_PARAMS',
97+
'pre-commit': 'yarn hooks:pre-commit && lint-staged && yarn lint',
98+
'pre-push': 'yarn test:lib:ci'
99+
}
100+
}
101+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export * from './full-package-json';
2+
export * from './v8-dep-overrided';
3+
export * from './v8-devdep-override';
4+
export * from './v8-all-override';
5+
export * from './package-unmatching';
6+
export * from './package-without-ng-packagr';
7+
export * from './v8-all-override-without-ng-packagr';
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
export const packageUnmatching = {
2+
name: 'lumberjack',
3+
version: '0.0.0',
4+
scripts: {
5+
ng: 'ng',
6+
start: 'ng serve lumberjack-app',
7+
build: 'ng build lumberjack-app --prod',
8+
test: 'ng test lumberjack-app',
9+
'test:ci': 'yarn test --configuration=ci',
10+
lint: 'ng lint',
11+
e2e: 'ng e2e lumberjack-app-e2e',
12+
'contributors:add': 'all-contributors add',
13+
'hooks:pre-commit': 'node hooks/pre-commit.js',
14+
commit: 'git-cz',
15+
'release:first': 'yarn release -- --first-release',
16+
'build:lib':
17+
'ng build ngworker-lumberjack --prod && npx copy README.md ./dist/ngworker/lumberjack',
18+
'test:lib': 'ng test ngworker-lumberjack',
19+
'test:lib:ci': 'yarn test:lib --configuration=ci',
20+
'test:internal':
21+
'ng test internal-test-util && ng test internal-console-driver-test-util',
22+
'test:internal:ci':
23+
'ng test internal-test-util --configuration=ci && ng test internal-console-driver-test-util --configuration=ci',
24+
release:
25+
'cd libs/ngworker/lumberjack && standard-version --infile ../../../CHANGELOG.md',
26+
publish: 'cd dist/ngworker/lumberjack && npm publish',
27+
ci:
28+
'yarn install && yarn lint && yarn build:lib && yarn test:internal:ci && yarn test:lib:ci && yarn build && yarn test:ci && yarn e2e',
29+
format:
30+
'npx prettier --config prettier.config.js --write "**/*.*" "!dist/**" "!yarn.lock"',
31+
'delete-path-alias': 'node tools/delete-path-alias.js'
32+
},
33+
private: true,
34+
dependencies: {
35+
unmatching: 'unmatching'
36+
},
37+
devDependencies: {
38+
'unmatching-dev': 'unmatching-dev',
39+
'@commitlint/cli': '8.1.0',
40+
'@commitlint/config-angular': '^8.3.4',
41+
'@commitlint/config-conventional': '^8.3.4',
42+
'@ngneat/spectator': '^6.0.0',
43+
'@types/jasmine': '~3.5.0',
44+
'@types/jasminewd2': '~2.0.3',
45+
'all-contributors-cli': '^6.8.1',
46+
copy: '~0.3.2',
47+
'git-cz': '^3.3.0',
48+
husky: '^3.1.0',
49+
'jasmine-core': '~3.5.0',
50+
'jasmine-spec-reporter': '~5.0.2',
51+
json: '^10.0.0',
52+
karma: '~5.0.9',
53+
'karma-chrome-launcher': '~3.1.0',
54+
'karma-coverage-istanbul-reporter': '~3.0.2',
55+
'karma-jasmine': '~3.3.1',
56+
'karma-jasmine-html-reporter': '^1.5.0',
57+
'lint-staged': '^9.5.0',
58+
'ng-packagr': '^10.0.0',
59+
prettier: '^2.0.5',
60+
protractor: '~7.0.0',
61+
'standard-version': '^6.0.1',
62+
'tslint-config-prettier': '^1.18.0',
63+
'tslint-plugin-prettier': '^2.3.0'
64+
},
65+
config: {
66+
commitizen: {
67+
path: 'cz-conventional-changelog'
68+
}
69+
},
70+
'lint-staged': {
71+
'*.{js,json,css,scss,ts,html,component.html}': [
72+
'prettier --write',
73+
'git add'
74+
]
75+
},
76+
husky: {
77+
hooks: {
78+
'commit-msg': 'commitlint -e $HUSKY_GIT_PARAMS',
79+
'pre-commit': 'yarn hooks:pre-commit && lint-staged && yarn lint',
80+
'pre-push': 'yarn test:lib:ci'
81+
}
82+
}
83+
};
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
export const packageJsonWithoutNgPackagr = {
2+
name: 'lumberjack',
3+
version: '0.0.0',
4+
scripts: {
5+
ng: 'ng',
6+
start: 'ng serve lumberjack-app',
7+
build: 'ng build lumberjack-app --prod',
8+
test: 'ng test lumberjack-app',
9+
'test:ci': 'yarn test --configuration=ci',
10+
lint: 'ng lint',
11+
e2e: 'ng e2e lumberjack-app-e2e',
12+
'contributors:add': 'all-contributors add',
13+
'hooks:pre-commit': 'node hooks/pre-commit.js',
14+
commit: 'git-cz',
15+
'release:first': 'yarn release -- --first-release',
16+
'build:lib':
17+
'ng build ngworker-lumberjack --prod && npx copy README.md ./dist/ngworker/lumberjack',
18+
'test:lib': 'ng test ngworker-lumberjack',
19+
'test:lib:ci': 'yarn test:lib --configuration=ci',
20+
'test:internal':
21+
'ng test internal-test-util && ng test internal-console-driver-test-util',
22+
'test:internal:ci':
23+
'ng test internal-test-util --configuration=ci && ng test internal-console-driver-test-util --configuration=ci',
24+
release:
25+
'cd libs/ngworker/lumberjack && standard-version --infile ../../../CHANGELOG.md',
26+
publish: 'cd dist/ngworker/lumberjack && npm publish',
27+
ci:
28+
'yarn install && yarn lint && yarn build:lib && yarn test:internal:ci && yarn test:lib:ci && yarn build && yarn test:ci && yarn e2e',
29+
format:
30+
'npx prettier --config prettier.config.js --write "**/*.*" "!dist/**" "!yarn.lock"',
31+
'delete-path-alias': 'node tools/delete-path-alias.js'
32+
},
33+
private: true,
34+
dependencies: {
35+
'@angular/animations': '~10.1.6',
36+
'@angular/common': '~10.1.6',
37+
'@angular/compiler': '~10.1.6',
38+
'@angular/core': '~10.1.6',
39+
'@angular/forms': '~10.1.6',
40+
'@angular/platform-browser': '~10.1.6',
41+
'@angular/platform-browser-dynamic': '~10.1.6',
42+
'@angular/router': '~10.1.6',
43+
rxjs: '~6.6.3',
44+
tslib: '^2.0.0',
45+
'zone.js': '~0.10.3'
46+
},
47+
devDependencies: {
48+
'@angular-devkit/build-angular': '~0.1001.7',
49+
'@angular/cli': '~10.1.7',
50+
'@angular/compiler-cli': '~10.1.6',
51+
'@commitlint/cli': '8.1.0',
52+
'@commitlint/config-angular': '^8.3.4',
53+
'@commitlint/config-conventional': '^8.3.4',
54+
'@ngneat/spectator': '^6.0.0',
55+
'@types/jasmine': '~3.5.0',
56+
'@types/jasminewd2': '~2.0.3',
57+
'@types/node': '^12.12.62',
58+
'all-contributors-cli': '^6.8.1',
59+
codelyzer: '^6.0.0',
60+
copy: '~0.3.2',
61+
'git-cz': '^3.3.0',
62+
husky: '^3.1.0',
63+
'jasmine-core': '~3.5.0',
64+
'jasmine-spec-reporter': '~5.0.2',
65+
json: '^10.0.0',
66+
karma: '~5.0.9',
67+
'karma-chrome-launcher': '~3.1.0',
68+
'karma-coverage-istanbul-reporter': '~3.0.2',
69+
'karma-jasmine': '~3.3.1',
70+
'karma-jasmine-html-reporter': '^1.5.0',
71+
'lint-staged': '^9.5.0',
72+
'ng-packagr': '^10.0.0',
73+
prettier: '^2.0.5',
74+
protractor: '~7.0.0',
75+
'standard-version': '^6.0.1',
76+
'ts-node': '~8.3.0',
77+
tslint: '~6.1.0',
78+
'tslint-config-prettier': '^1.18.0',
79+
'tslint-plugin-prettier': '^2.3.0',
80+
typescript: '~3.9.7'
81+
},
82+
config: {
83+
commitizen: {
84+
path: 'cz-conventional-changelog'
85+
}
86+
},
87+
'lint-staged': {
88+
'*.{js,json,css,scss,ts,html,component.html}': [
89+
'prettier --write',
90+
'git add'
91+
]
92+
},
93+
husky: {
94+
hooks: {
95+
'commit-msg': 'commitlint -e $HUSKY_GIT_PARAMS',
96+
'pre-commit': 'yarn hooks:pre-commit && lint-staged && yarn lint',
97+
'pre-push': 'yarn test:lib:ci'
98+
}
99+
}
100+
};

0 commit comments

Comments
 (0)