Skip to content

Commit ed0f50f

Browse files
committed
feat(angular): generate vitest unit test runner by default and use angular builder
1 parent 134b829 commit ed0f50f

File tree

36 files changed

+696
-281
lines changed

36 files changed

+696
-281
lines changed

e2e/angular/src/config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('angular.json v1 config', () => {
1414
beforeAll(() => {
1515
newProject({ packages: ['@nx/angular'] });
1616
runCLI(
17-
`generate @nx/angular:app ${app1} --bundler=webpack --no-interactive`
17+
`generate @nx/angular:app ${app1} --bundler=webpack --unit-test-runner=jest --no-interactive`
1818
);
1919
// reset workspace to use v1 config
2020
updateFile(`angular.json`, angularV1Json(app1));

e2e/angular/src/misc.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ describe('Move Angular Project', () => {
2020
app1 = uniq('app1');
2121
app2 = uniq('app2');
2222
newPath = `subfolder/${app2}`;
23-
runCLI(`generate @nx/angular:app ${app1} --no-interactive`);
23+
runCLI(
24+
`generate @nx/angular:app ${app1} --unit-test-runner=jest --no-interactive`
25+
);
2426
});
2527

2628
afterAll(() => cleanupProject());

packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,71 @@ exports[`app --strict should enable strict type checking: e2e tsconfig.json 1`]
625625
}
626626
`;
627627
628-
exports[`app --unit-test-runner vitest should add tsconfig.spec.json 1`] = `
628+
exports[`app angular compat support should generate components with the "component" type for versions lower than v20 1`] = `
629+
"import { Component } from '@angular/core';
630+
import { RouterModule } from '@angular/router';
631+
import { NxWelcomeComponent } from './nx-welcome.component';
632+
633+
@Component({
634+
imports: [NxWelcomeComponent, RouterModule],
635+
selector: 'app-root',
636+
templateUrl: './app.component.html',
637+
styleUrl: './app.component.css',
638+
})
639+
export class AppComponent {
640+
title = 'myapp';
641+
}
642+
"
643+
`;
644+
645+
exports[`app angular compat support should generate components with the "component" type for versions lower than v20 2`] = `
646+
"<app-nx-welcome></app-nx-welcome>
647+
<router-outlet></router-outlet>
648+
"
649+
`;
650+
651+
exports[`app angular compat support should generate components with the "component" type for versions lower than v20 3`] = `
652+
"import { TestBed } from '@angular/core/testing';
653+
import { AppComponent } from './app.component';
654+
import { NxWelcomeComponent } from './nx-welcome.component';
655+
656+
describe('AppComponent', () => {
657+
beforeEach(async () => {
658+
await TestBed.configureTestingModule({
659+
imports: [AppComponent, NxWelcomeComponent],
660+
}).compileComponents();
661+
});
662+
663+
it('should render title', () => {
664+
const fixture = TestBed.createComponent(AppComponent);
665+
fixture.detectChanges();
666+
const compiled = fixture.nativeElement as HTMLElement;
667+
expect(compiled.querySelector('h1')?.textContent).toContain(
668+
'Welcome myapp'
669+
);
670+
});
671+
672+
it(\`should have as title 'myapp'\`, () => {
673+
const fixture = TestBed.createComponent(AppComponent);
674+
const app = fixture.componentInstance;
675+
expect(app.title).toEqual('myapp');
676+
});
677+
});
678+
"
679+
`;
680+
681+
exports[`app angular compat support should generate components with the "component" type for versions lower than v20 4`] = `
682+
"import { bootstrapApplication } from '@angular/platform-browser';
683+
import { appConfig } from './app/app.config';
684+
import { AppComponent } from './app/app.component';
685+
686+
bootstrapApplication(AppComponent, appConfig).catch((err) =>
687+
console.error(err)
688+
);
689+
"
690+
`;
691+
692+
exports[`app angular compat support vitest & angular < 21 should add tsconfig.spec.json 1`] = `
629693
"{
630694
"extends": "./tsconfig.json",
631695
"compilerOptions": {
@@ -658,7 +722,7 @@ exports[`app --unit-test-runner vitest should add tsconfig.spec.json 1`] = `
658722
"
659723
`;
660724
661-
exports[`app --unit-test-runner vitest should generate src/test-setup.ts 1`] = `
725+
exports[`app angular compat support vitest & angular < 21 should generate src/test-setup.ts 1`] = `
662726
"import '@angular/compiler';
663727
import '@analogjs/vitest-angular/setup-zone';
664728
@@ -675,7 +739,7 @@ getTestBed().initTestEnvironment(
675739
"
676740
`;
677741
678-
exports[`app --unit-test-runner vitest should generate vite.config.mts 1`] = `
742+
exports[`app angular compat support vitest & angular < 21 should generate vite.config.mts 1`] = `
679743
"/// <reference types='vitest' />
680744
import { defineConfig } from 'vite';
681745
import angular from '@analogjs/vite-plugin-angular';
@@ -707,70 +771,6 @@ export default defineConfig(() => ({
707771
"
708772
`;
709773
710-
exports[`app angular compat support should generate components with the "component" type for versions lower than v20 1`] = `
711-
"import { Component } from '@angular/core';
712-
import { RouterModule } from '@angular/router';
713-
import { NxWelcomeComponent } from './nx-welcome.component';
714-
715-
@Component({
716-
imports: [NxWelcomeComponent, RouterModule],
717-
selector: 'app-root',
718-
templateUrl: './app.component.html',
719-
styleUrl: './app.component.css',
720-
})
721-
export class AppComponent {
722-
title = 'myapp';
723-
}
724-
"
725-
`;
726-
727-
exports[`app angular compat support should generate components with the "component" type for versions lower than v20 2`] = `
728-
"<app-nx-welcome></app-nx-welcome>
729-
<router-outlet></router-outlet>
730-
"
731-
`;
732-
733-
exports[`app angular compat support should generate components with the "component" type for versions lower than v20 3`] = `
734-
"import { TestBed } from '@angular/core/testing';
735-
import { AppComponent } from './app.component';
736-
import { NxWelcomeComponent } from './nx-welcome.component';
737-
738-
describe('AppComponent', () => {
739-
beforeEach(async () => {
740-
await TestBed.configureTestingModule({
741-
imports: [AppComponent, NxWelcomeComponent],
742-
}).compileComponents();
743-
});
744-
745-
it('should render title', () => {
746-
const fixture = TestBed.createComponent(AppComponent);
747-
fixture.detectChanges();
748-
const compiled = fixture.nativeElement as HTMLElement;
749-
expect(compiled.querySelector('h1')?.textContent).toContain(
750-
'Welcome myapp'
751-
);
752-
});
753-
754-
it(\`should have as title 'myapp'\`, () => {
755-
const fixture = TestBed.createComponent(AppComponent);
756-
const app = fixture.componentInstance;
757-
expect(app.title).toEqual('myapp');
758-
});
759-
});
760-
"
761-
`;
762-
763-
exports[`app angular compat support should generate components with the "component" type for versions lower than v20 4`] = `
764-
"import { bootstrapApplication } from '@angular/platform-browser';
765-
import { appConfig } from './app/app.config';
766-
import { AppComponent } from './app/app.component';
767-
768-
bootstrapApplication(AppComponent, appConfig).catch((err) =>
769-
console.error(err)
770-
);
771-
"
772-
`;
773-
774774
exports[`app at the root should accept numbers in the path 1`] = `"src/9-websites/my-app"`;
775775
776776
exports[`app format files should format files 1`] = `
@@ -1091,11 +1091,11 @@ exports[`app not nested should generate files: tsconfig.app.json 1`] = `
10911091
"types": [],
10921092
},
10931093
"exclude": [
1094-
"jest.config.ts",
1095-
"src/test-setup.ts",
1096-
"src/**/*.test.ts",
10971094
"src/**/*.spec.ts",
1095+
"src/**/*.test.ts",
1096+
"jest.config.ts",
10981097
"jest.config.cts",
1098+
"src/test-setup.ts",
10991099
],
11001100
"extends": "./tsconfig.json",
11011101
"include": [

0 commit comments

Comments
 (0)