-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix most tests that break with es2020 output. #5991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix most tests that break with es2020 output. #5991
Conversation
@@ -15,7 +15,7 @@ limitations under the License. | |||
|
|||
import {Extent, Polyline, Rect} from './internal_types'; | |||
|
|||
export function convertRectToExtent(rect: Rect): Extent { | |||
function convertRectToExtent(rect: Rect): Extent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we continue to export these so that we can import them directly in places other than the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If code uses the functions directly then they won't be using the mocks.
For example:
If the code you're writing does this:
function myFunction() {
return convertRectToExtent(this.someRect);
}
But your test does this:
spyOn(ChartUtils, 'convertRectToExtent').and.returnValue(someExtent);
expect(myFunction()).toEqual(someExtent);
It won't work. Because you're replacing what ChartUtils.convertRectToExtent points to with a mock/spy but raw convertRectToExtent remains unmodified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yea that makes sense. Dang ok I guess we have to do it this way.
@@ -17,7 +17,7 @@ limitations under the License. | |||
*/ | |||
import {Component, Input, NO_ERRORS_SCHEMA} from '@angular/core'; | |||
import {ComponentFixture, TestBed} from '@angular/core/testing'; | |||
import * as loadMonacoShim from './load_monaco_shim'; | |||
import {MonacoShim} from './load_monaco_shim'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks the sync. Would you mind working on the fix?
See cl/487331149. Thanks
The migration to spec_bundle() will require we configure the TypeScript compiler to output to JavaScript 'es2020'. There is one pattern of code that we often use that will break: in my_utilities.ts: ``` export function myFuncToSpyOn() { // Some code. } ``` in my_test.ts: ``` import * as my_utilities from './my_utilities' spyOn(my_utilities, 'myFuncToSpyOn').and.returnValue(1); ``` The Jasmine library will complain: `Error: <spyOn> : myFuncToSpyOn is not declared writable or has no setter` Jasmine is aware of the issue but can't provide a fix: * jasmine/jasmine#1942 * https://jasmine.github.io/pages/faq.html#module-spy Instead they suggest we refactor our code so that the functions being spied on are wrapped in some Class or other Object. This PR does exactly that, for the most part doing the most simple of wrapping: now in my_utilities.ts: ``` // No longer exported. function myFuncToSpyOn() { // Some code. } export const MyUtilities = { myFuncToSpyOn } ``` now in my_test.ts: ``` import {MyUtilities} from './my_utilities' spyOn(MyUtilities, 'myFuncToSpyOn').and.returnValue(1); ``` The change has a bit of bigger blast radius because not only do the tests need to be changed but so does every other file (test or not) that are using the utility functions.
The migration to spec_bundle() will require we configure the TypeScript compiler to output to JavaScript 'es2020'. There is one pattern of code that we often use that will break: in my_utilities.ts: ``` export function myFuncToSpyOn() { // Some code. } ``` in my_test.ts: ``` import * as my_utilities from './my_utilities' spyOn(my_utilities, 'myFuncToSpyOn').and.returnValue(1); ``` The Jasmine library will complain: `Error: <spyOn> : myFuncToSpyOn is not declared writable or has no setter` Jasmine is aware of the issue but can't provide a fix: * jasmine/jasmine#1942 * https://jasmine.github.io/pages/faq.html#module-spy Instead they suggest we refactor our code so that the functions being spied on are wrapped in some Class or other Object. This PR does exactly that, for the most part doing the most simple of wrapping: now in my_utilities.ts: ``` // No longer exported. function myFuncToSpyOn() { // Some code. } export const MyUtilities = { myFuncToSpyOn } ``` now in my_test.ts: ``` import {MyUtilities} from './my_utilities' spyOn(MyUtilities, 'myFuncToSpyOn').and.returnValue(1); ``` The change has a bit of bigger blast radius because not only do the tests need to be changed but so does every other file (test or not) that are using the utility functions.
The migration to spec_bundle() will require we configure the TypeScript compiler to output to JavaScript 'es2020'. There is one pattern of code that we often use that will break: in my_utilities.ts: ``` export function myFuncToSpyOn() { // Some code. } ``` in my_test.ts: ``` import * as my_utilities from './my_utilities' spyOn(my_utilities, 'myFuncToSpyOn').and.returnValue(1); ``` The Jasmine library will complain: `Error: <spyOn> : myFuncToSpyOn is not declared writable or has no setter` Jasmine is aware of the issue but can't provide a fix: * jasmine/jasmine#1942 * https://jasmine.github.io/pages/faq.html#module-spy Instead they suggest we refactor our code so that the functions being spied on are wrapped in some Class or other Object. This PR does exactly that, for the most part doing the most simple of wrapping: now in my_utilities.ts: ``` // No longer exported. function myFuncToSpyOn() { // Some code. } export const MyUtilities = { myFuncToSpyOn } ``` now in my_test.ts: ``` import {MyUtilities} from './my_utilities' spyOn(MyUtilities, 'myFuncToSpyOn').and.returnValue(1); ``` The change has a bit of bigger blast radius because not only do the tests need to be changed but so does every other file (test or not) that are using the utility functions.
The migration to spec_bundle() will require we configure the TypeScript compiler to output to JavaScript 'es2020'. For the most part, this will require very little changes to our code. There is one glaring exception, though, that we mostly address in this PR.
The following pattern will break:
in my_utilities.ts:
in my_test.ts:
The Jasmine library will complain:
Error: <spyOn> : myFuncToSpyOn is not declared writable or has no setter
Jasmine is aware of the issue but can't provide a fix:
Instead they suggest we refactor our code so that the functions being spied on are wrapped in some Class or other Object.
This PR does exactly that, for the most part doing the most simple of wrapping:
now in my_utilities.ts:
now in my_test.ts:
The change has a bit of bigger blast radius because not only do the tests need to be changed but so does every other file (test or not) that are using the utility functions.