Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"cacheProvider": "no",
"clientBundler": "webpack",
"clientFramework": "angular",
"clientTestFramework": "vitest",
"creationTimestamp": 1596513272473,
"databaseType": "sql",
"devDatabaseType": "h2Memory",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"cacheProvider": "no",
"clientBundler": "webpack",
"clientFramework": "angular",
"clientTestFramework": "vitest",
"clientTheme": "none",
"creationTimestamp": 1580314672693,
"databaseType": "mongodb",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"cacheProvider": "no",
"clientBundler": "webpack",
"clientFramework": "angular",
"clientTestFramework": "vitest",
"creationTimestamp": 1596513172471,
"databaseType": "sql",
"devDatabaseType": "h2Disk",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"app-sample": "ng-default",
"jdl-entity": "*",
"generatorOptions": {
"clientTestFramework": "vitest",
"clientBundler": "webpack"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ exports[`generator - github-build-matrix with angular should match matrix value
"app-sample": "ng-default",
"jdl-entity": "*",
"generatorOptions": {
"clientTestFramework": "vitest",
"clientBundler": "webpack"
},
"workspaces": "false",
Expand Down
13 changes: 12 additions & 1 deletion generators/angular/files-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,25 @@ export const files = asWriteFilesSection({
'tsconfig.json',
'tsconfig.app.json',
'tsconfig.spec.json',
'jest.conf.js',
],
}),
clientRootTemplatesBlock({
condition: ctx => ctx.enableTranslation && ctx.enableI18nRTL,
templates: ['postcss.config.json'],
}),
],
jest: [
clientRootTemplatesBlock({
condition: ctx => ctx.clientTestFrameworkJest,
templates: ['jest.conf.js'],
}),
],
vitest: [
clientSrcTemplatesBlock({
condition: ctx => ctx.clientTestFrameworkVitest,
templates: ['default-test-providers.ts'],
}),
],
webpack: [
clientRootTemplatesBlock({
condition: ctx => ctx.clientBundlerWebpack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ exports[`generator - angular:bootstrap bootstrapping default config should prepa
"clientSrcDir": "src/main/webapp/",
"clientTestDir": "src/test/javascript/",
"clientTestFramework": "jest",
"clientTestFrameworkAny": true,
"clientTestFrameworkJest": true,
"clientTestFrameworkName": "Jest",
"clientTestFrameworkVitest": false,
"clientTestFrameworks": undefined,
"clientTestFrameworksAny": false,
"clientTestFrameworksCypress": false,
Expand Down
2 changes: 1 addition & 1 deletion generators/angular/generators/bootstrap/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class BootstrapGenerator extends AngularApplicationGenerator {
createNeedleCallback({
needle: 'i18n-language-loader',
contentToAdd: allLanguages.map(
lang => `'${lang.languageTag}': async (): Promise<any> => import('i18n/${lang.languageTag}.json'),`,
lang => `'${lang.languageTag}': async (): Promise<any> => import('i18n/${lang.languageTag}.json').catch(),`,
),
}),
createNeedleCallback({
Expand Down
3 changes: 3 additions & 0 deletions generators/angular/resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@
"jest-junit": "16.0.0",
"jest-preset-angular": "14.6.0",
"jest-sonar": "0.2.16",
"jsdom": "27.0.1",
"merge-jsons-webpack-plugin": "2.0.1",
"postcss-rtlcss": "5.7.1",
"rimraf": "5.0.8",
"tinyglobby": "0.2.15",
"ts-jest": "29.4.5",
"typescript": "5.9.2",
"typescript-eslint": "8.46.2",
"vitest": "3.2.4",
"vitest-sonar-reporter": "2.0.4",
"webpack": "5.102.1",
"webpack-bundle-analyzer": "4.10.2",
"webpack-merge": "6.0.1",
Expand Down
10 changes: 10 additions & 0 deletions generators/angular/templates/angular.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,19 @@
"defaultConfiguration": "development"
},
"test": {
<%_ if (clientTestFrameworkJest) { _%>
"builder": "@angular-builders/jest:run",
<%_ } else { _%>
"builder": "@angular/build:unit-test",
<%_ } _%>
"options": {
<%_ if (clientTestFrameworkJest) { _%>
"configPath": "jest.conf.js",
<%_ } else { _%>
"runner": "vitest",
"buildTarget": "::development",
"providersFile": "<%= clientSrcDir %>default-test-providers.ts",
<%_ } _%>
"tsConfig": "tsconfig.spec.json"
}
}
Expand Down
10 changes: 10 additions & 0 deletions generators/angular/templates/angular.json.esbuild.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,19 @@
"defaultConfiguration": "development"
},
"test": {
<%_ if (clientTestFrameworkJest) { _%>
"builder": "@angular-builders/jest:run",
<%_ } else { _%>
"builder": "@angular/build:unit-test",
<%_ } _%>
"options": {
<%_ if (clientTestFrameworkJest) { _%>
"configPath": "jest.conf.js",
<%_ } else { _%>
"runner": "vitest",
"buildTarget": "::development",
"providersFile": "<%= clientSrcDir %>default-test-providers.ts",
<%_ } _%>
"tsConfig": "tsconfig.spec.json"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import eslint from '@eslint/js';
import angular from 'angular-eslint';
<&_ } -&>
<&_ if (fragment.configSection) { -&>
{ ignores: ['<%- this.relativeDir(clientRootDir, clientDistDir) %>', '<%- temporaryDir %>'] },
{ ignores: ['<%- this.relativeDir(clientRootDir, clientDistDir) %>', '<%- temporaryDir %>'<% if (clientTestFrameworkVitest) { %>, 'dist/'<% } %>] },
eslint.configs.recommended,
{
files: ['**/*.{js,cjs,mjs}'],
Expand Down
34 changes: 23 additions & 11 deletions generators/angular/templates/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"node_modules"
],
"dependencies": {
<%_ if (clientTestFrameworkJest) { _%>
"zone.js": "<%= nodeDependencies['zone.js'] %>",
<%_ } _%>
"@angular/common": "<%= nodeDependencies['@angular/common'] %>",
"@angular/compiler": "<%= nodeDependencies['@angular/common'] %>",
"@angular/core": "<%= nodeDependencies['@angular/common'] %>",
Expand All @@ -50,8 +53,7 @@
"dayjs": "<%= nodeDependencies['dayjs'] %>",
"ngx-infinite-scroll": "<%= nodeDependencies['ngx-infinite-scroll'] %>",
"rxjs": "<%= nodeDependencies['rxjs'] %>",
"tslib": "<%= nodeDependencies['tslib'] %>",
"zone.js": "<%= nodeDependencies['zone.js'] %>"
"tslib": "<%= nodeDependencies['tslib'] %>"
},
"devDependencies": {
<%_ if (skipServer) { _%>
Expand All @@ -62,14 +64,26 @@
"@angular-architects/module-federation-runtime": "<%= nodeDependencies['@angular-architects/module-federation-runtime'] %>",
<%_ } _%>
"@angular-architects/module-federation": "<%= nodeDependencies['@angular-architects/module-federation'] %>",
<%_ } _%>
<%_ if (clientTestFrameworkJest) { _%>
"@angular-builders/jest": "<%= nodeDependencies['@angular-builders/jest'] %>",
"@types/jest": "<%= nodeDependencies['@types/jest'] %>",
"jest": "<%= nodeDependencies['jest'] %>",
"jest-environment-jsdom": "<%= nodeDependencies['jest'] %>",
"jest-preset-angular": "<%= nodeDependencies['jest-preset-angular'] %>",
"jest-junit": "<%= nodeDependencies['jest-junit'] %>",
"jest-sonar": "<%= nodeDependencies['jest-sonar'] %>",
"ts-jest": "<%= nodeDependencies['ts-jest'] %>",
<%_ } else { _%>
"jsdom": null,
"vitest": null,
"vitest-sonar-reporter": null,
<%_ } _%>
"@angular/build": "<%= nodeDependencies['@angular/cli'] %>",
"@angular/cli": "<%= nodeDependencies['@angular/cli'] %>",
"@angular/compiler-cli": "<%= nodeDependencies['@angular/common'] %>",
"@angular/service-worker": "<%= nodeDependencies['@angular/common'] %>",
"@angular-builders/jest": "<%= nodeDependencies['@angular-builders/jest'] %>",
"@eslint/js": null,
"@types/jest": "<%= nodeDependencies['@types/jest'] %>",
"@types/node": "<%= nodeDependencies['@types/node'] %>",
"angular-eslint": "<%= nodeDependencies['angular-eslint'] %>",
"browser-sync": "<%= nodeDependencies['browser-sync'] %>",
Expand All @@ -78,17 +92,11 @@
"eslint-config-prettier": "<%= nodeDependencies['eslint-config-prettier'] %>",
"eslint-plugin-prettier": "<%= nodeDependencies['eslint-plugin-prettier'] %>",
"globals": "<%= nodeDependencies.globals %>",
"jest": "<%= nodeDependencies['jest'] %>",
"jest-environment-jsdom": "<%= nodeDependencies['jest'] %>",
"jest-preset-angular": "<%= nodeDependencies['jest-preset-angular'] %>",
"jest-junit": "<%= nodeDependencies['jest-junit'] %>",
"jest-sonar": "<%= nodeDependencies['jest-sonar'] %>",
<%_ if (enableI18nRTL) { _%>
"postcss-rtlcss": "<%= nodeDependencies['postcss-rtlcss'] %>",
<%_ } _%>
"rimraf": "<%= nodeDependencies['rimraf'] %>",
"swagger-ui-dist": "<%= nodeDependencies['swagger-ui-dist'] %>",
"ts-jest": "<%= nodeDependencies['ts-jest'] %>",
"typescript": "<%= nodeDependencies['typescript'] %>",
"typescript-eslint": "<%= nodeDependencies['typescript-eslint'] %>"
},
Expand All @@ -103,7 +111,6 @@
"lint:fix": "<%- nodePackageManager %> run lint -- --fix",
"cleanup": "rimraf <%= this.relativeDir(clientRootDir, temporaryDir) %>",
"clean-www": "rimraf <%= this.relativeDir(clientRootDir, clientDistDir) %>",
"jest": "jest --coverage --logHeapUsage --maxWorkers=2 --config jest.conf.js",
"start": "ng serve<% if (!microfrontend) { %> --hmr<% } %>",
"start-tls": "<%- nodePackageManager %> run webapp:dev-ssl",
<%_ if (skipServer) { _%>
Expand All @@ -112,7 +119,12 @@
"serve": "<%- nodePackageManager %> run start --",
"build": "<%- nodePackageManager %> run webapp:prod --",
"pretest": "<%- nodePackageManager %> run lint",
<%_ if (clientTestFrameworkJest) { _%>
"jest": "jest --coverage --logHeapUsage --maxWorkers=2 --config jest.conf.js",
"test": "ng test --coverage --log-heap-usage -w=2",
<%_ } else { _%>
"test": "ng test",
<%_ } _%>
"test:watch": "<%- nodePackageManager %> run test -- --watch",
"watch": "concurrently npm:start<% if(!skipServer) { %> npm:backend:start<% } %>",
"build-watch": "concurrently 'npm run webapp:build:dev -- --watch'<% if(!skipServer) { %> npm:backend:start<% } %>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
<%_ if (clientTestFrameworkVitest) { _%>
import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest';
<%_ } _%>
import { TestBed } from '@angular/core/testing';
import { provideHttpClientTesting, HttpTestingController } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
<%_ if (clientTestFrameworkVitest) { _%>
import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest';
<%_ } _%>
import { TestBed, inject } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { ActivatedRoute } from '@angular/router';
Expand Down Expand Up @@ -49,15 +52,15 @@ describe('Activate', () => {
});

it('calls activate.get with the key from params', inject([ActivateService], (service: ActivateService) => {
jest.spyOn(service, 'get').mockReturnValue(of());
<%= clientTestFramework %>.spyOn(service, 'get').mockReturnValue(of());

comp.ngOnInit();

expect(service.get).toHaveBeenCalledWith('ABC123');
}));

it('should set set success to true upon successful activation', inject([ActivateService], (service: ActivateService) => {
jest.spyOn(service, 'get').mockReturnValue(of({}));
<%= clientTestFramework %>.spyOn(service, 'get').mockReturnValue(of({}));

comp.ngOnInit();

Expand All @@ -66,7 +69,7 @@ describe('Activate', () => {
}));

it('should set set error to true upon activation failure', inject([ActivateService], (service: ActivateService) => {
jest.spyOn(service, 'get').mockReturnValue(throwError(Error));
<%= clientTestFramework %>.spyOn(service, 'get').mockReturnValue(throwError(Error));

comp.ngOnInit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
<%_ if (clientTestFrameworkVitest) { _%>
import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest';
<%_ } _%>
import { TestBed } from '@angular/core/testing';
import { provideHttpClientTesting, HttpTestingController } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
<%_ if (clientTestFrameworkVitest) { _%>
import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest';
<%_ } _%>
import { ElementRef, signal } from '@angular/core';
import { ComponentFixture, TestBed, inject } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
Expand Down Expand Up @@ -58,7 +61,7 @@ describe('PasswordResetFinish', () => {

it('sets focus after the view has been initialized', () => {
const node = {
focus: jest.fn(),
focus: <%= clientTestFramework %>.fn(),
};
comp.newPassword = signal<ElementRef>(new ElementRef(node));

Expand All @@ -79,7 +82,7 @@ describe('PasswordResetFinish', () => {
});

it('should update success to true after resetting password', inject([PasswordResetFinishService], (service: PasswordResetFinishService) => {
jest.spyOn(service, 'save').mockReturnValue(of({}));
<%= clientTestFramework %>.spyOn(service, 'save').mockReturnValue(of({}));
comp.passwordForm.patchValue({
newPassword: 'password',
confirmPassword: 'password',
Expand All @@ -92,7 +95,7 @@ describe('PasswordResetFinish', () => {
}));

it('should notify of generic error', inject([PasswordResetFinishService], (service: PasswordResetFinishService) => {
jest.spyOn(service, 'save').mockReturnValue(throwError(Error));
<%= clientTestFramework %>.spyOn(service, 'save').mockReturnValue(throwError(Error));
comp.passwordForm.patchValue({
newPassword: 'password',
confirmPassword: 'password',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
<%_ if (clientTestFrameworkVitest) { _%>
import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest';
<%_ } _%>
import { TestBed } from '@angular/core/testing';
import { provideHttpClientTesting, HttpTestingController } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
<%_ if (clientTestFrameworkVitest) { _%>
import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest';
<%_ } _%>
import { ElementRef, signal } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
Expand Down Expand Up @@ -44,7 +47,7 @@ describe('PasswordResetInit', () => {

it('sets focus after the view has been initialized', () => {
const node = {
focus: jest.fn(),
focus: <%= clientTestFramework %>.fn(),
};
comp.email = signal<ElementRef>(new ElementRef(node));

Expand All @@ -54,7 +57,7 @@ describe('PasswordResetInit', () => {
});

it('notifies of success upon successful requestReset', () => {
jest.spyOn(service, 'save').mockReturnValue(of({}));
<%= clientTestFramework %>.spyOn(service, 'save').mockReturnValue(of({}));
comp.resetRequestForm.patchValue({
email: '[email protected]',
});
Expand All @@ -67,7 +70,7 @@ describe('PasswordResetInit', () => {

it('no notification of success upon error response', () => {
const err = { status: 503, data: 'something else' };
jest.spyOn(service, 'save').mockReturnValue(throwError(() => err));
<%= clientTestFramework %>.spyOn(service, 'save').mockReturnValue(throwError(() => err));
comp.resetRequestForm.patchValue({
email: '[email protected]',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
<%_ if (clientTestFrameworkVitest) { _%>
import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest';
<%_ } _%>
import { ComponentFixture, TestBed } from '@angular/core/testing';
<%_ if (enableTranslation) { _%>
import { TranslateModule } from '@ngx-translate/core';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<%_ if (clientTestFrameworkVitest) { _%>
import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest';
<%_ } _%>
import { TestBed } from '@angular/core/testing';
import { provideHttpClientTesting, HttpTestingController } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
Expand Down
Loading
Loading