Title: `@angular-devkit/build-angular` breaks Jasmine's mock clock · Issue #11626 · angular/angular-cli · GitHub
Open Graph Title: `@angular-devkit/build-angular` breaks Jasmine's mock clock · Issue #11626 · angular/angular-cli
X Title: `@angular-devkit/build-angular` breaks Jasmine's mock clock · Issue #11626 · angular/angular-cli
Description: Bug Report or Feature Request (mark with an x) - [x] bug report -> please search issues before submitting - [ ] feature request Command (mark with an x) - [x] test Versions > node --version v8.11.3 > npm --version 5.6.0 > ng --version An...
Open Graph Description: Bug Report or Feature Request (mark with an x) - [x] bug report -> please search issues before submitting - [ ] feature request Command (mark with an x) - [x] test Versions > node --version v8.11.3...
X Description: Bug Report or Feature Request (mark with an x) - [x] bug report -> please search issues before submitting - [ ] feature request Command (mark with an x) - [x] test Versions > node --version v...
Opengraph URL: https://github.com/angular/angular-cli/issues/11626
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`@angular-devkit/build-angular` breaks Jasmine's mock clock","articleBody":"### Bug Report or Feature Request (mark with an `x`)\r\n```\r\n- [x] bug report -> please search issues before submitting\r\n- [ ] feature request\r\n```\r\n\r\n### Command (mark with an `x`)\r\n```\r\n- [x] test\r\n```\r\n\r\n### Versions\r\n```\r\n> node --version\r\nv8.11.3\r\n\r\n> npm --version\r\n5.6.0\r\n\r\n> ng --version\r\nAngular CLI: 6.1.0-rc.3\r\nNode: 8.11.3\r\nOS: win32 x64\r\nAngular: 6.0.9\r\n... animations, common, compiler, compiler-cli, core, forms\r\n... http, language-service, platform-browser\r\n... platform-browser-dynamic, router\r\n\r\nPackage Version\r\n-----------------------------------------------------------\r\n@angular-devkit/architect 0.7.0-rc.3\r\n@angular-devkit/build-angular 0.7.0-rc.3\r\n@angular-devkit/build-optimizer 0.7.0-rc.3\r\n@angular-devkit/build-webpack 0.7.0-rc.3\r\n@angular-devkit/core 0.7.0-rc.3\r\n@angular-devkit/schematics 0.7.0-rc.3\r\n@angular/cli 6.1.0-rc.3\r\n@ngtools/webpack 6.1.0-rc.3\r\n@schematics/angular 0.7.0-rc.3\r\n@schematics/update 0.7.0-rc.3\r\nrxjs 6.2.2\r\ntypescript 2.7.2\r\nwebpack 4.9.2\r\n```\r\nOS: Windows 10\r\n\r\n### Repro steps\r\n1. `npm install --global @angular/cli`.\r\n2. `ng new test-app && cd test-app`.\r\n3. `npm test` --> Passed ✔️\r\n4. Add a test in `src/app/app.component.spec.ts` that uses `jasmine.clock().install()`. E.g.:\r\n ```ts\r\n it('should pass', () => {\r\n jasmine.clock().install();\r\n expect(true).toBe(true);\r\n jasmine.clock().uninstall();\r\n });\r\n ```\r\n5. `npm test` --> Fails ❌\r\n > Error: Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?\r\n\r\n### The log given by the failure\r\n```\r\nChrome 67.0.3396 (Windows 10.0.0) AppComponent should pass FAILED\r\n Error: Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?\r\n at UserContext.eval (webpack:///./src/app/app.component.spec.ts?:31:25)\r\n at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone.js?:387:26)\r\n at ProxyZoneSpec.onInvoke (webpack:///./node_modules/zone.js/dist/zone-testing.js?:287:39)\r\n at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone.js?:386:32)\r\n at Zone.run (webpack:///./node_modules/zone.js/dist/zone.js?:137:43)\r\n at runInTestZone (webpack:///./node_modules/zone.js/dist/zone-testing.js?:508:34)\r\nChrome 67.0.3396 (Windows 10.0.0) AppComponent should pass FAILED\r\n Error: Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?\r\n at UserContext.eval (webpack:///./src/app/app.component.spec.ts?:31:25)\r\n at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone.js?:387:26)\r\n at ProxyZoneSpec.onInvoke (webpack:///./node_modules/zone.js/dist/zone-testing.js?:287:39)\r\n at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone.js?:386:32)\r\n at Zone.run (webpack:///./node_modules/zone.js/dist/zone.js?:137:43)\r\n at runInTestZone (webpack:///./node_modules/zone.js/dist/zone-testing.js?:508:34)\r\n at UserContext.eval (webpack:///./node_modules/zone.js/dist/zone-testing.js?:523:20)\r\nChrome 67.0.3396 (Windows 10.0.0): Executed 4 of 4 (1 FAILED) (0 secs / 0.433 secs)\r\nChrome 67.0.3396 (Windows 10.0.0) AppComponent should pass FAILED\r\n Error: Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?\r\n at UserContext.eval (webpack:///./src/app/app.component.spec.ts?:31:25)\r\n at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone.js?:387:26)\r\n at ProxyZoneSpec.onInvoke (webpack:///./node_modules/zone.js/dist/zone-testing.js?:287:39)\r\n at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone.js?:386:32)\r\n at Zone.run (webpack:///./node_modules/zone.js/dist/zone.js?:137:43)\r\n at runInTestZone (webpack:///./node_modules/zone.js/dist/zone-testing.js?:508:34)\r\nChrome 67.0.3396 (Windows 10.0.0): Executed 4 of 4 (1 FAILED) (0.462 secs / 0.433 secs)\r\n```\r\n\r\n### Desired functionality\r\nNo errors :grin:\r\n\r\n### Mention any other details that might be useful\r\nAFAICT, the problem is caused by incorrect order of code execution. More specifically:\r\n- Jasmine stores the global timing functions (such as `setTimeout`).\r\n- When calling `jasmine.clock().install()`, it overwrites the timing functions with mocks.\r\n- Before doign so, it checks whether the currently global timing functions are different than what it has stored in step 1. If so, it assumes the clock is already installed (i.e. the functions are overwritten) and throws.\r\n- Zone.js also overwrites the global timing functions to make them zone-aware.\r\n\r\nIn order for this to work, Zone.js must patch the global functions before Jasmine stores the \"original\" global functions (to later compare them and determine if the clock is already installed). For some reason, it seems that Jasmine is storing the global functions before Zone.js has patched them. Then, once we call `jasmine.clock().install()`, Jasmine compares the orignal, unpatched global functions with the current global functions (which have since been patched by Zone.js) and finds that they are not the same (and throws).\r\n\r\nI have no idea why this is happening, but by trying out several versions I have found out this is broken in `@angular-devkit/build-angular` v0.6.8 (and all the way through v0.7.0-rc.3). The commit that broke it is 0b126f6d3 and more specifically [this change][1].\r\n\r\nReverting the `test` property back to also check `!chunks.some(({ name }) => name === 'polyfills')` fixes the issue.\r\n\r\n[1]: https://github.com/angular/angular-cli/commit/0b126f6d34ac5d94a5fb96d38f23b2b690afd56d#diff-8311f86ef0adf0533613f54692cbd2abR80","author":{"url":"https://github.com/gkalpak","@type":"Person","name":"gkalpak"},"datePublished":"2018-07-23T12:24:22Z","url":"https://github.com/angular/angular-cli/issues/11626"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:48cb6b77-8b73-5572-4abf-01c235a54132 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DDEA:21AC3F:BEB1B9:F4E5A8:6B00E874 |
| html-safe-nonce | cc9d7579414d87625b0edc2a2b6fd7f54e98b81059e7af8d4a54abff28813f6a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEREVBOjIxQUMzRjpCRUIxQjk6RjRFNUE4OjZCMDBFODc0IiwidmlzaXRvcl9pZCI6IjgwNDkwNTk5NjkxMTY0NjUyNjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 58821a4a737d788124e3f4ef28b09db7a1b74b8c0b37e6ec0128619d81443994 |
| hovercard-subject-tag | issue:343610848 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/11626/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7c10b9e31003b4bc82800ce20b455f8da22a47c2699c1ba840ba85b6f8aa3fe5/angular/angular-cli/issues/11626 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7c10b9e31003b4bc82800ce20b455f8da22a47c2699c1ba840ba85b6f8aa3fe5/angular/angular-cli/issues/11626 |
| og:image:alt | Bug Report or Feature Request (mark with an x) - [x] bug report -> please search issues before submitting - [ ] feature request Command (mark with an x) - [x] test Versions > node --version v8.11.3... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gkalpak |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width