0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-23 00:51:51 +00:00
phpv8/tests/commonjs_node_compat_basic.phpt

42 lines
798 B
Plaintext
Raw Normal View History

--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===