Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Setting up #83

Open
elijahmg opened this issue Oct 2, 2019 · 2 comments
Open

Setting up #83

elijahmg opened this issue Oct 2, 2019 · 2 comments

Comments

@elijahmg
Copy link

elijahmg commented Oct 2, 2019

Hey guys,

II'm trying to configure webpack using mocha tests for nodejs project with mocha loader, but can not understand manual that you have here,
Can somebody describe step by step how to configure it

Thx

@jasonswearingen
Copy link

Very surprising no docs have been added / issue responded...... and yet this module still works!

I found this SO answer that describes what to do: https://stackoverflow.com/questions/32385219/mocha-tests-dont-run-with-webpack-and-mocha-loader

@jasonswearingen
Copy link

jasonswearingen commented Sep 24, 2020

actually, I'm wrong. This module does not work. it is broken

Specifically, this code seems to be for an old version of mocha, because it breaks everything: https://github.com/webpack-contrib/mocha-loader/blob/master/src/start.js

I actually figured out you don't actually need this mocha loader, at all.

webpack should delete this loader and just paste a snippet for getting mocha working

here is my working code, based on the SO answer I linked above

//test-main.js

//bootstrap mocha, as per: https://mochajs.org/#running-mocha-in-the-browser
require( "mocha" )
mocha.setup( "bdd" )


//load up all test files following general advice from: https://stackoverflow.com/questions/32385219/mocha-tests-dont-run-with-webpack-and-mocha-loader
{
	const foundTestsRequire = require.context( "..", true, /.*\.test\.js?$/ )
	//console.log( `keys found = ${ foundTestsRequire.keys().length }` )
	for ( const key of foundTestsRequire.keys() ) {
		console.log( key )
		foundTestsRequire( key )
	}
}

//run tests
mocha.run()

If you want a fully functional solution, look at this commit into my isomorphic xlib library: Novaleaf/xlib@c47696d

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants