diff --git a/templates/app-nolayers/angular/angular.json b/templates/app-nolayers/angular/angular.json index 0a99a4c08a4..81d536178ae 100644 --- a/templates/app-nolayers/angular/angular.json +++ b/templates/app-nolayers/angular/angular.json @@ -163,17 +163,7 @@ } }, "test": { - "builder": "@angular/build:karma", - "options": { - "browser": "src/test.ts", - "polyfills": ["src/polyfills.ts"], - "tsConfig": "tsconfig.spec.json", - "karmaConfig": "karma.conf.js", - "inlineStyleLanguage": "scss", - "assets": ["src/favicon.ico", "src/assets"], - "styles": ["src/styles.scss"], - "scripts": [] - } + "builder": "@angular/build:unit-test" }, "lint": { "builder": "@angular-eslint/builder:lint", diff --git a/templates/app-nolayers/angular/karma.conf.js b/templates/app-nolayers/angular/karma.conf.js deleted file mode 100644 index b06ddef227a..00000000000 --- a/templates/app-nolayers/angular/karma.conf.js +++ /dev/null @@ -1,44 +0,0 @@ -// Karma configuration file, see link for more information -// https://karma-runner.github.io/1.0/config/configuration-file.html - -module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine', '@angular-devkit/build-angular'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage'), - - ], - client: { - jasmine: { - // you can add configuration options for Jasmine here - // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html - // for example, you can disable the random execution with `random: false` - // or set a specific seed with `seed: 4321` - }, - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, - jasmineHtmlReporter: { - suppressAll: true // removes the duplicated traces - }, - coverageReporter: { - dir: require('path').join(__dirname, './coverage/MyProjectName'), - subdir: '.', - reporters: [ - { type: 'html' }, - { type: 'text-summary' } - ] - }, - reporters: ['progress', 'kjhtml'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - browsers: ['Chrome'], - singleRun: false, - restartOnFileChange: true - }); -}; diff --git a/templates/app-nolayers/angular/package.json b/templates/app-nolayers/angular/package.json index af876d60789..9defcbc937a 100644 --- a/templates/app-nolayers/angular/package.json +++ b/templates/app-nolayers/angular/package.json @@ -47,17 +47,12 @@ "@angular/cli": "~21.0.0", "@angular/compiler-cli": "~21.0.0", "@angular/language-service": "~21.0.0", - "@types/jasmine": "~3.6.0", "@types/node": "^12.11.1", "@typescript-eslint/eslint-plugin": "7.16.0", "@typescript-eslint/parser": "7.16.0", "eslint": "^8.0.0", - "jasmine-core": "~4.0.0", - "karma": "~6.4.4", - "karma-chrome-launcher": "~3.1.0", - "karma-coverage": "~2.1.0", - "karma-jasmine": "~4.0.0", - "karma-jasmine-html-reporter": "^1.7.0", - "typescript": "~5.9.0" + "jsdom": "^27.1.0", + "typescript": "~5.9.0", + "vitest": "^4.0.0" } } \ No newline at end of file diff --git a/templates/app-nolayers/angular/src/app/home/home.component.spec.ts b/templates/app-nolayers/angular/src/app/home/home.component.spec.ts index 9fb41df29ac..ea07d9ad362 100644 --- a/templates/app-nolayers/angular/src/app/home/home.component.spec.ts +++ b/templates/app-nolayers/angular/src/app/home/home.component.spec.ts @@ -1,54 +1,52 @@ import { CoreTestingModule } from '@abp/ng.core/testing'; import { ThemeSharedTestingModule } from '@abp/ng.theme.shared/testing'; -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { NgxValidateCoreModule } from '@ngx-validate/core'; import { HomeComponent } from './home.component'; -import { OAuthService } from 'angular-oauth2-oidc'; import { AuthService } from '@abp/ng.core'; +import { vi } from 'vitest'; describe('HomeComponent', () => { let fixture: ComponentFixture; - const mockOAuthService = jasmine.createSpyObj('OAuthService', ['hasValidAccessToken']); - const mockAuthService = jasmine.createSpyObj('AuthService', ['navigateToLogin']); - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [HomeComponent], + let mockAuthService: { isAuthenticated: boolean; navigateToLogin: ReturnType }; + + beforeEach(async () => { + mockAuthService = { + isAuthenticated: false, + navigateToLogin: vi.fn(), + }; + + await TestBed.configureTestingModule({ imports: [ CoreTestingModule.withConfig(), ThemeSharedTestingModule.withConfig(), NgxValidateCoreModule, + HomeComponent, ], providers: [ - /* mock providers here */ - { - provide: OAuthService, - useValue: mockOAuthService, - }, { provide: AuthService, useValue: mockAuthService, }, ], }).compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(HomeComponent); - fixture.detectChanges(); }); it('should be initiated', () => { + fixture = TestBed.createComponent(HomeComponent); + fixture.detectChanges(); expect(fixture.componentInstance).toBeTruthy(); }); describe('when login state is true', () => { - beforeAll(() => { - mockOAuthService.hasValidAccessToken.and.returnValue(true); + beforeEach(() => { + mockAuthService.isAuthenticated = true; + fixture = TestBed.createComponent(HomeComponent); + fixture.detectChanges(); }); it('hasLoggedIn should be true', () => { - expect(fixture.componentInstance.hasLoggedIn).toBeTrue(); - expect(mockOAuthService.hasValidAccessToken).toHaveBeenCalled(); + expect(fixture.componentInstance.hasLoggedIn).toBe(true); }); it('button should not be exists', () => { diff --git a/templates/app-nolayers/angular/src/test.ts b/templates/app-nolayers/angular/src/test.ts deleted file mode 100644 index 3b701bbfa08..00000000000 --- a/templates/app-nolayers/angular/src/test.ts +++ /dev/null @@ -1,13 +0,0 @@ -// This file is required by karma.conf.js and loads recursively all the .spec and framework files -import 'zone.js/testing'; -import { getTestBed } from '@angular/core/testing'; -import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting, -} from '@angular/platform-browser-dynamic/testing'; - -// First, initialize the Angular testing environment. -getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting() -); diff --git a/templates/app-nolayers/angular/tsconfig.app.json b/templates/app-nolayers/angular/tsconfig.app.json index 82d91dc4a4d..264f459bf87 100644 --- a/templates/app-nolayers/angular/tsconfig.app.json +++ b/templates/app-nolayers/angular/tsconfig.app.json @@ -1,15 +1,15 @@ -/* To learn more about this file see: https://angular.io/config/tsconfig. */ +/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */ +/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */ { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/app", "types": [] }, - "files": [ - "src/main.ts", - "src/polyfills.ts" - ], "include": [ - "src/**/*.d.ts" + "src/**/*.ts" + ], + "exclude": [ + "src/**/*.spec.ts" ] } diff --git a/templates/app-nolayers/angular/tsconfig.spec.json b/templates/app-nolayers/angular/tsconfig.spec.json index 092345b02e8..d38370633f6 100644 --- a/templates/app-nolayers/angular/tsconfig.spec.json +++ b/templates/app-nolayers/angular/tsconfig.spec.json @@ -1,18 +1,15 @@ -/* To learn more about this file see: https://angular.io/config/tsconfig. */ +/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */ +/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */ { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/spec", "types": [ - "jasmine" + "vitest/globals" ] }, - "files": [ - "src/test.ts", - "src/polyfills.ts" - ], "include": [ - "src/**/*.spec.ts", - "src/**/*.d.ts" + "src/**/*.d.ts", + "src/**/*.spec.ts" ] } diff --git a/templates/app/angular/angular.json b/templates/app/angular/angular.json index 0a99a4c08a4..81d536178ae 100644 --- a/templates/app/angular/angular.json +++ b/templates/app/angular/angular.json @@ -163,17 +163,7 @@ } }, "test": { - "builder": "@angular/build:karma", - "options": { - "browser": "src/test.ts", - "polyfills": ["src/polyfills.ts"], - "tsConfig": "tsconfig.spec.json", - "karmaConfig": "karma.conf.js", - "inlineStyleLanguage": "scss", - "assets": ["src/favicon.ico", "src/assets"], - "styles": ["src/styles.scss"], - "scripts": [] - } + "builder": "@angular/build:unit-test" }, "lint": { "builder": "@angular-eslint/builder:lint", diff --git a/templates/app/angular/karma.conf.js b/templates/app/angular/karma.conf.js deleted file mode 100644 index b06ddef227a..00000000000 --- a/templates/app/angular/karma.conf.js +++ /dev/null @@ -1,44 +0,0 @@ -// Karma configuration file, see link for more information -// https://karma-runner.github.io/1.0/config/configuration-file.html - -module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine', '@angular-devkit/build-angular'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage'), - - ], - client: { - jasmine: { - // you can add configuration options for Jasmine here - // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html - // for example, you can disable the random execution with `random: false` - // or set a specific seed with `seed: 4321` - }, - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, - jasmineHtmlReporter: { - suppressAll: true // removes the duplicated traces - }, - coverageReporter: { - dir: require('path').join(__dirname, './coverage/MyProjectName'), - subdir: '.', - reporters: [ - { type: 'html' }, - { type: 'text-summary' } - ] - }, - reporters: ['progress', 'kjhtml'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - browsers: ['Chrome'], - singleRun: false, - restartOnFileChange: true - }); -}; diff --git a/templates/app/angular/package.json b/templates/app/angular/package.json index 189c15b007f..7db07dea443 100644 --- a/templates/app/angular/package.json +++ b/templates/app/angular/package.json @@ -47,17 +47,12 @@ "@angular/cli": "~21.0.0", "@angular/compiler-cli": "~21.0.0", "@angular/language-service": "~21.0.0", - "@types/jasmine": "~3.6.0", "@types/node": "~20.11.0", "@typescript-eslint/eslint-plugin": "7.16.0", "@typescript-eslint/parser": "7.16.0", "eslint": "^8.0.0", - "jasmine-core": "~4.0.0", - "karma": "~6.4.4", - "karma-chrome-launcher": "~3.1.0", - "karma-coverage": "~2.1.0", - "karma-jasmine": "~4.0.0", - "karma-jasmine-html-reporter": "^1.7.0", - "typescript": "~5.9.3" + "jsdom": "^27.1.0", + "typescript": "~5.9.3", + "vitest": "^4.0.0" } -} \ No newline at end of file +} \ No newline at end of file diff --git a/templates/app/angular/src/app/home/home.component.html b/templates/app/angular/src/app/home/home.component.html index 83f1f9619ea..e3ffd708c1b 100644 --- a/templates/app/angular/src/app/home/home.component.html +++ b/templates/app/angular/src/app/home/home.component.html @@ -1,5 +1,4 @@
-
diff --git a/templates/app/angular/src/app/home/home.component.spec.ts b/templates/app/angular/src/app/home/home.component.spec.ts index 2243bfca921..4efbb17f0d1 100644 --- a/templates/app/angular/src/app/home/home.component.spec.ts +++ b/templates/app/angular/src/app/home/home.component.spec.ts @@ -1,98 +1,88 @@ import { CoreTestingModule } from "@abp/ng.core/testing"; import { ThemeSharedTestingModule } from "@abp/ng.theme.shared/testing"; -import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing"; +import { ComponentFixture, TestBed } from "@angular/core/testing"; import { NgxValidateCoreModule } from "@ngx-validate/core"; import { HomeComponent } from "./home.component"; -import { OAuthService } from 'angular-oauth2-oidc'; import { AuthService } from '@abp/ng.core'; +import { vi } from 'vitest'; describe("HomeComponent", () => { let fixture: ComponentFixture; - const mockOAuthService = jasmine.createSpyObj('OAuthService', ['hasValidAccessToken']) - const mockAuthService = jasmine.createSpyObj('AuthService', ['navigateToLogin']) - beforeEach( - waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [], - imports: [ - CoreTestingModule.withConfig(), - ThemeSharedTestingModule.withConfig(), - NgxValidateCoreModule, - HomeComponent - ], - providers: [ - /* mock providers here */ - { - provide: OAuthService, - useValue: mockOAuthService - }, - { - provide: AuthService, - useValue: mockAuthService - } - ], - }).compileComponents(); - }) - ); - - beforeEach(() => { - fixture = TestBed.createComponent(HomeComponent); - fixture.detectChanges(); + let mockAuthService: { isAuthenticated: boolean; navigateToLogin: ReturnType }; + + beforeEach(async () => { + mockAuthService = { + isAuthenticated: false, + navigateToLogin: vi.fn() + }; + + await TestBed.configureTestingModule({ + imports: [ + CoreTestingModule.withConfig(), + ThemeSharedTestingModule.withConfig(), + NgxValidateCoreModule, + HomeComponent + ], + providers: [ + { + provide: AuthService, + useValue: mockAuthService + } + ], + }).compileComponents(); }); it("should be initiated", () => { + fixture = TestBed.createComponent(HomeComponent); + fixture.detectChanges(); expect(fixture.componentInstance).toBeTruthy(); }); - - describe('when login state is true', () => { - beforeAll(() => { - mockOAuthService.hasValidAccessToken.and.returnValue(true) + beforeEach(() => { + mockAuthService.isAuthenticated = true; + fixture = TestBed.createComponent(HomeComponent); + fixture.detectChanges(); }); it("hasLoggedIn should be true", () => { - - expect(fixture.componentInstance.hasLoggedIn).toBeTrue(); - expect(mockOAuthService.hasValidAccessToken).toHaveBeenCalled() - }) + expect(fixture.componentInstance.hasLoggedIn).toBe(true); + }); it("button should not be exists", () => { - const element = fixture.nativeElement - const button = element.querySelector('[role="button"]') - expect(button).toBeNull() - }) - - }) + const element = fixture.nativeElement; + const button = element.querySelector('[role="button"]'); + expect(button).toBeNull(); + }); + }); describe('when login state is false', () => { - beforeAll(() => { - mockOAuthService.hasValidAccessToken.and.returnValue(false) + beforeEach(() => { + mockAuthService.isAuthenticated = false; + fixture = TestBed.createComponent(HomeComponent); + fixture.detectChanges(); }); it("hasLoggedIn should be false", () => { - - expect(fixture.componentInstance.hasLoggedIn).toBeFalse(); - expect(mockOAuthService.hasValidAccessToken).toHaveBeenCalled() - }) + expect(fixture.componentInstance.hasLoggedIn).toBe(false); + }); it("button should be exists", () => { - const element = fixture.nativeElement - const button = element.querySelector('[role="button"]') - expect(button).toBeDefined() - }) - describe('when button clicked', () => { + const element = fixture.nativeElement; + const button = element.querySelector('[role="button"]'); + expect(button).toBeDefined(); + }); + describe('when button clicked', () => { beforeEach(() => { - const element = fixture.nativeElement - const button = element.querySelector('[role="button"]') - button.click() + const element = fixture.nativeElement; + const button = element.querySelector('[role="button"]'); + button.click(); }); it("navigateToLogin have been called", () => { - expect(mockAuthService.navigateToLogin).toHaveBeenCalled() - }) - }) - }) - + expect(mockAuthService.navigateToLogin).toHaveBeenCalled(); + }); + }); + }); }); diff --git a/templates/app/angular/src/test.ts b/templates/app/angular/src/test.ts deleted file mode 100644 index 3b701bbfa08..00000000000 --- a/templates/app/angular/src/test.ts +++ /dev/null @@ -1,13 +0,0 @@ -// This file is required by karma.conf.js and loads recursively all the .spec and framework files -import 'zone.js/testing'; -import { getTestBed } from '@angular/core/testing'; -import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting, -} from '@angular/platform-browser-dynamic/testing'; - -// First, initialize the Angular testing environment. -getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting() -); diff --git a/templates/app/angular/tsconfig.app.json b/templates/app/angular/tsconfig.app.json index 82d91dc4a4d..264f459bf87 100644 --- a/templates/app/angular/tsconfig.app.json +++ b/templates/app/angular/tsconfig.app.json @@ -1,15 +1,15 @@ -/* To learn more about this file see: https://angular.io/config/tsconfig. */ +/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */ +/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */ { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/app", "types": [] }, - "files": [ - "src/main.ts", - "src/polyfills.ts" - ], "include": [ - "src/**/*.d.ts" + "src/**/*.ts" + ], + "exclude": [ + "src/**/*.spec.ts" ] } diff --git a/templates/app/angular/tsconfig.spec.json b/templates/app/angular/tsconfig.spec.json index 092345b02e8..d38370633f6 100644 --- a/templates/app/angular/tsconfig.spec.json +++ b/templates/app/angular/tsconfig.spec.json @@ -1,18 +1,15 @@ -/* To learn more about this file see: https://angular.io/config/tsconfig. */ +/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */ +/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */ { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/spec", "types": [ - "jasmine" + "vitest/globals" ] }, - "files": [ - "src/test.ts", - "src/polyfills.ts" - ], "include": [ - "src/**/*.spec.ts", - "src/**/*.d.ts" + "src/**/*.d.ts", + "src/**/*.spec.ts" ] } diff --git a/templates/module/angular/angular.json b/templates/module/angular/angular.json index 8c1b576257c..62b319d275e 100644 --- a/templates/module/angular/angular.json +++ b/templates/module/angular/angular.json @@ -28,12 +28,7 @@ "defaultConfiguration": "production" }, "test": { - "builder": "@angular/build:karma", - "options": { - "main": "projects/my-project-name/src/test.ts", - "tsConfig": "projects/my-project-name/tsconfig.spec.json", - "karmaConfig": "projects/my-project-name/karma.conf.js" - } + "builder": "@angular/build:unit-test" }, "lint": { "builder": "@angular-eslint/builder:lint", @@ -157,25 +152,7 @@ } }, "test": { - "builder": "@angular/build:karma", - "options": { - "browser": "projects/dev-app/src/test.ts", - "polyfills": ["projects/dev-app/src/polyfills.ts"], - "tsConfig": "projects/dev-app/tsconfig.spec.json", - "karmaConfig": "projects/dev-app/karma.conf.js", - "inlineStyleLanguage": "scss", - "assets": ["projects/dev-app/src/favicon.ico", "projects/dev-app/src/assets"], - "styles": [ - "node_modules/bootstrap/dist/css/bootstrap.min.css", - "node_modules/@fortawesome/fontawesome-free/css/all.min.css", - "node_modules/@fortawesome/fontawesome-free/css/v4-shims.min.css", - "node_modules/@swimlane/ngx-datatable/index.css", - "node_modules/@swimlane/ngx-datatable/assets/icons.css", - "node_modules/@swimlane/ngx-datatable/themes/material.css", - "projects/dev-app/src/styles.scss" - ], - "scripts": [] - } + "builder": "@angular/build:unit-test" }, "lint": { "builder": "@angular-eslint/builder:lint", diff --git a/templates/module/angular/package.json b/templates/module/angular/package.json index 8ae49e80fa1..d774e58b88e 100644 --- a/templates/module/angular/package.json +++ b/templates/module/angular/package.json @@ -47,19 +47,14 @@ "@angular/cli": "~21.0.0", "@angular/compiler-cli": "~21.0.0", "@angular/language-service": "~21.0.0", - "@types/jasmine": "~3.6.0", "@types/node": "^12.11.1", "@typescript-eslint/eslint-plugin": "7.16.0", "@typescript-eslint/parser": "7.16.0", "eslint": "^8.0.0", - "jasmine-core": "~4.0.0", - "karma": "~6.4.4", - "karma-chrome-launcher": "~3.1.0", - "karma-coverage": "~2.1.0", - "karma-jasmine": "~4.0.0", - "karma-jasmine-html-reporter": "^1.7.0", + "jsdom": "^27.1.0", "ng-packagr": "~21.0.0", "symlink": "^2.0.0", - "typescript": "~5.9.0" + "typescript": "~5.9.0", + "vitest": "^4.0.0" } } \ No newline at end of file diff --git a/templates/module/angular/projects/dev-app/karma.conf.js b/templates/module/angular/projects/dev-app/karma.conf.js deleted file mode 100644 index eee6000f3a8..00000000000 --- a/templates/module/angular/projects/dev-app/karma.conf.js +++ /dev/null @@ -1,44 +0,0 @@ -// Karma configuration file, see link for more information -// https://karma-runner.github.io/1.0/config/configuration-file.html - -module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine', '@angular-devkit/build-angular'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage'), - - ], - client: { - jasmine: { - // you can add configuration options for Jasmine here - // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html - // for example, you can disable the random execution with `random: false` - // or set a specific seed with `seed: 4321` - }, - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, - jasmineHtmlReporter: { - suppressAll: true // removes the duplicated traces - }, - coverageReporter: { - dir: require('path').join(__dirname, '../../coverage/dev-app'), - subdir: '.', - reporters: [ - { type: 'html' }, - { type: 'text-summary' } - ] - }, - reporters: ['progress', 'kjhtml'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - browsers: ['Chrome'], - singleRun: false, - restartOnFileChange: true - }); -}; diff --git a/templates/module/angular/projects/dev-app/src/test.ts b/templates/module/angular/projects/dev-app/src/test.ts deleted file mode 100644 index 7632e27a11b..00000000000 --- a/templates/module/angular/projects/dev-app/src/test.ts +++ /dev/null @@ -1,14 +0,0 @@ -// This file is required by karma.conf.js and loads recursively all the .spec and framework files - -import 'zone.js/testing'; -import { getTestBed } from '@angular/core/testing'; -import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting -} from '@angular/platform-browser-dynamic/testing'; - -// First, initialize the Angular testing environment. -getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting() -); diff --git a/templates/module/angular/projects/dev-app/tsconfig.app.json b/templates/module/angular/projects/dev-app/tsconfig.app.json index 809c09ca71a..742c48812c6 100644 --- a/templates/module/angular/projects/dev-app/tsconfig.app.json +++ b/templates/module/angular/projects/dev-app/tsconfig.app.json @@ -1,14 +1,15 @@ +/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */ +/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */ { "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "../../out-tsc/app", "types": [] }, - "files": [ - "src/main.ts", - "src/polyfills.ts" - ], "include": [ - "src/**/*.d.ts" + "src/**/*.ts" + ], + "exclude": [ + "src/**/*.spec.ts" ] } diff --git a/templates/module/angular/projects/dev-app/tsconfig.spec.json b/templates/module/angular/projects/dev-app/tsconfig.spec.json index a8ce1d396bb..ff7db766ac8 100644 --- a/templates/module/angular/projects/dev-app/tsconfig.spec.json +++ b/templates/module/angular/projects/dev-app/tsconfig.spec.json @@ -1,18 +1,16 @@ +/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */ +/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */ { "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "../../out-tsc/spec", "types": [ - "jasmine", + "vitest/globals", "node" ] }, - "files": [ - "src/test.ts", - "src/polyfills.ts" - ], "include": [ - "src/**/*.spec.ts", - "src/**/*.d.ts" + "src/**/*.d.ts", + "src/**/*.spec.ts" ] } diff --git a/templates/module/angular/projects/my-project-name/karma.conf.js b/templates/module/angular/projects/my-project-name/karma.conf.js deleted file mode 100644 index 4fa9d617e5e..00000000000 --- a/templates/module/angular/projects/my-project-name/karma.conf.js +++ /dev/null @@ -1,44 +0,0 @@ -// Karma configuration file, see link for more information -// https://karma-runner.github.io/1.0/config/configuration-file.html - -module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine', '@angular-devkit/build-angular'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage'), - - ], - client: { - jasmine: { - // you can add configuration options for Jasmine here - // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html - // for example, you can disable the random execution with `random: false` - // or set a specific seed with `seed: 4321` - }, - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, - jasmineHtmlReporter: { - suppressAll: true // removes the duplicated traces - }, - coverageReporter: { - dir: require('path').join(__dirname, '../../coverage/my-project-name'), - subdir: '.', - reporters: [ - { type: 'html' }, - { type: 'text-summary' } - ] - }, - reporters: ['progress', 'kjhtml'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - browsers: ['Chrome'], - singleRun: false, - restartOnFileChange: true - }); -}; diff --git a/templates/module/angular/projects/my-project-name/src/lib/my-project-name.component.spec.ts b/templates/module/angular/projects/my-project-name/src/lib/my-project-name.component.spec.ts index 4d6aae3ac8d..6176f4d6c6f 100644 --- a/templates/module/angular/projects/my-project-name/src/lib/my-project-name.component.spec.ts +++ b/templates/module/angular/projects/my-project-name/src/lib/my-project-name.component.spec.ts @@ -1,17 +1,19 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MyProjectNameComponent } from './components/my-project-name.component'; import { MyProjectNameService } from '@my-company-name/my-project-name'; import { of } from 'rxjs'; +import { vi } from 'vitest'; describe('MyProjectNameComponent', () => { let component: MyProjectNameComponent; let fixture: ComponentFixture; - const mockMyProjectNameService = jasmine.createSpyObj('MyProjectNameService', { - sample: of([]), - }); - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [MyProjectNameComponent], + const mockMyProjectNameService = { + sample: vi.fn().mockReturnValue(of([])), + }; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [MyProjectNameComponent], providers: [ { provide: MyProjectNameService, @@ -19,7 +21,7 @@ describe('MyProjectNameComponent', () => { }, ], }).compileComponents(); - })); + }); beforeEach(() => { fixture = TestBed.createComponent(MyProjectNameComponent); diff --git a/templates/module/angular/projects/my-project-name/src/lib/my-project-name.service.spec.ts b/templates/module/angular/projects/my-project-name/src/lib/my-project-name.service.spec.ts index ec7aeb6c68d..0782f6c0b62 100644 --- a/templates/module/angular/projects/my-project-name/src/lib/my-project-name.service.spec.ts +++ b/templates/module/angular/projects/my-project-name/src/lib/my-project-name.service.spec.ts @@ -1,10 +1,14 @@ import { TestBed } from '@angular/core/testing'; import { MyProjectNameService } from './services/my-project-name.service'; import { RestService } from '@abp/ng.core'; +import { vi } from 'vitest'; describe('MyProjectNameService', () => { let service: MyProjectNameService; - const mockRestService = jasmine.createSpyObj('RestService', ['request']); + const mockRestService = { + request: vi.fn(), + }; + beforeEach(() => { TestBed.configureTestingModule({ providers: [ diff --git a/templates/module/angular/projects/my-project-name/src/test.ts b/templates/module/angular/projects/my-project-name/src/test.ts deleted file mode 100644 index e63a8760624..00000000000 --- a/templates/module/angular/projects/my-project-name/src/test.ts +++ /dev/null @@ -1,15 +0,0 @@ -// This file is required by karma.conf.js and loads recursively all the .spec and framework files - -import 'zone.js'; -import 'zone.js/testing'; -import { getTestBed } from '@angular/core/testing'; -import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting -} from '@angular/platform-browser-dynamic/testing'; - -// First, initialize the Angular testing environment. -getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting() -); diff --git a/templates/module/angular/projects/my-project-name/tsconfig.spec.json b/templates/module/angular/projects/my-project-name/tsconfig.spec.json index 715dd0a5d2a..d63beb540b8 100644 --- a/templates/module/angular/projects/my-project-name/tsconfig.spec.json +++ b/templates/module/angular/projects/my-project-name/tsconfig.spec.json @@ -1,17 +1,15 @@ -/* To learn more about this file see: https://angular.io/config/tsconfig. */ +/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */ +/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */ { "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "../../out-tsc/spec", "types": [ - "jasmine" + "vitest/globals" ] }, - "files": [ - "src/test.ts" - ], "include": [ - "**/*.spec.ts", - "**/*.d.ts" + "**/*.d.ts", + "**/*.spec.ts" ] }