Commit 70edade4 authored by Robert Knight's avatar Robert Knight

Add mockable-imports Babel plugin as a replacement for proxyquire

This provides an alternative way to mock a module's dependencies that
fixes several issues with proxyquire and proxyquireify [1]. In
particular we have had issues in the past with:

- Third party modules that have global state (eg. angular) causing
  hard-to-debug errors when mocking
- An initial attempt to convert Common JS imports to ES 6 imports ran
  into problems with the transformed code breaking proxyquire

This also provides future-proofing as well in that it enables us to
change the module bundler or test runner without changing how mocking
works. It should also be much more efficient if we make more extensive
use of import mocking as AngularJS is gradually removed from the codebase.

[1] https://github.com/robertknight/babel-plugin-mockable-imports#how-does-this-plugin-differ-from-alternative-approaches
parent c6128ee0
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
"aws-sdk": "^2.345.0", "aws-sdk": "^2.345.0",
"babel-plugin-angularjs-annotate": "^0.10.0", "babel-plugin-angularjs-annotate": "^0.10.0",
"babel-plugin-istanbul": "^5.1.0", "babel-plugin-istanbul": "^5.1.0",
"babel-plugin-mockable-imports": "^1.1.0",
"babel-plugin-transform-async-to-promises": "^0.8.6", "babel-plugin-transform-async-to-promises": "^0.8.6",
"babel-preset-env": "^1.7.0", "babel-preset-env": "^1.7.0",
"babelify": "^10.0.0", "babelify": "^10.0.0",
......
...@@ -86,6 +86,7 @@ module.exports = function(config) { ...@@ -86,6 +86,7 @@ module.exports = function(config) {
// code coverage instrumentation for Istanbul. // code coverage instrumentation for Istanbul.
extensions: ['.js', '.coffee'], extensions: ['.js', '.coffee'],
plugins: [ plugins: [
'mockable-imports',
[ [
'babel-plugin-istanbul', 'babel-plugin-istanbul',
{ {
......
...@@ -1554,6 +1554,11 @@ babel-plugin-istanbul@^5.1.0: ...@@ -1554,6 +1554,11 @@ babel-plugin-istanbul@^5.1.0:
istanbul-lib-instrument "^3.0.0" istanbul-lib-instrument "^3.0.0"
test-exclude "^5.0.0" test-exclude "^5.0.0"
babel-plugin-mockable-imports@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/babel-plugin-mockable-imports/-/babel-plugin-mockable-imports-1.2.0.tgz#151db640cf6339a6a878a3b70e336eec4baa1895"
integrity sha512-KqKIFsPDQcXf2XZZazAxGa7xUgbGueLfCQb4mD7G16lvLYfz13SakC6IAcRaBueXwNn2O0K6VGlXZzPs0aLL3Q==
babel-plugin-syntax-async-functions@^6.8.0: babel-plugin-syntax-async-functions@^6.8.0:
version "6.13.0" version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment