Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@ngtools/webpack): files are not being updated when using `allowJ…
…s` or `resolveJsonModule` (#13089) * fix(@ngtools/webpack): files are not being updated when using `allowJs` or `resolveJsonModule` Fixes #13076 and Fixes #12964 * test: add tests for allowJs and resolveJsonModule in watch mode * test: improve tests for `allowJs` When not using `allowJs` js files are not processed by the tsc compiler, but still processed by webpack. So a correct test should be to check that the JS is transpiled down to ES5 syntax.
- Loading branch information
1 parent
f8bafc2
commit 8bc6e79
Showing
4 changed files
with
141 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/angular_devkit/build_angular/test/browser/resolve-json-module_spec_large.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { runTargetSpec } from '@angular-devkit/architect/testing'; | ||
import { join, virtualFs } from '@angular-devkit/core'; | ||
import { debounceTime, take, tap } from 'rxjs/operators'; | ||
import { browserTargetSpec, host, outputPath } from '../utils'; | ||
|
||
|
||
describe('Browser Builder resolve json module', () => { | ||
beforeEach(done => host.initialize().toPromise().then(done, done.fail)); | ||
afterEach(done => host.restore().toPromise().then(done, done.fail)); | ||
|
||
it('works with watch', (done) => { | ||
host.writeMultipleFiles({ | ||
'src/my-json-file.json': `{"foo": "1"}`, | ||
'src/main.ts': `import * as a from './my-json-file.json'; console.log(a);`, | ||
}); | ||
|
||
host.replaceInFile( | ||
'tsconfig.json', | ||
'"target": "es5"', | ||
'"target": "es5", "resolveJsonModule": true', | ||
); | ||
|
||
const overrides = { watch: true }; | ||
|
||
let buildCount = 1; | ||
runTargetSpec(host, browserTargetSpec, overrides).pipe( | ||
debounceTime(1000), | ||
tap(() => { | ||
const content = virtualFs.fileBufferToString( | ||
host.scopedSync().read(join(outputPath, 'main.js')), | ||
); | ||
|
||
switch (buildCount) { | ||
case 1: | ||
expect(content).toContain('foo":"1"'); | ||
host.writeMultipleFiles({ | ||
'src/my-json-file.json': `{"foo": "2"}`, | ||
}); | ||
break; | ||
case 2: | ||
expect(content).toContain('foo":"2"'); | ||
break; | ||
} | ||
|
||
buildCount++; | ||
}), | ||
tap((buildEvent) => expect(buildEvent.success).toBe(true)), | ||
take(2), | ||
).toPromise().then(done, done.fail); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters