Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): load polyfills and runtime as scr…
Browse files Browse the repository at this point in the history
…ipts 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 #24651
  • Loading branch information
alan-agius4 authored and angular-robot[bot] committed Feb 3, 2023
1 parent 175b716 commit bf3be56
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
// All served files with the latest timestamps
%MAPPINGS%
</script>
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous" type="module"></script>
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous" type="module"></script>
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous"></script>
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous"></script>
<!-- Dynamically replaced with <script> tags -->
%SCRIPTS%
<script src="_karma_webpack_/scripts.js" crossorigin="anonymous" defer></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
// All served files with the latest timestamps
%MAPPINGS%
</script>
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous" type="module"></script>
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous" type="module"></script>
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous"></script>
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous"></script>
<!-- Dynamically replaced with <script> tags -->
%SCRIPTS%
<script src="_karma_webpack_/scripts.js" crossorigin="anonymous" defer></script>
Expand Down
37 changes: 37 additions & 0 deletions tests/legacy-cli/e2e/tests/test/test-jasmine-clock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ng } from '../../utils/process';
import { writeFile } from '../../utils/fs';

export default async function () {
await writeFile(
'src/app/app.component.spec.ts',
`
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeAll(() => {
jasmine.clock().install();
});
afterAll(() => {
jasmine.clock().uninstall();
});
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [AppComponent],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
expect(fixture.componentInstance).toBeTruthy();
});
});
`,
);

await ng('test', '--watch=false');
}

0 comments on commit bf3be56

Please sign in to comment.