Skip to content

Commit 838b2f4

Browse files
committed
test(@angular-devkit/build-angular): add file replacement watch test
courtesy of @filipesilva
1 parent 4016933 commit 838b2f4

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

packages/angular_devkit/build_angular/test/browser/replacements_spec_large.ts

+42-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { runTargetSpec } from '@angular-devkit/architect/testing';
1010
import { join, normalize, virtualFs } from '@angular-devkit/core';
11-
import { tap } from 'rxjs/operators';
11+
import { debounceTime, take, tap } from 'rxjs/operators';
1212
import { browserTargetSpec, host } from '../utils';
1313

1414

@@ -100,4 +100,45 @@ describe('Browser Builder file replacements', () => {
100100
runTargetSpec(host, browserTargetSpec, overrides)
101101
.subscribe(undefined, () => done(), done.fail);
102102
});
103+
104+
it('file replacements work with watch mode', (done) => {
105+
const overrides = {
106+
fileReplacements: [
107+
{
108+
replace: normalize('/src/meaning.ts'),
109+
with: normalize('/src/meaning-too.ts'),
110+
},
111+
],
112+
watch: true,
113+
};
114+
115+
let buildNumber = 0;
116+
117+
runTargetSpec(host, browserTargetSpec, overrides, 45000).pipe(
118+
debounceTime(1000),
119+
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
120+
tap(() => {
121+
const fileName = join(outputPath, 'main.js');
122+
const content = virtualFs.fileBufferToString(host.scopedSync().read(fileName));
123+
buildNumber += 1;
124+
125+
switch (buildNumber) {
126+
case 1:
127+
expect(content).toMatch(/meaning\s*=\s*42/);
128+
expect(content).not.toMatch(/meaning\s*=\s*10/);
129+
host.writeMultipleFiles({
130+
'src/meaning-too.ts': 'export var meaning = 84;',
131+
});
132+
break;
133+
134+
case 2:
135+
expect(content).toMatch(/meaning\s*=\s*84/);
136+
expect(content).not.toMatch(/meaning\s*=\s*42/);
137+
break;
138+
}
139+
}),
140+
take(2),
141+
).toPromise().then(() => done(), done.fail);
142+
});
143+
103144
});

0 commit comments

Comments
 (0)