xolvio / qualityfaster

An example project showing how to create robust and maintainable acceptance tests
262 stars 58 forks source link

Module loading logic #25

Closed rhyslbw closed 8 years ago

rhyslbw commented 8 years ago

I'm trying to better understand module-loader.js (or on server):

// Force meteor to load modules at build time, so they can be required in Chimp's server.execute
if (false) {
  require('./imports/domain/services/bank-service/client');
  require('./imports/application/services/account-service/client');
}

Can you explain this in more detail? What confuses me is why there's a conditional that will never evaluate to true, and therefore never be called

ghost commented 8 years ago

This is a hack to make the Meteor build tool include this files in the built app, when nothing of the app code requires this files yet. With this hack Chimp can require this files in server.execute blocks. Without it, the files would not be included in the built Meteor app and couldn't be required in server.execute blocks.

rhyslbw commented 8 years ago

Ok so this allows code to be written without needing it to be imported into some part of the app, and suits a TDD workflow. Anyone interested, here's the background: https://github.com/meteor/meteor/issues/6068#issuecomment-178940948

Given this is a standard development approach and we can't just require the file in the test at runtime, it would be nice to at least improve the current situation.

Some ideas:

  1. Add a more detailed comment
  2. Make an expressive global variable (that equals false) eg is(notYetImported)
  3. A wrapper function that is even more expressive eg addToBuild()
  4. ?
rhyslbw commented 8 years ago

Digging a little deeper I can see this is being thought about and tracked elsewhere. Will close this for now