Skip to content

Commit 6ca70c8

Browse files
committed
fix(@angular-devkit/build-angular): load polyfills and runtime as scripts instead of modules
This commit updates changes the way polyfills and runtime are loaded from modules to scripts. This is required as otherwise Jasmine will be loaded prior to Zone.js which causes clock patching not to work. Closes angular#24651
1 parent fac1e58 commit 6ca70c8

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

Diff for: packages/angular_devkit/build_angular/src/webpack/plugins/karma/karma-context.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
// All served files with the latest timestamps
3131
%MAPPINGS%
3232
</script>
33-
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous" type="module"></script>
34-
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous" type="module"></script>
33+
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous"></script>
34+
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous"></script>
3535
<!-- Dynamically replaced with <script> tags -->
3636
%SCRIPTS%
3737
<script src="_karma_webpack_/scripts.js" crossorigin="anonymous" defer></script>

Diff for: packages/angular_devkit/build_angular/src/webpack/plugins/karma/karma-debug.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
// All served files with the latest timestamps
3333
%MAPPINGS%
3434
</script>
35-
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous" type="module"></script>
36-
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous" type="module"></script>
35+
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous"></script>
36+
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous"></script>
3737
<!-- Dynamically replaced with <script> tags -->
3838
%SCRIPTS%
3939
<script src="_karma_webpack_/scripts.js" crossorigin="anonymous" defer></script>
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ng } from '../../utils/process';
2+
import { writeFile } from '../../utils/fs';
3+
4+
export default async function () {
5+
await writeFile(
6+
'src/app/app.component.spec.ts',
7+
`
8+
import { TestBed } from '@angular/core/testing';
9+
import { RouterTestingModule } from '@angular/router/testing';
10+
import { AppComponent } from './app.component';
11+
12+
describe('AppComponent', () => {
13+
beforeAll(() => {
14+
jasmine.clock().install();
15+
});
16+
17+
afterAll(() => {
18+
jasmine.clock().uninstall();
19+
});
20+
21+
beforeEach(async () => {
22+
await TestBed.configureTestingModule({
23+
imports: [RouterTestingModule],
24+
declarations: [AppComponent],
25+
}).compileComponents();
26+
});
27+
28+
it('should create the app', () => {
29+
const fixture = TestBed.createComponent(AppComponent);
30+
expect(fixture.componentInstance).toBeTruthy();
31+
});
32+
});
33+
`,
34+
);
35+
36+
await ng('test', '--watch=false');
37+
}

0 commit comments

Comments
 (0)