0

I'm having an issue triggering method calls while writing feature tests. I'm not actually given an error in the chimp terminal log, but the server.call line is where the failure is highlighted. I believe this might be related to the folder structure of the app (which I've loosely based on Letterpress) or the order in which the call is defined and then triggered. When I move the method call out to my main.js file (in the root folder of the app), it works without a problem.

hooks.js path: /app/tests/cucumber/features/support/hooks.js

(function(){
    module.exports = function() {
        this.Before(function() {
            console.log("server calling");
            server.call("fixtures/resetUsers"); //test stops here
        });
    };
})();

fixtures.js /app/packages/fixtures/fixtures.js

(function(){
    'use strict';

    Meteor.methods({
        "fixtures/resetUsers": function() {
            Meteor.users.remove({});
        }
    });
})();

package.js /app/packages/fixtures/packages.js

Package.describe({
    name: 'forum:fixtures',
    version: '0.0.1',
    summary: '',
    debugOnly: true
});

Package.onUse(function(api) {
    api.versionsFrom('1.2.1');
    api.use('ecmascript');
    api.addFiles('fixtures.js', 'server');
});

Note: I originally didn't have the fixtures folder wrapped in the packages folder (it still didn't work then) but came across this post by @Xolv.io, the developers of Chimp.js who advised to do so.

Community
  • 1
  • 1
Kyle Bachan
  • 1,053
  • 2
  • 15
  • 33

2 Answers2

1

with the new chimp, you can just use:

server.execute(function() {
  // code you put here will run on the server
});

Check this repository for examples: https://github.com/xolvio/automated-testing-best-practices/

Xolv.io
  • 2,483
  • 1
  • 15
  • 17
  • This did it! Just FYI for future readers--you need to add the package xolvio:backdoor for this to work. – Kyle Bachan Feb 12 '16 at 17:58
  • Oh, I may have spoken too soon. I forgot I had moved the fixture code out to the common.js file as opposed to the packages folder which you recommended. Using the server.execute block, I now get the error: "Error in server.executeError: Method not found" so it must not be finding the defined Meteor method in the fixtures folder. – Kyle Bachan Feb 12 '16 at 22:39
  • Super sorry for the delay--I had to recreate an app with the issue since I was initially working with a private repo and unable to share from that. This one here triggers the same error: https://github.com/programthis/sample-chimp – Kyle Bachan Feb 23 '16 at 21:52
0

In your sample repo, if you define a meteor method, 'something', you can call as server.call('something'). If you have a standard method definition (not even a meteor method), say something2=function(){}, with xolvio:backdoor, you can server.execute('something2'). ( calling chimp with --ddp switch)