Skip to content

Commit 8b218e9

Browse files
authored
feat: migrated packages/components from jasmine/karma to jest (#DS-2694) (koobiq#196)
1 parent fafe889 commit 8b218e9

File tree

92 files changed

+5811
-4683
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+5811
-4683
lines changed

.eslintrc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// @ts-check
22

3+
const isCI = !!process.env.CI;
4+
35
/** @type {import('eslint').Linter.Config} */
46
const config = {
57
root: true,
@@ -16,7 +18,7 @@ const config = {
1618
],
1719
rules: {
1820
// plugin:file-progress
19-
'file-progress/activate': process.env.GITHUB_ACTION ? 0 : 1,
21+
'file-progress/activate': isCI ? 0 : 1,
2022
// plugin:eslint-comments
2123
'eslint-comments/no-unused-disable': 1
2224
},
@@ -62,6 +64,7 @@ const config = {
6264
],
6365
'@typescript-eslint/no-duplicate-enum-values': 0,
6466
'@typescript-eslint/ban-tslint-comment': 1,
67+
6568
// plugin:@angular-eslint
6669
'@angular-eslint/component-class-suffix': 0,
6770
'@angular-eslint/no-host-metadata-property': 0,

angular.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,22 @@
230230
}
231231
},
232232
"test": {
233+
"builder": "@angular-builders/jest:run",
234+
"options": {
235+
"roots": ["packages/components"],
236+
"configPath": "../../jest.config.js",
237+
"tsConfig": "../../tsconfig.spec.json"
238+
}
239+
},
240+
"karma-test": {
233241
"builder": "@angular-devkit/build-angular:karma",
234242
"options": {
235243
"karmaConfig": "packages/components/karma.conf.js",
236-
"main": "packages/components/test.ts",
237-
"tsConfig": "packages/components/tsconfig.spec.json",
238-
"codeCoverage": true
244+
"main": "packages/components/karma-test.ts",
245+
"tsConfig": "packages/components/tsconfig.karma-spec.json",
246+
"include": [
247+
"**/*.karma-spec.ts"
248+
]
239249
}
240250
}
241251
}

docs/guides/06-testing.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22

33
## Unit tests
44

5-
- write unit test for component using **Jasmine test framework**.
5+
We are using [Jest](https://github.com/jestjs/jest).
66

7-
## Browser tests
7+
Runs tests for package
88

9-
- in progress
9+
```bash
10+
ng test components
11+
```
1012

11-
## Browser Webdriver/Integration tests
13+
Runs specific spec file
1214

13-
- in progress
15+
```bash
16+
yarn jest packages/components/alert/alert.component.spec.ts
17+
```
1418

15-
## Visual regression tests
19+
Runs specific test closure (`it`)
1620

17-
- in progress
21+
```bash
22+
yarn jest packages/components/alert/alert.component.spec.ts --testNamePattern='should add class'
23+
```

jest.config.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@
33
const { pathsToModuleNameMapper } = require('ts-jest');
44
const { compilerOptions } = require('./tsconfig.json');
55

6+
const isCI = !!process.env.CI;
7+
68
/** @type {import('jest').Config} */
79
const config = {
810
rootDir: __dirname,
911
bail: 1,
10-
verbose: true,
12+
verbose: !isCI,
13+
silent: isCI,
1114
resetModules: true,
1215
clearMocks: true,
1316
cacheDirectory: '<rootDir>/node_modules/.cache/jest',
1417
preset: 'jest-preset-angular',
15-
setupFilesAfterEnv: ['<rootDir>/tools/jest/setup.js'],
16-
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
17-
testMatch: ['<rootDir>/**/*.spec.ts']
18+
setupFilesAfterEnv: ['<rootDir>/tools/jest/setup.ts'],
19+
moduleNameMapper: {
20+
...pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' })
21+
},
22+
testMatch: ['<rootDir>/**/*.spec.ts'],
23+
testTimeout: 2000
1824
};
1925

2026
module.exports = config;

karma.conf.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ module.exports = () => {
3030
'junit'
3131
],
3232

33-
files: [{ pattern: '../../dist/components/prebuilt-themes/light-theme.css', included: true, watched: true }],
34-
3533
port: 9876,
3634
colors: true,
3735
logLevel: constants.LOG_INFO,

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,6 @@
173173
"build:package-docs-content": "ts-node --project ./tools/package-docs-content/tsconfig.json ./tools/package-docs-content/package-docs-content.ts",
174174
"styles:built-all": "ts-node --project tools/scss-compiler/tsconfig.json tools/scss-compiler/scss-bundle.ts",
175175
"build:schematics": "rimraf packages/schematics/dist && rollup --failAfterWarnings -c packages/schematics/rollup.config.js && node ./packages/schematics/scripts/copy-meta-to-dist.mjs",
176-
"unit:cdk": "ng test cdk",
177-
"unit:components": "ng test components",
178-
"unit:angular-moment-adapter": "ng test angular-moment-adapter",
179-
"unit:angular-luxon-adapter": "ng test angular-luxon-adapter",
180-
"unit:schematics": "jest --roots packages/schematics",
181176
"docs": "pnpm run build:cdk && pnpm run build:components && pnpm run styles:built-all && pnpm run build:angular-luxon-adapter && pnpm run build:angular-moment-adapter && pnpm run build:docs-content && pnpm run build:package-docs-content && pnpm run build:docs-examples-module && pnpm run build:docs-examples && pnpm run docs:start:dev",
182177
"docs:start:dev": "ng serve --configuration=development koobiq-docs",
183178
"docs:start:prod": "ng serve --configuration=production koobiq-docs",
@@ -260,7 +255,13 @@
260255
"dev:timezone": "ng serve dev-timezone --port 3003",
261256
"dev:title": "ng serve dev-title --port 3003",
262257
"dev:validation": "ng serve dev-validation --port 3003",
263-
"dev:z-index": "ng serve dev-z-index --port 3003"
258+
"dev:z-index": "ng serve dev-z-index --port 3003",
259+
"-----Unit Tests-----": "-------------------------------------------------------------------------------------",
260+
"unit:cdk": "ng test cdk",
261+
"unit:components": "ng test components && ng run components:karma-test",
262+
"unit:angular-moment-adapter": "ng test angular-moment-adapter",
263+
"unit:angular-luxon-adapter": "ng test angular-luxon-adapter",
264+
"unit:schematics": "jest --roots packages/schematics"
264265
},
265266
"release": {
266267
"packages": [

packages/angular-luxon-adapter/adapter/date-adapter.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { LOCALE_ID } from '@angular/core';
2-
import { inject, TestBed, waitForAsync } from '@angular/core/testing';
2+
import { inject, TestBed } from '@angular/core/testing';
33
import { DateAdapter, KBQ_DATE_LOCALE, KBQ_LOCALE_SERVICE } from '@koobiq/components/core';
44
import { KBQ_LUXON_DATE_ADAPTER_OPTIONS, LuxonDateAdapter } from './date-adapter';
55
import { LuxonDateModule } from './index';
66

77
describe('LuxonDateAdapter with KBQ_DATE_LOCALE override', () => {
88
let adapter: LuxonDateAdapter;
99

10-
beforeEach(waitForAsync(() => {
10+
beforeEach(() => {
1111
TestBed.configureTestingModule({
1212
imports: [LuxonDateModule],
1313
providers: [
1414
{ provide: KBQ_DATE_LOCALE, useValue: 'es-LA' },
1515
{ provide: KBQ_LOCALE_SERVICE, useValue: null }
1616
]
1717
}).compileComponents();
18-
}));
18+
});
1919

2020
beforeEach(inject([DateAdapter], (d: LuxonDateAdapter) => {
2121
adapter = d;
@@ -29,15 +29,15 @@ describe('LuxonDateAdapter with KBQ_DATE_LOCALE override', () => {
2929
describe('LuxonDateAdapter with LOCALE_ID override', () => {
3030
let adapter: LuxonDateAdapter;
3131

32-
beforeEach(waitForAsync(() => {
32+
beforeEach(() => {
3333
TestBed.configureTestingModule({
3434
imports: [LuxonDateModule],
3535
providers: [
3636
{ provide: LOCALE_ID, useValue: 'es-LA' },
3737
{ provide: KBQ_LOCALE_SERVICE, useValue: null }
3838
]
3939
}).compileComponents();
40-
}));
40+
});
4141

4242
beforeEach(inject([DateAdapter], (d: LuxonDateAdapter) => {
4343
adapter = d;
@@ -51,7 +51,7 @@ describe('LuxonDateAdapter with LOCALE_ID override', () => {
5151
describe('LuxonDateAdapter with KBQ_LUXON_DATE_ADAPTER_OPTIONS override', () => {
5252
let adapter: LuxonDateAdapter;
5353

54-
beforeEach(waitForAsync(() => {
54+
beforeEach(() => {
5555
TestBed.configureTestingModule({
5656
imports: [LuxonDateModule],
5757
providers: [
@@ -62,7 +62,7 @@ describe('LuxonDateAdapter with KBQ_LUXON_DATE_ADAPTER_OPTIONS override', () =>
6262
{ provide: KBQ_LOCALE_SERVICE, useValue: null }
6363
]
6464
}).compileComponents();
65-
}));
65+
});
6666

6767
beforeEach(inject([DateAdapter], (d: LuxonDateAdapter) => {
6868
adapter = d;

packages/angular-moment-adapter/adapter/moment-date-adapter.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { LOCALE_ID } from '@angular/core';
2-
import { inject, TestBed, waitForAsync } from '@angular/core/testing';
2+
import { inject, TestBed } from '@angular/core/testing';
33
import { DateAdapter, KBQ_DATE_LOCALE, KBQ_LOCALE_SERVICE } from '@koobiq/components/core';
44
import moment from 'moment';
55

@@ -11,15 +11,15 @@ const JAN = 0;
1111
describe('MomentDateAdapter with KBQ_DATE_LOCALE override', () => {
1212
let adapter: MomentDateAdapter;
1313

14-
beforeEach(waitForAsync(() => {
14+
beforeEach(() => {
1515
TestBed.configureTestingModule({
1616
imports: [MomentDateModule],
1717
providers: [
1818
{ provide: KBQ_DATE_LOCALE, useValue: 'en-US' },
1919
{ provide: KBQ_LOCALE_SERVICE, useValue: null }
2020
]
2121
}).compileComponents();
22-
}));
22+
});
2323

2424
beforeEach(inject([DateAdapter], (d: MomentDateAdapter) => {
2525
adapter = d;
@@ -33,15 +33,15 @@ describe('MomentDateAdapter with KBQ_DATE_LOCALE override', () => {
3333
describe('MomentDateAdapter with LOCALE_ID override', () => {
3434
let adapter: MomentDateAdapter;
3535

36-
beforeEach(waitForAsync(() => {
36+
beforeEach(() => {
3737
TestBed.configureTestingModule({
3838
imports: [MomentDateModule],
3939
providers: [
4040
{ provide: LOCALE_ID, useValue: 'en-US' },
4141
{ provide: KBQ_LOCALE_SERVICE, useValue: null }
4242
]
4343
}).compileComponents();
44-
}));
44+
});
4545

4646
beforeEach(inject([DateAdapter], (d: MomentDateAdapter) => {
4747
adapter = d;
@@ -55,7 +55,7 @@ describe('MomentDateAdapter with LOCALE_ID override', () => {
5555
describe('MomentDateAdapter with KBQ_MOMENT_DATE_ADAPTER_OPTIONS override', () => {
5656
let adapter: MomentDateAdapter;
5757

58-
beforeEach(waitForAsync(() => {
58+
beforeEach(() => {
5959
TestBed.configureTestingModule({
6060
imports: [MomentDateModule],
6161
providers: [
@@ -66,7 +66,7 @@ describe('MomentDateAdapter with KBQ_MOMENT_DATE_ADAPTER_OPTIONS override', () =
6666
{ provide: KBQ_LOCALE_SERVICE, useValue: null }
6767
]
6868
}).compileComponents();
69-
}));
69+
});
7070

7171
beforeEach(inject([DateAdapter], (d: MomentDateAdapter) => {
7272
adapter = d;

packages/components/alert/alert.component.spec.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
import { Component, DebugElement } from '@angular/core';
2-
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
2+
import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { KbqAlert, KbqAlertModule } from './index';
55

66
describe('MсAlert', () => {
77
let fixture: ComponentFixture<TestApp>;
88
let alertDebugElement: DebugElement;
99
let alertNativeElement: HTMLElement;
10-
// let testComponent: TestApp;
1110

12-
beforeEach(fakeAsync(() => {
11+
beforeEach(() => {
1312
TestBed.configureTestingModule({
1413
imports: [KbqAlertModule],
1514
declarations: [TestApp]
16-
});
17-
18-
TestBed.compileComponents();
15+
}).compileComponents();
1916

2017
fixture = TestBed.createComponent(TestApp);
2118
fixture.detectChanges();
2219

2320
alertDebugElement = fixture.debugElement.query(By.directive(KbqAlert));
2421
alertNativeElement = alertDebugElement.nativeElement;
25-
// testComponent = fixture.debugElement.componentInstance;
26-
}));
22+
});
2723

2824
it('should add class', () => {
2925
expect(alertNativeElement.classList.contains('kbq-alert')).toBe(true);

0 commit comments

Comments
 (0)