-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
72 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# EnzymeAdapterPlugin | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* global ENZYME_MODULE_REQUEST, ENZYME_ADAPTER_REQUEST */ | ||
/* eslint no-var: off */ | ||
/* | ||
* enzyme-proxy.js | ||
* | ||
* A proxy module to automatically initialize the Enzyme Adapter whenever Enzyme is | ||
* required/imported. | ||
*/ | ||
|
||
var enzyme = require(ENZYME_MODULE_REQUEST); | ||
var Adapter = require(ENZYME_ADAPTER_REQUEST); | ||
|
||
enzyme.configure({adapter: new Adapter()}); | ||
|
||
module.exports = enzyme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const {DefinePlugin} = require('webpack'); | ||
|
||
function EnzymeAdapterPlugin(options) { | ||
this.options = options || {}; | ||
this.options.enzyme = this.options.enzyme || 'enzyme'; | ||
this.options.adapter = this.options.adapter || 'enzyme-adapter-react-16'; | ||
} | ||
|
||
EnzymeAdapterPlugin.prototype.apply = function(compiler) { | ||
const opts = this.options; | ||
const proxyJS = require.resolve('./enzyme-proxy'); | ||
|
||
// Inject enzyme and adapter module filepath constants | ||
compiler.apply(new DefinePlugin({ | ||
ENZYME_MODULE_REQUEST: JSON.stringify(opts.enzyme), | ||
ENZYME_ADAPTER_REQUEST: JSON.stringify(opts.adapter) | ||
})); | ||
|
||
// Redirect external 'enzyme' import/require statements to the enzyme proxy | ||
compiler.plugin('normal-module-factory', (factory) => { | ||
factory.plugin('before-resolve', (result, callback) => { | ||
if(!result) return callback(); | ||
if(result.request === 'enzyme' && result.contextInfo.issuer !== proxyJS | ||
&& !result.contextInfo.issuer.includes('enzyme')) { | ||
result.request = proxyJS; | ||
} | ||
return callback(null, result); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = EnzymeAdapterPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters