Skip to content

Commit

Permalink
Merge pull request #3 from alexfriesen/jest-setup
Browse files Browse the repository at this point in the history
✨ add jest
  • Loading branch information
alexfriesen authored Nov 28, 2023
2 parents 6888ea2 + d29bbde commit d625761
Show file tree
Hide file tree
Showing 40 changed files with 3,609 additions and 2,550 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ jobs:
cache: 'npm'
- run: npm i -g yarn
- run: yarn --check-files
- run: npm run build
- run: yarn build
- run: yarn test
31 changes: 0 additions & 31 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@
},
"defaultConfiguration": "production"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"tsConfig": "projects/ngx-mat-timepicker/tsconfig.spec.json",
"karmaConfig": "projects/ngx-mat-timepicker/karma.conf.js",
"polyfills": [
"zone.js",
"zone.js/testing"
]
}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
Expand Down Expand Up @@ -132,26 +121,6 @@
"buildTarget": "demo:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "projects/demo/tsconfig.spec.json",
"karmaConfig": "projects/demo/karma.conf.js",
"inlineStyleLanguage": "scss",
"assets": [
"projects/demo/src/favicon.ico",
"projects/demo/src/assets"
],
"styles": [
"projects/demo/src/styles.scss"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
Expand Down
29 changes: 29 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Config } from 'jest';
import { pathsToModuleNameMapper } from 'ts-jest';
import { compilerOptions } from './tsconfig.json';

const config: Config = {
clearMocks: true,
collectCoverage: true,
coverageProvider: 'v8',
preset: 'jest-preset-angular',
testEnvironment: 'jsdom',

projects: ['<rootDir>/projects/*'],

roots: ['<rootDir>'],
modulePaths: ['<rootDir>/../..'],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths),
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
useESM: true,
},
],
},
};

export default config;
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"test": "ng test",
"test": "jest",
"test:lib": "jest --projects ./projects/ngx-mat-timepicker",
"test:demo": "jest --projects ./projects/demo",
"build": "ng build ngx-mat-timepicker --configuration=production",
"build:demo": "ng build demo --configuration=production",
"build:demo:gh-pages": "yarn build:demo --base-href https://alexfriesen.github.io/ngx-mat-timepicker/",
Expand Down Expand Up @@ -63,26 +65,22 @@
"@angular/language-service": "^17.0.0",
"@fontsource/material-icons": "^5.0.7",
"@fontsource/roboto": "^5.0.8",
"@types/jasmine": "~4.0.0",
"@types/jasminewd2": "~2.0.3",
"@types/jest": "^29.5.10",
"@types/node": "^18.0.0",
"@types/prismjs": "^1.26.0",
"@typescript-eslint/eslint-plugin": "6.11.0",
"@typescript-eslint/parser": "6.11.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"jasmine-core": "~4.1.0",
"jasmine-spec-reporter": "~7.0.0",
"karma": "~6.3.20",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-preset-angular": "^13.1.4",
"ng-packagr": "^17.0.0",
"prettier": "^3.1.0",
"prismjs": "^1.29.0",
"semver": "^7.3.8",
"ts-jest": "^29.1.1",
"ts-node": "~10.9.1",
"typescript": "~5.2.2"
},
Expand Down
12 changes: 12 additions & 0 deletions projects/demo/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Config } from 'jest';
import baseConfig from '../../jest.config';

const config: Config = {
...baseConfig,
displayName: 'demo',
roots: ['<rootDir>'],
coverageDirectory: '<rootDir>/../../coverage/demo',
setupFilesAfterEnv: ['<rootDir>/src/setup-jest.ts'],
};

export default config;
44 changes: 0 additions & 44 deletions projects/demo/karma.conf.js

This file was deleted.

8 changes: 7 additions & 1 deletion projects/demo/src/app/components/demo/demo.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
overflow: hidden;
z-index: 2;

--mat-toolbar-mobile-height: 80px;

> div {
display: flex;
align-items: center;
Expand Down Expand Up @@ -51,6 +53,10 @@
padding-left: 8px;
padding-right: 8px;
}

@include respond-below(xxs) {
flex-direction: column;
}
}

.ngx-mtp-github-logo {
Expand Down Expand Up @@ -178,7 +184,7 @@ footer {
}

.terminal::before {
content: '\2022 \2022 \2022';
content: "\2022 \2022 \2022";
position: absolute;
z-index: 1;
top: 0;
Expand Down
31 changes: 31 additions & 0 deletions projects/demo/src/app/components/demo/demo.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DemoComponent } from './demo.component';
import { MatNativeDateModule, NativeDateModule } from '@angular/material/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

describe('DemoComponent', () => {
let component: DemoComponent;
let fixture: ComponentFixture<DemoComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
NativeDateModule,
MatNativeDateModule,

DemoComponent,
],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(DemoComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
21 changes: 5 additions & 16 deletions projects/demo/src/scss/responsive.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$breakpoints: (
xxs: 360px,
xs: 768px,
sm: 992px,
md: 1200px,
lg: 1920px
xxs: 480px,
xs: 768px,
sm: 992px,
md: 1200px,
lg: 1920px,
);

//
Expand All @@ -12,10 +12,8 @@ $breakpoints: (

// e.g. @include respond-above(sm) {}
@mixin respond-above($breakpoint) {

// If the breakpoint exists in the map.
@if map-has-key($breakpoints, $breakpoint) {

// Get the breakpoint value.
$breakpoint-value: map-get($breakpoints, $breakpoint);

Expand All @@ -26,7 +24,6 @@ $breakpoints: (

// If the breakpoint doesn't exist in the map.
} @else {

// Log a warning.
@warn 'Invalid breakpoint: #{$breakpoint}.';
}
Expand All @@ -38,10 +35,8 @@ $breakpoints: (

// e.g. @include respond-below(sm) {}
@mixin respond-below($breakpoint) {

// If the breakpoint exists in the map.
@if map-has-key($breakpoints, $breakpoint) {

// Get the breakpoint value.
$breakpoint-value: map-get($breakpoints, $breakpoint);

Expand All @@ -52,7 +47,6 @@ $breakpoints: (

// If the breakpoint doesn't exist in the map.
} @else {

// Log a warning.
@warn 'Invalid breakpoint: #{$breakpoint}.';
}
Expand All @@ -64,10 +58,8 @@ $breakpoints: (

// e.g. @include respond-between(sm, md) {}
@mixin respond-between($lower, $upper) {

// If both the lower and upper breakpoints exist in the map.
@if map-has-key($breakpoints, $lower) and map-has-key($breakpoints, $upper) {

// Get the lower and upper breakpoints.
$lower-breakpoint: map-get($breakpoints, $lower);
$upper-breakpoint: map-get($breakpoints, $upper);
Expand All @@ -79,17 +71,14 @@ $breakpoints: (

// If one or both of the breakpoints don't exist.
} @else {

// If lower breakpoint is invalid.
@if (map-has-key($breakpoints, $lower) == false) {

// Log a warning.
@warn 'Your lower breakpoint was invalid: #{$lower}.';
}

// If upper breakpoint is invalid.
@if (map-has-key($breakpoints, $upper) == false) {

// Log a warning.
@warn 'Your upper breakpoint was invalid: #{$upper}.';
}
Expand Down
1 change: 1 addition & 0 deletions projects/demo/src/setup-jest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'jest-preset-angular/setup-jest';
19 changes: 0 additions & 19 deletions projects/demo/src/test.ts

This file was deleted.

12 changes: 7 additions & 5 deletions projects/demo/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine"
]
"jest",
"node"
],
},
"files": [
"src/test.ts"
"src/test-setup.ts"
],
"include": [
"jest.config.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
],
}
11 changes: 11 additions & 0 deletions projects/ngx-mat-timepicker/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Config } from 'jest';
import baseConfig from '../../jest.config';

const config: Config = {
...baseConfig,
displayName: 'ngx-mat-timepicker',
coverageDirectory: '<rootDir>/../../coverage/ngx-mat-timepicker',
setupFilesAfterEnv: ['<rootDir>/src/setup-jest.ts'],
};

export default config;
Loading

0 comments on commit d625761

Please sign in to comment.