I need to determine the name of the Meteor package that a given test file is currently testing, so that I can derive the path to assets. For example, if we're testing fortawesome:fontawesome, the assets will be accessible at /packages/fortawesome_fontawesome/
.
How can I get the name of the very package that TinyTest is testing?
package.js:
Package.onTest(function (api) {
api.use(packageName, where);
api.use(['tinytest', 'http'], 'client');
api.addFiles('test.js', 'client');
});
test.js:
var packageName = ???;
HTTP.get('/packages/' + packageName.replace(':', '_') + '/fonts/fontawesome-webfont.woff');
I haven't found an API call for this, but the Package
object contains all loaded packages, including one that starts with local-test
, which has so far been the tested package:
Therefore,
var packageName = _.find(Object.keys(Package), function(p) {
return p.search(/local-test/) > -1
}).replace('local-test:', '');
Note however that for some mysterious reason, the local-test:<your_package>
package isn't loaded before the first Tinytest call, so careful where you place the code above.