Skip to content
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

jsunit not calls setUp when optimizations are on #1151

Open
emaxx-google opened this issue Jan 25, 2022 · 3 comments
Open

jsunit not calls setUp when optimizations are on #1151

emaxx-google opened this issue Jan 25, 2022 · 3 comments
Assignees

Comments

@emaxx-google
Copy link

emaxx-google commented Jan 25, 2022

In the goog.testing.TestCase.Test constructor the setUp and tearDown properties are extracted from objChain without using quoted string syntax. Therefore this breaks when the Closure Compiler's advanced optimizations are on, as these setUp accesses get renamed to something that doesn't match the property names in the test code.

@shicks
Copy link
Member

shicks commented Jan 27, 2022

Can you point me to a (minimal) example demonstrating the breakage? (If you want to ping me internally, that's fine.)

I think I know how to fix it, but if you've already got a regression test, it would save me a lot of time over trying to reproduce the issue myself.

@shicks shicks self-assigned this Jan 27, 2022
@shicks
Copy link
Member

shicks commented Jan 27, 2022

Alternatively, if we don't really have a good way to set up a regression test (we don't compile our tests internally, obviously/unfortunately), maybe you could send a PR that you've verified works for your case?

@emaxx-google
Copy link
Author

The minified example is:

goog.require('goog.testing.jsunit');
goog.global['testMy'] = {
  'setUp': function() {
    console.error('setUp called');
  },
  'tearDown': function() {
    console.error('tearDown called');
  },
  'test': function() {
    console.error('test called');
  },
};

It prints three log messages when compiled in the SIMPLE mode, and only one in the ADVANCED mode.

As for the fix - I believe you already prepared the fix that seems to coincide with the patch that I made locally in my fork: GoogleChromeLabs/chromeos_smart_card_connector#519.
I didn't upload it as a PR myself as I wasn't sure it covers all possible cases. In particular, I was unsure whether goog.testing.TestCase.setUp needs to be quoted too (can it be passed in objChain to goog.testing.TestCase.Test?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants