Skip to content

Commit

Permalink
test: actions tests config
Browse files Browse the repository at this point in the history
  • Loading branch information
Alain Boudard committed Oct 7, 2024
1 parent 83b8ecd commit 4c2694f
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 11 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": 1,
"newProjectRoot": "projects",
"projects": {
"testTesting": {
"angularTesting": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
Expand Down Expand Up @@ -62,18 +62,18 @@
"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"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "testTesting:build"
"buildTarget": "angularTesting:build"
}
},
"test": {
Expand All @@ -92,7 +92,8 @@
"styles": [
"src/styles.scss"
],
"scripts": []
"scripts": [],
"karmaConfig": "karma.conf.js"
}
}
}
Expand Down
45 changes: 45 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -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']
}
}
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 5 additions & 3 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
});
4 changes: 2 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
1 change: 1 addition & 0 deletions src/app/components/dumb/dumb.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>dumb works!</p>
Empty file.
23 changes: 23 additions & 0 deletions src/app/components/dumb/dumb.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { DumbComponent } from './dumb.component';

describe('DumbComponent', () => {
let component: DumbComponent;
let fixture: ComponentFixture<DumbComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DumbComponent]
})
.compileComponents();

fixture = TestBed.createComponent(DumbComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
12 changes: 12 additions & 0 deletions src/app/components/dumb/dumb.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-dumb',
standalone: true,
imports: [],
templateUrl: './dumb.component.html',
styleUrl: './dumb.component.scss'
})
export class DumbComponent {

}

0 comments on commit 4c2694f

Please # to comment.