closure-library icon indicating copy to clipboard operation
closure-library copied to clipboard

jsunit not calls setUp when optimizations are on

Open emaxx-google opened this issue 3 years ago • 3 comments

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.

emaxx-google avatar Jan 25 '22 06:01 emaxx-google

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 avatar Jan 27 '22 19:01 shicks

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?

shicks avatar Jan 27 '22 19:01 shicks

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: https://github.com/GoogleChromeLabs/chromeos_smart_card_connector/pull/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?).

emaxx-google avatar Jan 28 '22 04:01 emaxx-google