@@ -10,6 +10,7 @@ import { concatMap, count, debounceTime, distinctUntilChanged, take, timeout } f
10
10
import { execute } from '../../index' ;
11
11
import { BASE_OPTIONS , KARMA_BUILDER_INFO , describeKarmaBuilder } from '../setup' ;
12
12
import { BuilderOutput } from '@angular-devkit/architect' ;
13
+ import { randomBytes } from 'node:crypto' ;
13
14
14
15
describeKarmaBuilder ( execute , KARMA_BUILDER_INFO , ( harness , setupTarget ) => {
15
16
describe ( 'Behavior: "Rebuilds"' , ( ) => {
@@ -68,5 +69,59 @@ describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
68
69
69
70
expect ( buildCount ) . toBe ( expectedSequence . length ) ;
70
71
} ) ;
72
+
73
+ it ( 'correctly serves binary assets on rebuilds' , async ( ) => {
74
+ await harness . writeFiles ( {
75
+ './src/random.bin' : randomBytes ( 1024 ) ,
76
+ './src/app/app.component.spec.ts' : `
77
+ describe('AppComponent', () => {
78
+ it('should fetch binary file with correct size', async () => {
79
+ const resp = await fetch('/random.bin');
80
+ const data = await resp.arrayBuffer();
81
+ expect(data.byteLength).toBe(1024);
82
+ });
83
+ });` ,
84
+ } ) ;
85
+
86
+ harness . useTarget ( 'test' , {
87
+ ...BASE_OPTIONS ,
88
+ watch : true ,
89
+ assets : [ 'src/random.bin' ] ,
90
+ } ) ;
91
+
92
+ interface OutputCheck {
93
+ ( result : BuilderOutput | undefined ) : Promise < void > ;
94
+ }
95
+
96
+ const expectedSequence : OutputCheck [ ] = [
97
+ async ( result ) => {
98
+ // Karma run should succeed.
99
+ expect ( result ?. success ) . withContext ( 'Initial test run should succeed' ) . toBeTrue ( ) ;
100
+ // Modify test file to trigger a rebuild
101
+ await harness . appendToFile (
102
+ 'src/app/app.component.spec.ts' ,
103
+ `\n;console.log('modified');` ,
104
+ ) ;
105
+ } ,
106
+ async ( result ) => {
107
+ expect ( result ?. success ) . withContext ( 'Test should succeed again' ) . toBeTrue ( ) ;
108
+ } ,
109
+ ] ;
110
+
111
+ const buildCount = await harness
112
+ . execute ( { outputLogsOnFailure : true } )
113
+ . pipe (
114
+ timeout ( 60000 ) ,
115
+ debounceTime ( 500 ) ,
116
+ concatMap ( async ( { result } , index ) => {
117
+ await expectedSequence [ index ] ( result ) ;
118
+ } ) ,
119
+ take ( expectedSequence . length ) ,
120
+ count ( ) ,
121
+ )
122
+ . toPromise ( ) ;
123
+
124
+ expect ( buildCount ) . toBe ( expectedSequence . length ) ;
125
+ } ) ;
71
126
} ) ;
72
127
} ) ;
0 commit comments