#2798 JS Test Code

SlimerDude Mon 1 Jun

Just a thought - in the interests of streaming lining / minifying Fantom JS content delivery, perhaps Test code could be left out of the generated Fantom .js files?

I note that in particular the concurrent and graphics pods ship Test code in their .js files, so I assume the other core pods do too.

For instance, I see the following JS classes being delivered to the browser and many more:

  • fan.concurrent.ConcurrentMapTest
  • fan.concurrent.AtomicTest
  • fan.graphics.GeomTest
  • fan.graphics.FontTest

brian Mon 1 Jun

Its designed so you can do your builds with the stripTest build config property. Or set the FAN_BUILD_STRIPTEST=true environment variable. See BuildPod

SlimerDude Mon 1 Jun

Thanks Brian. Sure, I could re-compile the core pods myself from source...

...I was just thinking that typically one looks to minify JS files, and the Test classes will probably never be used in a prod environment or be tested in a Browser - so perhaps Fantom could look at excluding them from the core pods in future builds?

That way, anyone else looking to use Fantom in a web app doesn't have to re-compile their own distribution.

I understand this may go against the Fantom ethos of bundling test code in pods, but in the case of JS files, I don't see that much benefit in it.

brian Wed 1 Jul

I think we would need to make a decision to always have test code or never have test code in the build zip itself. And if we go never, then that would mean omitting testSys, testCompiler, etc.

I can see both arguments and don't have a strong preference myself. So would be interested in community feedback:

Option A: Include all test cases and test pods in build.zip (todays behavior)

Option B: Omit all test cases and test pods from build zip

SlimerDude Mon 13 Jul

I think I've realised this is a actually a tricksy ask!

In general, I'm happy for all code in test/ directories to be left out of distributed pods, but...

...if there's no test code in the pods, then how do you run the tests!?

I guess there'll need to be a build switch to include / exclude test dirs, similar to what there is now, but more accessible from the cmd line.

andy Tue 14 Jul

This on my todo list as well.

...if there's no test code in the pods, then how do you run the tests!?

Yeah generally I want to the test code on the host system -- but not on the target system.

So I've wondered if we shouldn't have a runtime tool that can strip the test classes post-build.

SlimerDude Thu 16 Jul

a runtime tool that can strip the test classes post-build.

Hmm, that sounds very prone to error as how would you know post-build which files, classes, and resources were in the test/ directory? And how would you dis-entangle the such compiled source and data from .js files?

Instead I would suggest Fantom enters a more standard means of compilation where file sets dictate which directories are used for various build phases. A cut down version of this idea was already mentioned and largely agreed upon in BuildPod: special configuration for test dirs

But I believe the current feature of the stripTest build config property already does, pretty much, what everyone wants. I was just asking if it could be invoked when building the official Fantom releases.

andy Thu 16 Jul

Trying to solve this at build time is not really practical — remember its not just Fantom core — its any dependencies you have — some of which may not be open source. So you would be at the liberty of whatever the author chose todo. Not to mention it creates extra complexity of "debug" versus "production" pod releases/patches.

So I think you have to solve this at runtime to make it work. I also don’t think you get crazy with static analysis — its just a convention you need to follow — any code under test/ should not be a dependency on anything in your pod.

But you are correct — we probably need a formal way in the build system to identify what is in the test/ directory post-compilation.

Login or Signup to reply.