frontend: Configure custom Webpack for Karma testing and update component imports in tests

This commit is contained in:
Carlos Santos 2025-03-13 16:43:58 +01:00
parent 13e9540b60
commit 6f86890209
8 changed files with 962 additions and 75 deletions

View File

@ -167,10 +167,14 @@
"defaultConfiguration": "production"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"builder": "@angular-builders/custom-webpack:karma",
"options": {
"tsConfig": "projects/shared-meet-components/tsconfig.spec.json",
"polyfills": ["zone.js", "zone.js/testing"]
"polyfills": ["zone.js", "zone.js/testing"],
"karmaConfig": "./karma.conf.js",
"customWebpackConfig": {
"path": "projects/shared-meet-components/src/tests/webpack.config.js"
}
}
}
}

32
frontend/karma.conf.js Normal file
View File

@ -0,0 +1,32 @@
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: {
clearContext: false // Leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // Removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage'),
subdir: '.',
reporters: [{ type: 'html' }, { type: 'text-summary' }]
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
});
};

File diff suppressed because it is too large Load Diff

View File

@ -45,6 +45,7 @@
"zone.js": "0.14.10"
},
"devDependencies": {
"@angular-builders/custom-webpack": "^18.0.0",
"@angular-devkit/build-angular": "18.2.6",
"@angular-eslint/builder": "18.3.1",
"@angular-eslint/eslint-plugin": "18.3.1",
@ -55,6 +56,7 @@
"@angular/compiler-cli": "18.2.5",
"@types/chai": "4.3.19",
"@types/fluent-ffmpeg": "2.1.27",
"@types/jasmine": "^5.1.7",
"@types/mocha": "9.1.1",
"@types/node": "20.12.14",
"@types/pixelmatch": "^5.2.6",
@ -68,6 +70,13 @@
"eslint": "8.57.1",
"eslint-config-prettier": "9.1.0",
"fluent-ffmpeg": "2.1.3",
"jasmine-core": "^5.6.0",
"jasmine-spec-reporter": "^7.0.0",
"karma": "^6.4.4",
"karma-chrome-launcher": "^3.2.0",
"karma-coverage": "^2.2.1",
"karma-jasmine": "^5.1.0",
"karma-jasmine-html-reporter": "^2.1.0",
"mocha": "10.7.3",
"ng-packagr": "18.2.1",
"pixelmatch": "5.3.0",

View File

@ -1,23 +1,22 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LoginComponent } from './login.component';
import { ConsoleLoginComponent } from './login.component';
describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
describe('ConsoleLoginComponent', () => {
let component: ConsoleLoginComponent;
let fixture: ComponentFixture<ConsoleLoginComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [LoginComponent]
})
.compileComponents();
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ConsoleLoginComponent]
}).compileComponents();
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(ConsoleLoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,18 +1,18 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RoomPreferencesComponent } from './rooms.component';
import { RoomsComponent } from './rooms.component';
describe('RoomConfigComponent', () => {
let component: RoomPreferencesComponent;
let fixture: ComponentFixture<RoomPreferencesComponent>;
let component: RoomsComponent;
let fixture: ComponentFixture<RoomsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RoomPreferencesComponent]
imports: [RoomsComponent]
})
.compileComponents();
fixture = TestBed.createComponent(RoomPreferencesComponent);
fixture = TestBed.createComponent(RoomsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

View File

@ -0,0 +1,10 @@
module.exports = {
resolve: {
extensions: ['.ts', '.js', '.json'],
extensionAlias: {
".js": [".ts", ".js"],
".cjs": [".cts", ".cjs"],
".mjs": [".mts", ".mjs"]
}
}
};

View File

@ -1,15 +1,10 @@
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine"
]
},
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": ["jasmine"]
},
"include": ["**/*.spec.ts", "**/*.d.ts"]
}