[SOLVED] Using third-party libraries in cucumber tests


#1

Hi, new meteor user here.

I’m trying to use moment.js in my cucumber step definitions in order to format some dates. I have added momentjs:moment to my meteor app, and it works fine in the client code. But when I try to utilize it in my cucumber step definitons I get

ReferenceError: moment is not defined

What do I need to do in order to be able to utilize moment.js in my tests?


#2

The scope of cucumber steps is separate from the scope of Meteor code, so you can’t use Meteor packages in your step definitions. You can however use standard NPM packages by including a package.json inside your tests/cucumber directory and they will be available to you using require('moment') in your feature files.

You can also create a file inside your step definition files that attaches moment to the global space like this:

// /tests/cucumber/features/support/globals.js

global.moment = require('moment');

then you can just use moment in your steps


#3

Thanks for the incredibly swift reply, it works perfectly.