Comments (13)
Just a note, this works fine in node as is and works fine in karma when i swap proxyquire-wrapper for proxyquerify manually. i just really need this library to be tested on both. thanks!
from karma-browserify.
So aliases aren't a real browserify feature. grunt-browserify chose to implement that for some reason and here's how:
https://github.com/jmreidy/grunt-browserify/blob/master/lib/runner.js#L40-L49
You can try requiring your wrapper and exposing it in prebundle
. I think that'll work.
from karma-browserify.
thanks for the quick reply! thats really good to know.
if you have the time it would help me out a lot if you could give an example of how to do something similar to this with prebundle?
thanks again!
from karma-browserify.
browserify: {
basedir: './spec',
prebundle: function (bundle) {
bundle.require(
'proxyquireify',
{ expose: './proxyquire-wrapper' }
);
},
debug: true,
plugin: ['proxyquireify/plugin'],
}
this seems to get proxyqueryify inside the project but now i am getting module not found on all my relative paths.
Error: Cannot find module '../src/pantry'
at newRequire (/var/folders/j8/_z4qvh9j72d60z435jh6bmfh0000gn/T/1ec01b14c2f311b868220a443664d0d98b4fa64b.browserify:52:27 <- /Volumes/Home/admin/Documents/software-coop/pantry/node_modules/proxyquireify/lib/prelude.js:52:0)
at req (/var/folders/j8/_z4qvh9j72d60z435jh6bmfh0000gn/T/1ec01b14c2f311b868220a443664d0d98b4fa64b.browserify:61:24 <- /Volumes/Home/admin/Documents/software-coop/pantry/node_modules/proxyquireify/lib/prelude.js:61:0)
at original (/var/folders/j8/_z4qvh9j72d60z435jh6bmfh0000gn/T/1ec01b14c2f311b868220a443664d0d98b4fa64b.browserify:9358:12 <- /Volumes/Home/admin/Documents/software-coop/pantry/node_modules/proxyquireify/index.js:83:0)
at Function.proxyquire._proxy (/var/folders/j8/_z4qvh9j72d60z435jh6bmfh0000gn/T/1ec01b14c2f311b868220a443664d0d98b4fa64b.browserify:9365:21 <- /Volumes/Home/admin/Documents/software-coop/pantry/node_modules/proxyquireify/index.js:90:0)
at moduleRequire (/var/folders/j8/_z4qvh9j72d60z435jh6bmfh0000gn/T/1ec01b14c2f311b868220a443664d0d98b4fa64b.browserify:69:42 <- /Volumes/Home/admin/Documents/software-coop/pantry/node_modules/proxyquireify/lib/prelude.js:69:0)
at /var/folders/j8/_z4qvh9j72d60z435jh6bmfh0000gn/T/1ec01b14c2f311b868220a443664d0d98b4fa64b.browserify:9346:15 <- /Volumes/Home/admin/Documents/software-coop/pantry/node_modules/proxyquireify/index.js:71:0
at Suite.<anonymous> (/var/folders/j8/_z4qvh9j72d60z435jh6bmfh0000gn/T/1ec01b14c2f311b868220a443664d0d98b4fa64b.browserify:10190:18 <- /Volumes/Home/admin/Documents/software-coop/pantry/spec/pantry-spec.js:20:0)
at jasmineInterface.describe (/Volumes/Home/admin/Documents/software-coop/pantry/node_modules/karma-jasmine/lib/boot.js:50:18)
at Object./Volumes/Home/admin/Documents/software-coop/pantry/spec/pantry-spec.js../proxyquire-wrapper (/var/folders/j8/_z4qvh9j72d60z435jh6bmfh0000gn/T/1ec01b14c2f311b868220a443664d0d98b4fa64b.browserify:10173:1 <- /Volumes/Home/admin/Documents/software-coop/pantry/spec/pantry-spec.js:3:0)
from karma-browserify.
You have the right idea but got things backwards. You want to bundle.require
your wrapper and expose it as 'proxyquireify
.
from karma-browserify.
i am quite confused. isn't what you are suggesting seems the same as requiring proxyquireify?
i want to swap out my wrapper for proxyquireify when it is browserified. i want to keep my wrapper when i am using it in node.
all the wrapper does is makes proxyquire behave more like proxyquireify.
var proxyquire = require('./proxyquire-wrapper')(require); // works in node
var proxyquire = require('proxyquireify')(require); // works in browser
from karma-browserify.
Ah okay, wasn't sure what you meant by:
swap it out for proxyquireify
The example helps. Has this ever worked in another tool?
from karma-browserify.
No it hasn't. It feels like this should work somehow though? The tests work absolutely fine both in the browser and in node when they have the right module loaded. I'd like this library to have one set of tests that works both in the browser and in node and karma-bro seems like the best tool to do this.
from karma-browserify.
Got it. I think the easiest way to demonstrate the right approach here would just be for me to write up a little module to do this. Shouldn't take long and I should have time to knock this out after lunch.
from karma-browserify.
Thank you so much that sounds perfect!
from karma-browserify.
Give this a shot:
https://github.com/bendrucker/proxyquire-universal
from karma-browserify.
omg this works gorgeously with karma-bro.
here is my karma configuration after installing proxyquire-universal
karma: {
jasmine: {
frameworks: ['browserify', 'jasmine'],
singleRun: true,
port: 9876,
runnerPort: 9100,
autoWatch: false,
captureTimeout: 60000,
exclude: ['**/*.md'],
reporters: ['story'],
browsers: ['Chrome'],
client: {
captureConsole: true
},
preprocessors: {
'./spec/*': ['browserify']
},
browserify: {
debug: true,
plugin: ['proxyquire-universal'],
},
configFile: './jasmine.karma.conf.js'
}
}
tests are working in the browser and in node.
this is perfect. thank you so much!
from karma-browserify.
Quite welcome! Just so you know, the plugin works by first transforming the code to replace require('proxyquire')
with require('proxyquire')(require)
(1) and then registers the proxyquireify plugin itself(2):
- https://github.com/bendrucker/proxyquire-universal/blob/master/src/transform.js#L12
- https://github.com/bendrucker/proxyquire-universal/blob/master/src/index.js#L6
from karma-browserify.
Related Issues (20)
- intellij karma runner doesn't use watchify for bundle rebuild HOT 3
- Cannot read property 'bundleFile' of undefined HOT 2
- Error: Cannot find module HOT 2
- Use global transforms HOT 4
- ERROR [framework.browserify]: Error: Cannot find module HOT 2
- attempting to use node-underscorify with karma-browserify fails HOT 2
- Missing repo nikku/node-browserify breaks older versions (<4.0) HOT 1
- Karma not working with Firefox(FirefoxHeadless) when loading with html page. HOT 1
- Unable to browserify file HOT 1
- Install issues due to browserify peerDependecy condition HOT 1
- karma-browserify HOT 1
- lodash vulnerability reported by "npm audit" HOT 1
- When packaged, my test coverage is always 100% HOT 4
- release with PhantomJS removed? HOT 1
- promisify is not a function HOT 2
- Using karma-browserify with WASM HOT 2
- Cannot use import statement outside a module only on karma-browserify HOT 3
- Support for Browserify v17 HOT 2
- Breaking change coming for karma-browserify/lib/preprocessor.js HOT 4
- Support watchify <= 4 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from karma-browserify.