Instantly share code, notes, and snippets.

Embed
What would you like to do?
A wallaby configuration for Meteor apps
// Use old-school javascript in this file to make it work nicely
// Or use a newer node version with nvm
function setupWallaby(wallaby) {
return {
name,
// debug: true, // Use this if things go wrong
testFramework: 'mocha',
files: [
// load all files in imports
'imports/**/**.js*',
// Don't import unnecessary folders
'!imports/assets/**',
// Don't load tests here, but in the next variable
'!imports/**/*.spec.js*',
// Load language files for some tests
'lang/*.json',
],
tests: ['imports/**/*.spec.js*'],
compilers: {
// Careful, don't lazily compile all .js* files, but only .js and .jsx.
// Otherwise wallaby will try to compile .json files as well.
'**/*.js?(x)': wallaby.compilers.babel({
// Add any other custom presets here, like '@babel/preset-flow'
presets: ['meteor', '@babel/preset-react'],
// Add any other custom plugins here, like '@babel/plugin-proposal-class-properties'
plugins: [
'@babel/plugin-transform-modules-commonjs',
'meteor-babel/plugins/dynamic-import',
[
'module-resolver',
{
root: ['.'],
alias: {
// Optional: if necessary
// Use an alias for a symlinked "shared" directory shared between multiple meteor apps
core: './imports/shared',
// Mock meteor packages with this, you have to add a bunch of files in
// meteorStubs/ that correspond to the package names, such as
// meteor.js, check.js, cultofcoders:grapher.js, etc.
// Careful, ":" can't be used in file names on Windows, no solution at the moment
// You could try to map the package name to another with an underscore/hyphen for example..
meteor: './imports/utils/testHelpers/meteorStubs',
},
},
],
],
}),
},
env: { type: 'node' },
setup() {
// Helpful global variable if necessary
global.IS_WALLABY = true;
// Make fetch work
global.fetch = require('node-fetch');
// Do this to prevent some weird issues
global.window = { navigator: { userAgent: 'node.js' } };
// Activate JSDOM if you want to run tests that require a document, such as UI tests
// Configure jsdom for react mount tests
// const jsdom = require('jsdom');
// const { JSDOM } = jsdom;
// const { document } = new JSDOM('<!doctype html><html><body></body></html>').window;
// global.document = document;
// global.window = document.defaultView;
// global.navigator = {
// userAgent: 'node.js',
// platform: 'Win32',
// };
},
};
}
module.exports = setupWallaby;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment