I’ve been working on this general problem for the past couple of months now… specifically, how to package a component, provide test coverage for it (in my case, acceptance/validation test coverage), and then move files from the package into the
tests/ folder so they can be run.
My solution was to create the
starrynight command line utility that has scaffolding utilities which can clone a repository and copy files into the correct directories. That way, a package can store files in the manner you are suggesting, but a command can be run that will extract the files into the /tests folder.
starrynight create --package foo:mypackage --from /path/to/component
starrynight create command is a refactoring tool which will take the files within the
client/component/commentsForm directory, and move them into a
/packages/commentsForm and scaffold a package for you.
starrynight pattern --url http://github.com/myaccount/myrepo
Once published, the
starrynight pattern command will clone your repo into the
/packages directory, and then copy the test files within it into the
/tests directory. Well, the nightwatch tests anyway. It would be simple enough to add mocha and jasmine support; just copy the lines 49 through 62 a couple times, and specify the relevant directories.
There’s lots more approaches like this we could do. What if tests were stored within a
.tests folder within a component directory? We could write a script that parses through the
/server directories, and extracts all of the files within
.test subdirectories into the
/tests directory. Then we could run that script as part of the build pipeline, and they’d be refreshed each time the Meteor app restarts.
You might be interested in taking a look at the clinical:hipaa-audit-log package to see a component-scoped
tests directory in action. I was rather pleased with how it turned out, as this approach allows me to provide API extensions in each package README. That is, it allows us to say 'This package provides the
reviewHipaaAuditLogPage() Nightwatch API`.