Beispiel #1
0
    def test_react_works(self):
        ctx = dukpy.RequirableContext([self.node_packages])
        ret = ctx.evaljs("""
var React = require('react'),
    ReactDOM = require('react-dom/server');

var HelloWorld = React.createClass({
  render: function() {
    return React.createElement('p', null, 'Hi!');
  }
});

({
  React: React,
  ReactDOM: ReactDOM,
  HelloWorld: HelloWorld
})
""")

        React = ret.React
        ReactDOM = ret.ReactDOM
        HelloWorld = ret.HelloWorld

        markup = ReactDOM.renderToStaticMarkup(React.createElement(HelloWorld, None, ''))
        assert markup == "<p>Hi!</p>"
Beispiel #2
0
 def test_python_require(self):
     import sys, imp
     testpy = imp.new_module('testpy')
     testpy.call = lambda: 'Hello from Python!'
     testpy.__all__ = ['call']
     sys.modules['testpy'] = testpy
     c = dukpy.RequirableContext([], enable_python=True)
     assert c.evaljs("require('python/testpy').call()") == "Hello from Python!"
Beispiel #3
0
 def test_python_require_doesnt_work_by_default(self):
     import sys, imp
     testpy = imp.new_module('testpy')
     testpy.call = lambda: 'Hello from Python!'
     testpy.__all__ = ['call']
     sys.modules['testpy'] = testpy
     c = dukpy.RequirableContext([])
     try:
         c.evaljs("require('python/testpy').call()")
         assert False
     except ImportError:
         pass
Beispiel #4
0
def load_dukpy_ctx():
    result = os.path.join(basepath, 'node_modules')
    if not os.path.exists(result):
        raise ValueError("Unable to locate node_modules directory - is Ore installed correctly?")

    ctx = dukpy.RequirableContext([result])

    def resolve_wrap(resolve):
        def inner(req_ctx, id_, search_paths):
            # bodge to work around the fact
            # that the browser version of util
            # imports inherits, which expects util to provide inherits
            # yaey
            if id_ == '!inherits!':
                id_ = '!inherits/inherits_browser.js!'

            return resolve(req_ctx, id_, search_paths)
        return inner

    ctx.finder.resolve = resolve_wrap(ctx.finder.resolve)

    return ctx
Beispiel #5
0
 def test_js_require(self):
     c = dukpy.RequirableContext([self.test_js_dir])
     assert c.evaljs("require('testjs').call()") == "Hello from JS!"