0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-08 21:18:40 +00:00
phpv8/tests/commonjs_modules.phpt

39 lines
750 B
Plaintext
Raw Normal View History

2013-05-09 22:14:02 +00:00
--TEST--
Test V8Js::setModuleLoader : CommonJS modules
--SKIPIF--
<?php
if(!function_exists('json_encode')) {
die('SKIP');
}
require_once(dirname(__FILE__) . '/skipif.inc');
?>
2013-05-09 22:14:02 +00:00
--FILE--
<?php
$JS = <<< EOT
require("path/to/module1");
EOT;
$v8 = new V8Js();
$v8->setModuleLoader(function($module) {
switch ($module) {
case 'path/to/module1':
return 'print(' . json_encode($module . PHP_EOL) . ');require("./module2");';
case 'path/to/module2':
return 'print(' . json_encode($module . PHP_EOL) . ');require("../../module3");';
default:
return 'print(' . json_encode($module . PHP_EOL) . ');';
}
});
$v8->executeString($JS, 'module.js');
?>
===EOF===
--EXPECT--
path/to/module1
path/to/module2
module3
===EOF===