I’ve encountered rare cases when Meteor runs the code of a module before the code of its imported modules have been run.
In my case, a Simple Schema (parent) imports another Simple Schema (child) that should extend the parent. But since the parent Schema runs before the imported child, the parent Schema won’t be extended with the child (which is still undefined when the parentSchema.extend(childSchema) call is being executed).
Interestingly, this only happens when I do meteor test
, not if I just start the app normally.
There are no cyclic dependencies, as the child Schema is only imported by parent Schemas, but does not import another Schema (or any other module) itself.
The only imports in the child Schema are:
import SimpleSchema from 'meteor/aldeed:simple-schema';
import { check } from 'meteor/check';
And still, this Schema’s code won’t run before all parent Schemas that include it; one of its parent Schemas runs before it (and thus lacks the child that should extend it).
What might cause such behaviour?