diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a14b244..e1e1f4f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,16 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - uses: actions/setup-node@v2 + with: + node-version: '20' + + - name: Node install dependencies + run: npm install + + - name: Run unit tests + run: npm run test + - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master env: diff --git a/angular.json b/angular.json index e8c4aa9..2f279b5 100644 --- a/angular.json +++ b/angular.json @@ -3,7 +3,7 @@ "version": 1, "newProjectRoot": "projects", "projects": { - "testTesting": { + "angularTesting": { "projectType": "application", "schematics": { "@schematics/angular:component": { @@ -62,10 +62,10 @@ "builder": "@angular-devkit/build-angular:dev-server", "configurations": { "production": { - "buildTarget": "testTesting:build:production" + "buildTarget": "angularTesting:build:production" }, "development": { - "buildTarget": "testTesting:build:development" + "buildTarget": "angularTesting:build:development" } }, "defaultConfiguration": "development" @@ -73,7 +73,7 @@ "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { - "buildTarget": "testTesting:build" + "buildTarget": "angularTesting:build" } }, "test": { @@ -92,7 +92,8 @@ "styles": [ "src/styles.scss" ], - "scripts": [] + "scripts": [], + "karmaConfig": "karma.conf.js" } } } diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..dc7936d --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,45 @@ +// 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'), + require('@angular-devkit/build-angular/plugins/karma') + ], + 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/angular-testing'), + subdir: '.', + reporters: [ + { type: 'html' }, + { type: 'text-summary' } + ] + }, + reporters: ['progress', 'kjhtml', 'coverage'], + browsers: ['ChromeHeadlessNoSandbox'], + restartOnFileChange: true, + customLaunchers: { + ChromeHeadlessNoSandbox: { + base: 'ChromeHeadless', + flags: ['--no-sandbox'] + } + } + }); +}; diff --git a/package.json b/package.json index d28c71e..fc5cb7b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development", - "test": "ng test" + "test": "ng test --code-coverage --watch=false" }, "private": true, "dependencies": { diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 210a2e9..4e81794 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -14,16 +14,18 @@ describe('AppComponent', () => { expect(app).toBeTruthy(); }); - it(`should have the 'testTesting' title`, () => { + it(`should have the 'angularTesting' title`, () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.componentInstance; - expect(app.title).toEqual('testTesting'); + expect(app.title).toEqual('angularTesting'); }); it('should render title', () => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); const compiled = fixture.nativeElement as HTMLElement; - expect(compiled.querySelector('h1')?.textContent).toContain('Hello, testTesting'); + expect(compiled.querySelector('h1')?.textContent).toContain( + 'Hello, angularTesting' + ); }); }); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 0d4d160..72d039e 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -6,8 +6,8 @@ import { RouterOutlet } from '@angular/router'; standalone: true, imports: [RouterOutlet], templateUrl: './app.component.html', - styleUrl: './app.component.scss' + styleUrl: './app.component.scss', }) export class AppComponent { - title = 'testTesting'; + title = 'angularTesting'; } diff --git a/src/app/components/dumb/dumb.component.html b/src/app/components/dumb/dumb.component.html new file mode 100644 index 0000000..b15a542 --- /dev/null +++ b/src/app/components/dumb/dumb.component.html @@ -0,0 +1 @@ +
dumb works!
diff --git a/src/app/components/dumb/dumb.component.scss b/src/app/components/dumb/dumb.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/dumb/dumb.component.spec.ts b/src/app/components/dumb/dumb.component.spec.ts new file mode 100644 index 0000000..cb8fcf5 --- /dev/null +++ b/src/app/components/dumb/dumb.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { DumbComponent } from './dumb.component'; + +describe('DumbComponent', () => { + let component: DumbComponent; + let fixture: ComponentFixture