javascriptgoogle-closureplovr

Plovr externs don't load when using test-template option


I am using plovr to run unit tests for my JavaScript code that uses Google Closure Library. My setup was working fine until I needed to run some asynchronous tests. I found out from this discussion that I needed to replace the default org.plovr.test.soy file by using plovr's test-template option.

I updated the test.soy file so I could use goog.testing.ContinuationTestCase:

<body>
  <script src="{$baseJsUrl}"></script>

  //This script tag was added.
  <script>
    goog.require('goog.testing.jsunit');
    goog.require('goog.testing.ContinuationTestCase');
  </script>

  <script src="{$testJsUrl}"></script>
</body>

Now my unit tests using ContinuationTestCase work, but an a different unexpected problem has popped up. My externs are not being loaded! See my plovr configuration below:

{
  "id": "peders-app",
  "inputs": "src/peder/application.js",
  "paths": "src/peder",
  "output-file": "compiled.js",
  "externs": "src/peder/kinetic-externs.js",
  "test-template":"test/org.plovr.test.soy"
}

When I didn't have test-template in my config, my externs loaded fine, but my unit tests using ContinuationTestCase fail.

When I add the test-template option, my unit tests using ContinuationTestCase pass, but many other tests fail since the externs are not loaded.

Below are the error that make me believe the externs aren't working:

12:25:39.398  Start
12:25:39.400  testAddLine : PASSED
12:25:39.402  testCreateUndoCommand : PASSED
12:25:39.403  testUpdateLocalData : PASSED
12:25:39.404  testUpdateServerData : PASSED
12:25:39.404  Done

JS ERROR: Uncaught ReferenceError: Kinetic is not defined
URL: http://localhost:9810/input/peders-app/src/peder/smartPoint.js
Line: 143
JS ERROR: Uncaught TypeError: Cannot read property 'prototype' of undefined
URL: http://localhost:9810/input/peders-app/src/peder/modifyLine.js
Line: 24
JS ERROR: Uncaught ReferenceError: Kinetic is not defined
URL: http://localhost:9810/input/peders-app/src/peder/shapes/line.js
Line: 154

Does anyone know why using a custom test-template would stop my externs from being loaded?


Solution

  • It turns out that the externs were never being loaded when running tests for some reason. The errors from where functions from the externs were being called just weren't causing the tests to fail. I still have no clue why using the test-template option made the errors fail the tests, but luckily I found a workaround.

    I simply added my externs directly into the plovr jar. To do this just add your extern into the externs folder inside plovr.jar. Then update externs_manifest.txt at the top level of the plovr jar to include whatever files you added. This will make plovr treat your extern as a default extern.

    This probably isn't the "right" way to fix this problem, but it gets the job done.