0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-08 12:38:41 +00:00
phpv8/tests/commonjs_node_compat_basic.phpt
2017-11-12 16:20:24 +01:00

42 lines
798 B
PHP

--TEST--
Test V8Js::setModuleLoader : exports/module.exports behaviour
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$v8 = new V8Js();
$v8->setModuleLoader(function ($moduleName) {
return <<<'EOJS'
var_dump(typeof exports);
var_dump(typeof module.exports);
// for compatibility both should be linked
var_dump(exports === module.exports);
exports = { number: 23 };
module.exports = { number: 42 };
EOJS
;
});
$v8->executeString(<<<'EOJS'
var result = require('foo');
// expect module.exports value to be picked up
var_dump(typeof result);
var_dump(result.number);
EOJS
);
?>
===EOF===
--EXPECT--
string(6) "object"
string(6) "object"
bool(true)
string(6) "object"
int(42)
===EOF===