@@ -615,6 +615,167 @@ module.exports = function (config) {
615615 });
616616};
617617```
618+ ### Issue 6: Chrome Headless Timeout - "Disconnected, because no message in 30000 ms"
619+
620+ ** Error messages:**
621+ ```
622+ Chrome Headless 140.0.0.0 (Linux 0.0.0) ERROR
623+ Disconnected , because no message in 30000 ms.
624+ Error: Process completed with exit code 1.
625+ ```
626+
627+ ** Cause:** Tests are taking longer than 30 seconds to compile or load, causing Karma to disconnect the browser. This commonly happens when:
628+ - Tests include many dependencies or large files
629+ - Initial compilation takes too long in CI environment
630+ - Memory/CPU constraints in the CI environment
631+
632+ ** Solution - Option A: Increase Browser Timeout (Recommended)**
633+
634+ Update ` karma.conf.js ` to increase the timeout values:
635+
636+ ``` javascript
637+ module .exports = function (config ) {
638+ config .set ({
639+ // ... other config
640+ browserNoActivityTimeout: 60000 , // Increase from default 30s to 60s
641+ browserDisconnectTimeout: 10000 ,
642+ browserDisconnectTolerance: 3 ,
643+ captureTimeout: 210000 ,
644+ });
645+ };
646+ ```
647+
648+ ** Solution - Option B: Add Chrome Flags for CI**
649+
650+ Update ` karma.conf.js ` to add Chrome flags that improve performance in CI:
651+
652+ ``` javascript
653+ module .exports = function (config ) {
654+ config .set ({
655+ // ... other config
656+ customLaunchers: {
657+ ChromeHeadlessCI: {
658+ base: ' ChromeHeadless' ,
659+ flags: [
660+ ' --no-sandbox' ,
661+ ' --disable-gpu' ,
662+ ' --disable-dev-shm-usage' ,
663+ ' --disable-software-rasterizer' ,
664+ ' --disable-extensions' ,
665+ ]
666+ }
667+ },
668+ browsers: [' ChromeHeadlessCI' ],
669+ browserNoActivityTimeout: 60000 ,
670+ });
671+ };
672+ ```
673+
674+ Then update package.json to use this custom launcher:
675+
676+ ``` json
677+ {
678+ "scripts" : {
679+ "test:ci" : " ng test --no-watch --no-progress --browsers=ChromeHeadlessCI --code-coverage --include='**/time-planning-pn/**/*.spec.ts'"
680+ }
681+ }
682+ ```
683+
684+ ** Solution - Option C: Optimize Test Configuration**
685+
686+ In ` angular.json ` , ensure optimization is disabled for tests:
687+
688+ ``` json
689+ {
690+ "projects" : {
691+ "your-project-name" : {
692+ "architect" : {
693+ "test" : {
694+ "builder" : " @angular-devkit/build-angular:karma" ,
695+ "options" : {
696+ "optimization" : false ,
697+ "sourceMap" : true ,
698+ "vendorChunk" : true ,
699+ "buildOptimizer" : false
700+ }
701+ }
702+ }
703+ }
704+ }
705+ }
706+ ```
707+
708+ ** Solution - Option D: Use Single Quotes for Glob Pattern**
709+
710+ Make sure the test: ci script uses single quotes around the glob pattern:
711+
712+ ``` json
713+ {
714+ "scripts" : {
715+ "test:ci" : " ng test --no-watch --no-progress --browsers=ChromeHeadlessCI --code-coverage --include='**/time-planning-pn/**/*.spec.ts'"
716+ }
717+ }
718+ ```
719+
720+ ** Combined Recommended Configuration:**
721+
722+ For the best results in CI environments, combine multiple solutions in ` karma.conf.js ` :
723+
724+ ``` javascript
725+ module .exports = function (config ) {
726+ config .set ({
727+ basePath: ' ' ,
728+ frameworks: [' jasmine' , ' @angular-devkit/build-angular' ],
729+ plugins: [
730+ require (' karma-jasmine' ),
731+ require (' karma-chrome-launcher' ),
732+ require (' karma-jasmine-html-reporter' ),
733+ require (' karma-coverage' ),
734+ require (' @angular-devkit/build-angular/plugins/karma' )
735+ ],
736+ client: {
737+ jasmine: {},
738+ clearContext: false
739+ },
740+ jasmineHtmlReporter: {
741+ suppressAll: true
742+ },
743+ coverageReporter: {
744+ dir: require (' path' ).join (__dirname , ' ./coverage' ),
745+ subdir: ' .' ,
746+ reporters: [
747+ { type: ' html' },
748+ { type: ' text-summary' }
749+ ]
750+ },
751+ reporters: [' progress' , ' kjhtml' , ' coverage' ],
752+ port: 9876 ,
753+ colors: true ,
754+ logLevel: config .LOG_INFO ,
755+ autoWatch: true ,
756+ browsers: [' Chrome' ],
757+ customLaunchers: {
758+ ChromeHeadlessCI: {
759+ base: ' ChromeHeadless' ,
760+ flags: [
761+ ' --no-sandbox' ,
762+ ' --disable-gpu' ,
763+ ' --disable-dev-shm-usage' ,
764+ ' --disable-software-rasterizer' ,
765+ ' --disable-extensions' ,
766+ ]
767+ }
768+ },
769+ singleRun: false ,
770+ restartOnFileChange: true ,
771+ browserNoActivityTimeout: 60000 ,
772+ browserDisconnectTimeout: 10000 ,
773+ browserDisconnectTolerance: 3 ,
774+ captureTimeout: 210000 ,
775+ });
776+ };
777+ ```
778+
618779## Contact
619780
620781If you need help configuring the tests, check:
0 commit comments