Skip to content

Commit 53baaad

Browse files
author
Alain Boudard
committed
test: actions tests config
1 parent 83b8ecd commit 53baaad

File tree

11 files changed

+112
-13
lines changed

11 files changed

+112
-13
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ jobs:
1313
- uses: actions/checkout@v4
1414
with:
1515
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
16+
- uses: actions/setup-node@v2
17+
with:
18+
node-version: '20'
19+
20+
- name: Node install dependencies
21+
run: npm install
22+
23+
- name: Run unit tests
24+
run: npm run test
25+
1626
- name: SonarCloud Scan
1727
uses: SonarSource/sonarcloud-github-action@master
1828
env:

angular.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": 1,
44
"newProjectRoot": "projects",
55
"projects": {
6-
"testTesting": {
6+
"angularTesting": {
77
"projectType": "application",
88
"schematics": {
99
"@schematics/angular:component": {
@@ -62,18 +62,18 @@
6262
"builder": "@angular-devkit/build-angular:dev-server",
6363
"configurations": {
6464
"production": {
65-
"buildTarget": "testTesting:build:production"
65+
"buildTarget": "angularTesting:build:production"
6666
},
6767
"development": {
68-
"buildTarget": "testTesting:build:development"
68+
"buildTarget": "angularTesting:build:development"
6969
}
7070
},
7171
"defaultConfiguration": "development"
7272
},
7373
"extract-i18n": {
7474
"builder": "@angular-devkit/build-angular:extract-i18n",
7575
"options": {
76-
"buildTarget": "testTesting:build"
76+
"buildTarget": "angularTesting:build"
7777
}
7878
},
7979
"test": {
@@ -92,7 +92,8 @@
9292
"styles": [
9393
"src/styles.scss"
9494
],
95-
"scripts": []
95+
"scripts": [],
96+
"karmaConfig": "karma.conf.js"
9697
}
9798
}
9899
}

karma.conf.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-chrome-launcher'),
11+
require('karma-jasmine-html-reporter'),
12+
require('karma-coverage'),
13+
require('@angular-devkit/build-angular/plugins/karma')
14+
],
15+
client: {
16+
jasmine: {
17+
// you can add configuration options for Jasmine here
18+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19+
// for example, you can disable the random execution with `random: false`
20+
// or set a specific seed with `seed: 4321`
21+
},
22+
clearContext: false // leave Jasmine Spec Runner output visible in browser
23+
},
24+
jasmineHtmlReporter: {
25+
suppressAll: true // removes the duplicated traces
26+
},
27+
coverageReporter: {
28+
dir: require('path').join(__dirname, './coverage/angular-testing'),
29+
subdir: '.',
30+
reporters: [
31+
{ type: 'html' },
32+
{ type: 'text-summary' },
33+
{ type: 'lcov' }
34+
]
35+
},
36+
reporters: ['progress', 'kjhtml', 'coverage'],
37+
browsers: ['ChromeHeadlessNoSandbox'],
38+
restartOnFileChange: true,
39+
customLaunchers: {
40+
ChromeHeadlessNoSandbox: {
41+
base: 'ChromeHeadless',
42+
flags: ['--no-sandbox']
43+
}
44+
}
45+
});
46+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"start": "ng serve",
77
"build": "ng build",
88
"watch": "ng build --watch --configuration development",
9-
"test": "ng test"
9+
"test": "ng test --code-coverage --watch=false"
1010
},
1111
"private": true,
1212
"dependencies": {

sonar-project.properties

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ sonar.organization=aboudard
55
sonar.projectName=angular-testing
66
sonar.projectVersion=1.0
77

8+
sonar.coverage.exclusions=**/*.spec.ts
89

910
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
10-
#sonar.sources=.
11+
sonar.sources=src
1112

1213
# Encoding of the source code. Default is default system encoding
13-
#sonar.sourceEncoding=UTF-8
14+
#sonar.sourceEncoding=UTF-8
15+
16+
sonar.typescript.tsconfigPath=tsconfig.json
17+
sonar.javascript.lcov.reportPaths=./coverage/angular-testing/lcov.info

src/app/app.component.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ describe('AppComponent', () => {
1414
expect(app).toBeTruthy();
1515
});
1616

17-
it(`should have the 'testTesting' title`, () => {
17+
it(`should have the 'angularTesting' title`, () => {
1818
const fixture = TestBed.createComponent(AppComponent);
1919
const app = fixture.componentInstance;
20-
expect(app.title).toEqual('testTesting');
20+
expect(app.title).toEqual('angularTesting');
2121
});
2222

2323
it('should render title', () => {
2424
const fixture = TestBed.createComponent(AppComponent);
2525
fixture.detectChanges();
2626
const compiled = fixture.nativeElement as HTMLElement;
27-
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, testTesting');
27+
expect(compiled.querySelector('h1')?.textContent).toContain(
28+
'Hello, angularTesting'
29+
);
2830
});
2931
});

src/app/app.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { RouterOutlet } from '@angular/router';
66
standalone: true,
77
imports: [RouterOutlet],
88
templateUrl: './app.component.html',
9-
styleUrl: './app.component.scss'
9+
styleUrl: './app.component.scss',
1010
})
1111
export class AppComponent {
12-
title = 'testTesting';
12+
title = 'angularTesting';
1313
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>dumb works!</p>

src/app/components/dumb/dumb.component.scss

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { DumbComponent } from './dumb.component';
4+
5+
describe('DumbComponent', () => {
6+
let component: DumbComponent;
7+
let fixture: ComponentFixture<DumbComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
imports: [DumbComponent]
12+
})
13+
.compileComponents();
14+
15+
fixture = TestBed.createComponent(DumbComponent);
16+
component = fixture.componentInstance;
17+
fixture.detectChanges();
18+
});
19+
20+
it('should create', () => {
21+
expect(component).toBeTruthy();
22+
});
23+
});

0 commit comments

Comments
 (0)