0

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?

closed as off-topic by Rosco Kalis, Ismael, Crissi Mariam Robert, flygoing, Nicolas Massart Mar 6 at 13:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Ethereum, the decentralized application platform and smart contract enabled blockchain, within the scope defined in the help center." – Rosco Kalis, Ismael, Crissi Mariam Robert, flygoing
If this question can be reworded to fit the rules in the help center, please edit the question.

2

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;

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