xolvio / qualityfaster

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

I having problems with service configurations #37

Closed gerwinbrunner closed 8 years ago

gerwinbrunner commented 8 years ago

I added accounts-facebook to this app.

When I start the app and the @focus features run I can do this in the browser: Accounts.loginServiceConfiguration.find().fetch() Found: 1

As soon as the [chimp] critical scenarios... are run the service configuration is lost. Accounts.loginServiceConfiguration.find().fetch() Found: 0

Any idea where the problem here could be?

ghost commented 8 years ago

The database is reseted before each scenario. You need to insert the service configuration after this line.

gerwinbrunner commented 8 years ago

Do you have a hint how? @Sanjo

gerwinbrunner commented 8 years ago

I have a regular service configuration file like this:

ServiceConfiguration.configurations.remove({
  service: 'facebook',
});

ServiceConfiguration.configurations.insert({
  service: 'facebook',
  appId:   '1x060107363xxxx2',
  secret:  '6x5c67c5xxxxxxxxxcf5e0ab',
});
gerwinbrunner commented 8 years ago

How would I rerun that file for the tests?

ghost commented 8 years ago

Just expose this code as a function on the server side. The server.execute blocks runs on the server. With ES2015 modules it is:

export function configureServices() {
  ServiceConfiguration.configurations.remove({
    service: 'facebook',
  });

  ServiceConfiguration.configurations.insert({
    service: 'facebook',
    appId:   '1x060107363xxxx2',
    secret:  '6x5c67c5xxxxxxxxxcf5e0ab',
  });
}

Code that comes after https://github.com/xolvio/automated-testing-best-practices/blob/master/tests/step_definitions/critical/support/fixtures/common-fixtures.js#L6:

require('/imports/path/to/services_configurations.js').configureServices();

If you don't use ES2015 modules, you can expose the function on the global scope. global.configureServices = ....

gerwinbrunner commented 8 years ago

@Sanjo I did try it that way, but now I get this error

    Before 
      Error: Error in server.executeReferenceError: _serviceConfigurations is not defined
      ReferenceError: _serviceConfigurations is not defined
        @ evalmachine.<anonymous>:3:11
        @ [object Object].xolvioBackdoor (packages/xolvio:backdoor/server.js:10:54)
        @ maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1704:12)
        @ packages/ddp-server/livedata_server.js:711:19
        @ [object Object]._.extend.withValue (packages/meteor.js:1100:17)
        @ packages/ddp-server/livedata_server.js:709:40
        @ [object Object]._.extend.withValue (packages/meteor.js:1100:17)
        @ packages/ddp-server/livedata_server.js:707:46
        @ tryCallTwo (/Users/ap/.meteor/packages/promise/.0.6.6.1cqifiz++os+web.browser+web.cordova/npm/node_modules/meteor-promise/node_modules/promise/lib/core.js:45:5)
        @ doResolve (/Users/ap/.meteor/packages/promise/.0.6.6.1cqifiz++os+web.browser+web.cordova/npm/node_modules/meteor-promise/node_modules/promise/lib/core.js:200:13)

So I think there is something meteor serviceConfigurations related missing... :(

gerwinbrunner commented 8 years ago

@Sanjo any ideas on how to solve this?

ghost commented 8 years ago

Post the server.execute code block please.

gerwinbrunner commented 8 years ago

this is the server block:

    server.execute(function () {
      Package['xolvio:cleaner'].resetDatabase();
      configureServices();
    });
ghost commented 8 years ago

Do you have any idea, in which code the _serviceConfigurations reference is that is mentioned in the error?

gerwinbrunner commented 8 years ago

Oh that's interesting. The variable exists only in the generated source code:

var require = meteorInstall({"imports":{"infrastructure":{"server":{"serviceConfigurations.js":function(require,exports){

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                     //
// imports/infrastructure/server/serviceConfigurations.js                                              //
//                                                                                                     //
/////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                       //
exports.__esModule = true;                                                                             //
exports.configureServices = configureServices;                                                         //
function configureServices() {                                                                         // 1
                                                                                                       //
  console.log("ServiceConfiguration loading");                                                         // 3
                                                                                                       //
  ServiceConfiguration.configurations.remove({                                                         // 5
    service: 'facebook'                                                                                // 6
  });                                                                                                  //
                                                                                                       //
  ServiceConfiguration.configurations.insert({                                                         // 9
    service: 'facebook',                                                                               // 10
    appId: 'xxxx',                                                                         // 11
    secret: 'xxxx'                                                         // 12
  });                                                                                                  //
}                                                                                                      //
/////////////////////////////////////////////////////////////////////////////////////////////////////////

}}}},"entry":{"server":{"module-loader.js":function(require){

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

},"main.js":["../../imports/infrastructure/server/serviceConfigurations",function(require){

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                     //
// entry/server/main.js                                                                                //
//                                                                                                     //
/////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                       //
var _serviceConfigurations = require('../../imports/infrastructure/server/serviceConfigurations');     // 7
                                                                                                       //
(0, _serviceConfigurations.configureServices)(); // import '../../imports/infrastructure/collections';
// import '../../imports/infrastructure/server/publications';                                          //
// import '../../imports/application/services/bank-service/server/bank-service-api';                   //
                                                                                                       //
//import '../../imports/infrastructure/server/serviceConfigurations';                                  //
/////////////////////////////////////////////////////////////////////////////////////////////////////////

}]}}},{"extensions":[".js",".json",".jsx"]});
require("./entry/server/module-loader.js");
require("./entry/server/main.js");
//# sourceMappingURL=app.js.map

Here is how the original main.js looks like:

// import '../../imports/infrastructure/collections';
// import '../../imports/infrastructure/server/publications';
// import '../../imports/application/services/bank-service/server/bank-service-api';

//import '../../imports/infrastructure/server/serviceConfigurations';

import { configureServices } from '../../imports/infrastructure/server/serviceConfigurations';

configureServices();
ghost commented 8 years ago

Try this:

server.execute(function () {
  Package['xolvio:cleaner'].resetDatabase();
  const { configureServices } = require('/imports/infrastructure/server/serviceConfigurations');
  configureServices();
});

In server.execute you always need to use require instead of import. And you need to specify an absolute path. The root of the path is your app root. Like in the code above.

gerwinbrunner commented 8 years ago

hmmm... did it. Now I get this error:

      Error: Error in server.executeReferenceError: require is not defined
      ReferenceError: require is not defined
        @ evalmachine.<anonymous>:5:22
        @ [object Object].xolvioBackdoor (packages/xolvio:backdoor/server.js:10:54)
        @ maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1704:12)
        @ packages/ddp-server/livedata_server.js:711:19
        @ [object Object]._.extend.withValue (packages/meteor.js:1100:17)
        @ packages/ddp-server/livedata_server.js:709:40
        @ [object Object]._.extend.withValue (packages/meteor.js:1100:17)
        @ packages/ddp-server/livedata_server.js:707:46
        @ tryCallTwo (/Users/ap/.meteor/packages/promise/.0.6.6.1cqifiz++os+web.browser+web.cordova/npm/node_modules/meteor-promise/node_modules/promise/lib/core.js:45:5)
gerwinbrunner commented 8 years ago

that's the file:

fixtures.common = {
  reset: function () {
    // make sure the DDP connection is not logged in before clearing the database
    server.call('logout');
    server.execute(function () {
      Package['xolvio:cleaner'].resetDatabase({});
      const { configureServices } = require('/imports/infrastructure/server/serviceConfigurations');
    });
  }
};
ghost commented 8 years ago

Install xolvio:backdoor@0.2.0

Gerwin Brunner notifications@github.com schrieb am Do., 21. Apr. 2016, 20:24:

that's the file:

fixtures.common = { reset: function () { // make sure the DDP connection is not logged in before clearing the database server.call('logout'); server.execute(function () { Package['xolvio:cleaner'].resetDatabase({}); //Package['xolvio:cleaner'].resetDatabase({excludedCollections: ['meteor_accounts_loginServiceConfiguration']}); //const { configureServices } = require('/imports/infrastructure/server/serviceConfigurations'); const { configureServices } = require('/imports/infrastructure/server/serviceConfigurations'); }); } };

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/xolvio/automated-testing-best-practices/issues/37#issuecomment-213227664

gerwinbrunner commented 8 years ago

that did the trick! Thanks!