Skip to content

Instantly share code, notes, and snippets.

@daveneeley
Last active May 5, 2020 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveneeley/89cc99d4741d880b988688664408eeae to your computer and use it in GitHub Desktop.
Save daveneeley/89cc99d4741d880b988688664408eeae to your computer and use it in GitHub Desktop.
Babel typeof recursion error with require and export
// babel.config.js
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
};
/* global require */
/* instanbul ignore next */
if (typeof(require) !== undefined) {
var Chat = require('./Help.js')['default'];
}
var Bot = {
onMessage: function(event) {
return "someaction"
}
};
/* global exports */
/* istanbul ignore next */
if (typeof(exports) !== 'undefined') {
exports['__esModule'] = true;
exports['default'] = Bot;
}
import Bot from './Bot.js';
var tests = [
['', 'someaction'],
['Hi!', 'someaction']
];
test.each(tests)('onMessage %s: %s', (message, expected) => {
expect(Bot.onMessage(message)).toBe(expected);
});
var Help = {
help: function() {
return { text: 'You can say `help`' };
}
};
/* global exports */
/* istanbul ignore next */
if (typeof(exports) !== 'undefined') {
exports['__esModule'] = true;
exports['default'] = Help;
}
import Help from './Help.js';
test('help', () => {
var message = Help.help();
expect(message.text).toBeDefined();
});
{
"scripts": {
"test": "jest",
"coverage": "jest --coverage"
},
"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"babel-jest": "^26.0.0",
"jest": "^26.0.0"
},
"jest": {
"collectCoverageFrom": [
"src/*.js"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment