maty21 / mocha-sidebar

Mocha side bar viewer that allows you to run Mocha tests from side bar menu and view results can run each level hierarchy from all tests to a single test(and each describer of course)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It doesn't run my setup/global file as mocha does

orekav opened this issue · comments

When I run "npm test" --> mocha './test/**/*.spec.js', it runs perfectly.
But when I run it with mocha sidebar it doesn't pay attention to my "setup.spec.js"

To avoid this behavior with mocha-sidebar I have to add at the beginning of each test file this: require("../setup.spec");

//  setup.spec.js
const chaiAsPromised = require("chai-as-promised");
const chai = require("chai");

chai.use(chaiAsPromised);
chai.should();

const sequelize = require("../src/models/index");

before(async () => {
	await sequelize.sync({ force: true });
});

after(async () => {
	await sequelize.close();
});

I have this error:
TypeError: Cannot read property 'eventually' of undefined

If I add that file as required I have the message: "before is not defined"


{
	"folders": [
		{
			"path": "."
		}
	],
	"settings": {
		"mocha.env": {
			"NODE_ENV": "test",
			"DATABASE_URL": "mariadb://root:mypass@172.17.0.2:3306/node_test_travis",
			"DATABASE_USE_SSL": "false"
		},
		"mocha.files.glob": "./test/**/*.spec.js",
		"mocha.parallelTests": 1,
		// "mocha.coverage": null
		"mocha.requires": ["chai-as-promised", "chai", "mocha", "./test/setup.spec.js"],
		"mocha.runTestsOnSave": "true",
		"mocha.options": {
			
		}
	}
}

Does anyone know how can I run setup.spec.js before everything?
require("./setup.spec"); in each test file is not an option.

I have the same issue, need some help

I will start the migration to jest because also with Sinon + Decache I am facing issues with my app.js file when I tried to mock a Middleware (Google Captcha). It works perfectly, except for the Sequelize connection that remains OPEN because of the "decache". That provokes the test run never quits.

Tried for a bit to figure this out; --require is loaded before mocha is initialized so if you have a global hook in there it will run but won't work. I ended up just doing a replace-all for import 'mocha'; -> import 'mocha';\nimport 'tests/globals'; and that worked pretty well.