I realized that this is allowed using require.extensions (in node it is deprecated , but should never go away) in order to force import of these asset types in order to result in no-op. Running mocha with the --require flag allows us to customize the runtime for our tests, starting with moka as follows:
NODE_PATH=./app mocha -w --compilers js:babel-core/register --require ./app/lib/testHelper.js --require ./app/lib/testNullCompiler.js 'app/**/* .spec.@ (js|jsx)' --watch-extensions js,jsx
where testNullCompiler.js :
const noop = () => 1; require.extensions['.css'] = noop; require.extensions['.scss'] = noop; require.extensions['.png'] = noop; require.extensions['.jpg'] = noop; require.extensions['.jpeg'] = noop; require.extensions['.gif'] = noop; require.extensions['.svg'] = noop;
This will cause all the above file types to return the noop function instead of trying to load the actual file.
My code uses es6 import syntax, but I assume that babel convert it to require under covers, which allows you to use this technique.
pherris
source share