Giter VIP home page Giter VIP logo

Comments (13)

beckyconning avatar beckyconning commented on June 12, 2024

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.

bendrucker avatar bendrucker commented on June 12, 2024

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.

beckyconning avatar beckyconning commented on June 12, 2024

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.

beckyconning avatar beckyconning commented on June 12, 2024
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.

bendrucker avatar bendrucker commented on June 12, 2024

You have the right idea but got things backwards. You want to bundle.require your wrapper and expose it as 'proxyquireify.

from karma-browserify.

beckyconning avatar beckyconning commented on June 12, 2024

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.

bendrucker avatar bendrucker commented on June 12, 2024

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.

beckyconning avatar beckyconning commented on June 12, 2024

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.

bendrucker avatar bendrucker commented on June 12, 2024

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.

beckyconning avatar beckyconning commented on June 12, 2024

Thank you so much that sounds perfect!

from karma-browserify.

bendrucker avatar bendrucker commented on June 12, 2024

Give this a shot:

https://github.com/bendrucker/proxyquire-universal

from karma-browserify.

beckyconning avatar beckyconning commented on June 12, 2024

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.

bendrucker avatar bendrucker commented on June 12, 2024

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):

  1. https://github.com/bendrucker/proxyquire-universal/blob/master/src/transform.js#L12
  2. https://github.com/bendrucker/proxyquire-universal/blob/master/src/index.js#L6

from karma-browserify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.