Continuous Integration – Should Tests Be Run Against src or dist?

continuous integrationjavascriptunit testing

I've had a dispute with a colleague about when to run JavaScript unit tests in a CI environment at one of two different times. Let's call the two parties PE (pro-early) and PL (pro-late).

Early (against src)

Running the tests against the source code right out of the version control system.

PE says that we should run the riskiest code first and "fail fast." Both parties agree that we should run unit tests this way during development because the cycle time is much faster. PE says that since we need to have the build configured to run early in any case, an alternate configuration that runs the tests late constitues duplication and bloat.

Late (against dist)

Running the same tests against code has been packaged up (concatenated and minified).

PL says that we should test the code as it ships. PL claims to have experienced time-consuming scenarios where the code worked when run directly from source, but failed because of something that went wrong when the code was packaged for distribution.

PE says a hypothetical "something might go wrong" is a weak argument. And anyway it's not CI's job to catch that kind of problem. The distributable code is tested by QA before it's shipped.

Further details

"Early and late in CI" is not an option, much to PEL's dismay.

The code is modularized using AMD and RequireJS. We're using Karma for unit tests and Grunt for the build script.

So which is it — early or late?

Is one side definitely right? Are we missing any considerations that may sway one person to the other side?

Best Answer

From a generic testing point of view:

"Testing early" is a workflow optimization. It helps you iterate faster by failing quickly. Tests that are close to source code, like unit tests, are useful here.

"Testing late" is a requirement for quality assurance. You must test code exactly as it ships, because as you said, there are multiple places where things can go wrong even after the source code is validated. High-level tests that integrate multiple components are useful here.

You should be doing both low-level and high-level tests. I'm not sure why "early and late" is not an option, but that is exactly what I'd recommend.