I have files in Test directory, each one performs different test but all of them contain at least exactly the same functions "register" and "vote", also few arrays like votings = [], groups = [] and variables. I would like to organize it and somehow build a "prototype" with basic stuff with these variables, arrays and functions, and include them to each Test file.

Is this possible?

| improve this question | | | | |

That's a Node question, not a Truffle question, but you can do this in two steps:

Step 1 - create file common.js and initialize your common stuff in it, for example:

module.exports.myVal  = 42;
module.exports.myFunc = function(x) {return x;};

Step 2 - import and use this file in your Truffle tests, for example:

const common = require("./common.js");
const myVal  = common.myVal;
const myFunc = common.myFunc;
| improve this answer | | | | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.