Skip to content
Closed
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
18 changes: 11 additions & 7 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@
"build": {
"builder": "@angular/build:ng-packagr",
"options": {
"tsConfig": "libs/core/tsconfig.lib.json",
"project": "libs/core/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "libs/core/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "libs/core/tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"builder": "@angular-devkit/build-angular:jest",
"builder": "@angular/build:unit-test",
"options": {
"tsConfig": "tsconfig.spec.json",
"polyfills": ["zone.js", "zone.js/testing"]
"runner": "vitest"
}
}
}
Expand All @@ -40,21 +42,23 @@
"build": {
"builder": "@angular/build:ng-packagr",
"options": {
"project": "libs/components/ng-package.json",
"tsConfig": "libs/components/tsconfig.lib.json"
"project": "libs/components/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "libs/components/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "libs/components/tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"builder": "@angular-devkit/build-angular:jest",
"builder": "@angular/build:unit-test",
"options": {
"tsConfig": "tsconfig.spec.json",
"polyfills": ["zone.js", "zone.js/testing"]
"runner": "vitest"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/components/eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"count": 17
}
}
}
}
8 changes: 8 additions & 0 deletions libs/components/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ export default defineScAngularConfig(
'no-undef': 'off',
},
},
{
files: ['**/*.spec.ts', '**/*.test.ts'],
rules: {
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
}
}
)
4 changes: 0 additions & 4 deletions libs/components/jest.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion libs/components/tsconfig.lint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"paths": {
"@shiftcode/ngx-core": ["../core/src/public-api.ts"]
},
"types": ["jest", "node"]
"types": ["node"]
}
}
5 changes: 3 additions & 2 deletions libs/components/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.spec.json",
"compilerOptions": {
"types": ["jest", "node"]
}
"baseUrl": "."
},
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}
30 changes: 1 addition & 29 deletions libs/core/eslint-suppressions.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
{
"src/lib/http/http-date.interceptor.spec.ts": {
"@typescript-eslint/no-unsafe-member-access": {
"count": 2
}
},
"src/lib/local-storage/local-storage.service.spec.ts": {
"@typescript-eslint/no-unsafe-member-access": {
"count": 2
},
"@typescript-eslint/no-unsafe-return": {
"count": 1
}
},
"src/lib/logger/cloudwatch/cloud-watch.service.ts": {
"@typescript-eslint/no-unsafe-return": {
"count": 2
Expand All @@ -22,11 +9,6 @@
"count": 4
}
},
"src/lib/logger/logger.service.spec.ts": {
"@typescript-eslint/no-unsafe-member-access": {
"count": 4
}
},
"src/lib/static-utils/jwt-helper.ts": {
"@typescript-eslint/no-unsafe-call": {
"count": 2
Expand All @@ -38,21 +20,11 @@
"count": 2
}
},
"src/lib/static-utils/rxjs/filter-if-instance-of.operator.spec.ts": {
"@typescript-eslint/no-unsafe-member-access": {
"count": 1
}
},
"src/lib/static-utils/rxjs/filter-if-instance-of.operator.ts": {
"@typescript-eslint/no-unsafe-return": {
"count": 1
}
},
"src/lib/static-utils/rxjs/filter-if-truthy.operator.spec.ts": {
"@typescript-eslint/no-unsafe-return": {
"count": 1
}
},
"src/lib/static-utils/rxjs/tap-last.operator.ts": {
"@typescript-eslint/no-unsafe-call": {
"count": 1
Expand All @@ -64,4 +36,4 @@
"count": 1
}
}
}
}
8 changes: 8 additions & 0 deletions libs/core/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ export default defineScAngularConfig(
'no-undef': 'off',
},
},
{
files: ['**/*.spec.ts', '**/*.test.ts'],
rules: {
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
}
}
)
4 changes: 0 additions & 4 deletions libs/core/jest.config.js

This file was deleted.

9 changes: 5 additions & 4 deletions libs/core/src/lib/http/http-date.interceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { HttpTestingController, provideHttpClientTesting } from '@angular/common
import { ClassProvider } from '@angular/core'
import { TestBed } from '@angular/core/testing'
import { firstValueFrom } from 'rxjs'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { HttpDateInterceptor } from './http-date.interceptor'

Expand All @@ -21,7 +22,7 @@ describe('HttpDateInterceptor', () => {
let interceptor: HttpDateInterceptor
let httpClient: HttpClient
let httpController: HttpTestingController
let mapResponseSpy: jest.SpyInstance
let mapResponseSpy: ReturnType<typeof vi.spyOn>

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -38,10 +39,10 @@ describe('HttpDateInterceptor', () => {

httpClient = TestBed.inject(HttpClient)
httpController = TestBed.inject(HttpTestingController)
mapResponseSpy = jest.spyOn(interceptor, 'mapResponse')
mapResponseSpy = vi.spyOn(interceptor, 'mapResponse')
})

test('maps dates on response 200', async () => {
it('maps dates on response 200', async () => {
const expected: any = {
createdAt: new Date(0),
nested: {
Expand All @@ -60,7 +61,7 @@ describe('HttpDateInterceptor', () => {
expect(response).toEqual(expected)
})

test('does not map when not json requested', async () => {
it('does not map when not json requested', async () => {
const request = firstValueFrom(httpClient.get('/test', { responseType: 'text' }))
httpController.expectOne('/test').flush('just text content', { headers: { 'Content-Type': 'text/plain' } })
await request
Expand Down
49 changes: 25 additions & 24 deletions libs/core/src/lib/local-storage/local-storage.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ClassProvider, ValueProvider } from '@angular/core'
import { TestBed } from '@angular/core/testing'
import { firstValueFrom, scan, shareReplay } from 'rxjs'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { MockStorage } from '../../../test'
import { WindowRef } from '../window/window-ref.service'
Expand All @@ -13,8 +14,8 @@ const prefix: LocalStorageOptions['prefix'] = 'TEST_'
function configureTestBed(options: LocalStorageOptions = { prefix }) {
class MockWindowRef {
readonly nativeWindow = {
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
localStorage: new MockStorage(),
}
}
Expand All @@ -34,20 +35,20 @@ function configureTestBed(options: LocalStorageOptions = { prefix }) {

describe('LocalStorage', () => {
let storage: MockStorage
let lsFnSpy: jest.SpyInstance<any, any>
let lsFnSpy: ReturnType<typeof vi.spyOn>
let service: LocalStorage

describe('observe', () => {
let win: WindowRef
let winSpy: jest.SpyInstance<any, any>
let winSpy: ReturnType<typeof vi.spyOn>
beforeEach(() => {
configureTestBed()
win = TestBed.inject(WindowRef)
winSpy = jest.spyOn(win.nativeWindow!, 'addEventListener')
winSpy = vi.spyOn(win.nativeWindow!, 'addEventListener')
storage = win.nativeWindow!.localStorage
service = TestBed.inject(LocalStorage)
})
test('only emits events of provided key with configured prefix', async () => {
it('only emits events of provided key with configured prefix', async () => {
expect(winSpy).toHaveBeenCalledTimes(0) // since its a cold observable

const key = 'ThisIsMyKey'
Expand All @@ -72,25 +73,25 @@ describe('LocalStorage', () => {
beforeEach(() => {
configureTestBed()
storage = TestBed.inject(WindowRef).nativeWindow!.localStorage
lsFnSpy = jest.spyOn(storage, 'setItem')
lsFnSpy = vi.spyOn(storage, 'setItem')
service = TestBed.inject(LocalStorage)
})

test('writes item by key with configured prefix', () => {
it('writes item by key with configured prefix', () => {
service.setItem('key', true)
expect(lsFnSpy).toHaveBeenCalledTimes(1)
expect(lsFnSpy).toHaveBeenCalledWith(`${prefix}key`, 'true')
})
test('stringifies value before storing', () => {
it('stringifies value before storing', () => {
const value = { a: true, b: 'ok' }
service.setItem('key', value)
expect(lsFnSpy).toHaveBeenCalledWith(`${prefix}key`, JSON.stringify(value))
})
test('sets null when undefined', () => {
it('sets null when undefined', () => {
service.setItem('key', undefined)
expect(lsFnSpy).toHaveBeenCalledWith(`${prefix}key`, JSON.stringify(null))
})
test('throws when no stringifyable value', () => {
it('throws when no stringifyable value', () => {
const x: any = { value: true }
x.x = x
expect(() => service.setItem('x', x)).toThrow(TypeError)
Expand All @@ -101,21 +102,21 @@ describe('LocalStorage', () => {
beforeEach(() => {
configureTestBed()
storage = TestBed.inject(WindowRef).nativeWindow!.localStorage
lsFnSpy = jest.spyOn(storage, 'getItem')
lsFnSpy = vi.spyOn(storage, 'getItem')
service = TestBed.inject(LocalStorage)
})

test('returns item by key with configured prefix', () => {
it('returns item by key with configured prefix', () => {
service.getItem('key')
expect(lsFnSpy).toHaveBeenCalledTimes(1)
expect(lsFnSpy).toHaveBeenCalledWith(`${prefix}key`)
})
test('parses value before returning', () => {
it('parses value before returning', () => {
const value = { ok: true, values: [] }
lsFnSpy.mockReturnValue(JSON.stringify(value))
expect(service.getItem('key')).toEqual(value)
})
test('returns null when not parsable', () => {
it('returns null when not parsable', () => {
lsFnSpy.mockReturnValue('this value is not parsable')
expect(service.getItem('key')).toEqual(null)
})
Expand All @@ -125,14 +126,14 @@ describe('LocalStorage', () => {
beforeEach(() => {
configureTestBed()
storage = TestBed.inject(WindowRef).nativeWindow!.localStorage
lsFnSpy = jest.spyOn(storage, 'removeItem')
lsFnSpy = vi.spyOn(storage, 'removeItem')
service = TestBed.inject(LocalStorage)
})
test('removes item by key with configured prefix', () => {
it('removes item by key with configured prefix', () => {
service.delete('key')
expect(lsFnSpy).toHaveBeenCalledWith(`${prefix}key`)
})
test('removes multiple items by keys with configured prefix', () => {
it('removes multiple items by keys with configured prefix', () => {
const keys = ['a', 'b', 'c', 'd']
service.delete(...keys)
expect(lsFnSpy).toHaveBeenCalledTimes(keys.length)
Expand All @@ -143,19 +144,19 @@ describe('LocalStorage', () => {
})

describe('clear', () => {
let lsClearSpy: jest.SpyInstance<any, any>
let lsClearSpy: ReturnType<typeof vi.spyOn>
beforeEach(() => {
configureTestBed()
storage = TestBed.inject(WindowRef).nativeWindow!.localStorage
lsFnSpy = jest.spyOn(storage, 'removeItem')
lsClearSpy = jest.spyOn(storage, 'clear')
lsFnSpy = vi.spyOn(storage, 'removeItem')
lsClearSpy = vi.spyOn(storage, 'clear')
service = TestBed.inject(LocalStorage)
})
test('does not use clear', () => {
it('does not use clear', () => {
service.clear()
expect(lsClearSpy).not.toHaveBeenCalled()
})
test('clears all keys starting with configured prefix', () => {
it('clears all keys starting with configured prefix', () => {
storage.setItem('keep_a', 'a')
storage.setItem(`${prefix}_a`, 'a')
storage.setItem(`${prefix}_b`, 'a')
Expand All @@ -174,7 +175,7 @@ describe('LocalStorage', () => {
storage = TestBed.inject(WindowRef).nativeWindow!.localStorage
service = TestBed.inject(LocalStorage)
})
test('returns all keys starting with configured prefix but removes prefix', () => {
it('returns all keys starting with configured prefix but removes prefix', () => {
const keys: string[] = ['a', 'b', 'c']
const prefixedKeys = keys.map((k) => `${prefix}${k}`)
storage.setItem('other_a', 'not-my-key')
Expand Down
6 changes: 4 additions & 2 deletions libs/core/src/lib/logger/helper/leading-zero.function.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { describe, expect,it } from 'vitest'

import { leadingZero } from './leading-zero.function'

describe('leadingZero', () => {
test('works', () => {
it('works', () => {
expect(leadingZero(2, 1)).toEqual('01')
expect(leadingZero(2, 22)).toEqual('22')
expect(leadingZero(2, 333)).toEqual('33')
Expand All @@ -17,7 +19,7 @@ describe('leadingZero', () => {
expect(leadingZero(4, 4444)).toEqual('4444')
expect(leadingZero(4, 55555)).toEqual('5555')
})
test('rounds decimal values', () => {
it('rounds decimal values', () => {
expect(leadingZero(2, 1.3)).toEqual('01')
expect(leadingZero(2, 5.8)).toEqual('06')
})
Expand Down
Loading
Loading