def test_cli_compile_all_service(self): # create a new working directory to install our current site utils.remember_cwd(self) working_dir = utils.mkdtemp(self) os.chdir(working_dir) # Trigger the compile using the module level compile function, # but without bundling spec = cli.compile_all( ['service'], source_registries=(self.registry_name,), bundle_map_method='none', ) self.assertEqual( spec['export_target'], join(working_dir, 'service.js')) # verify that the bundle works with node. First change back to # directory with requirejs library installed. os.chdir(self._env_root) # The execution should then work as expected on the bundle we # have. stdout, stderr = run_node( 'var requirejs = require("requirejs");\n' 'var define = requirejs.define;\n' '%s\n' 'var rpclib = requirejs("service/rpc/lib");\n' 'console.log(rpclib.Library);\n', spec['export_target'], ) self.assertEqual(stderr, '') self.assertEqual(stdout, 'service.rpc.lib.Library\n')
def test_cli_compile_all_service(self): # create a new working directory to install our current site utils.remember_cwd(self) working_dir = utils.mkdtemp(self) os.chdir(working_dir) # Trigger the compile using the module level compile function, # but without bundling spec = cli.compile_all( ['service'], source_registries=(self.registry_name,), bundlepath_method='none', ) self.assertEqual( spec['export_target'], join(working_dir, 'service.js')) # verify that the bundle works with node. First change back to # directory with requirejs library installed. os.chdir(self._env_root) # The execution should then work as expected on the bundle we # have. stdout, stderr = run_node( 'var requirejs = require("requirejs");\n' 'var define = requirejs.define;\n' '%s\n' 'var rpclib = requirejs("service/rpc/lib");\n' 'console.log(rpclib.Library);\n', spec['export_target'], ) self.assertEqual(stderr, '') self.assertEqual(stdout, 'service.rpc.lib.Library\n')
def test_toolchain_transpile_empty(self): # dict works well enough as a null toolchain with pretty_logging(stream=StringIO()) as stream: spec = compile_all([], toolchain=dict, transpile_no_indent=True) self.assertNotIn('packages []', stream.getvalue()) self.assertIn('no packages specified', stream.getvalue()) self.assertTrue(isinstance(spec, Spec)) self.assertTrue(spec['transpile_no_indent'])
def test_toolchain_empty(self): # dict works well enough as a null toolchain with pretty_logging(stream=StringIO()) as stream: spec = compile_all([], toolchain=dict) self.assertNotIn('packages []', stream.getvalue()) self.assertIn('no packages specified', stream.getvalue()) self.assertTrue(isinstance(spec, Spec)) self.assertEqual(spec['export_target'], 'calmjs.rjs.export.js')
def test_toolchain_empty(self): # dict works well enough as a null toolchain with pretty_logging(stream=StringIO()) as stream: spec = compile_all([], toolchain=dict) self.assertNotIn('packages []', stream.getvalue()) self.assertIn('no packages specified', stream.getvalue()) self.assertTrue(isinstance(spec, Spec)) self.assertEqual(spec['export_target'], join( self.cwd, 'calmjs.rjs.export.js'))
def test_cli_compile_explicit_service(self): utils.remember_cwd(self) working_dir = utils.mkdtemp(self) os.chdir(working_dir) # Trigger the compile using the module level compile function, # but without bundling spec = cli.compile_all( ['service'], source_registries=(self.registry_name,), bundlepath_method='none', sourcepath_method='explicit', ) service_js = join(working_dir, 'service.js') self.assertEqual(spec['export_target'], service_js) with open(service_js) as fd: self.assertIn('service/rpc/lib', fd.read()) # build its parent js separately, too spec = cli.compile_all( ['framework'], source_registries=(self.registry_name,), bundlepath_method='none', sourcepath_method='explicit', ) framework_js = join(working_dir, 'framework.js') self.assertEqual(spec['export_target'], framework_js) # verify that the bundle works with node. First change back to # directory with requirejs library installed. os.chdir(self._env_root) # The execution should then work as expected if we loaded both # bundles. stdout, stderr = run_node( 'var requirejs = require("requirejs");\n' 'var define = requirejs.define;\n' '%s\n' 'var rpclib = requirejs("service/rpc/lib");\n' 'console.log(rpclib.Library);\n', framework_js, service_js, ) self.assertEqual(stderr, '') self.assertEqual(stdout, 'service.rpc.lib.Library\n')
def test_cli_compile_explicit_service(self): utils.remember_cwd(self) working_dir = utils.mkdtemp(self) os.chdir(working_dir) # Trigger the compile using the module level compile function, # but without bundling spec = cli.compile_all( ['service'], source_registries=(self.registry_name,), bundle_map_method='none', source_map_method='explicit', ) service_js = join(working_dir, 'service.js') self.assertEqual(spec['export_target'], service_js) with open(service_js) as fd: self.assertIn('service/rpc/lib', fd.read()) # build its parent js separately, too spec = cli.compile_all( ['framework'], source_registries=(self.registry_name,), bundle_map_method='none', source_map_method='explicit', ) framework_js = join(working_dir, 'framework.js') self.assertEqual(spec['export_target'], framework_js) # verify that the bundle works with node. First change back to # directory with requirejs library installed. os.chdir(self._env_root) # The execution should then work as expected if we loaded both # bundles. stdout, stderr = run_node( 'var requirejs = require("requirejs");\n' 'var define = requirejs.define;\n' '%s\n' 'var rpclib = requirejs("service/rpc/lib");\n' 'console.log(rpclib.Library);\n', framework_js, service_js, ) self.assertEqual(stderr, '') self.assertEqual(stdout, 'service.rpc.lib.Library\n')
def test_cli_compile_all_site(self): # create a new working directory to install our current site utils.remember_cwd(self) working_dir = utils.mkdtemp(self) os.chdir(working_dir) # Finally, install dependencies for site in the new directory # normally this might be done # npm = Driver() # npm.npm_install('site', production=True) # However, since we have our set of fake_modules, just install # by copying the fake_modules dir from dist_dir into the current # directory. copytree( join(self.dist_dir, 'fake_modules'), join(working_dir, 'fake_modules'), ) # Trigger the compile using the module level compile function spec = cli.compile_all( ['site'], source_registries=(self.registry_name,)) self.assertEqual( spec['export_target'], join(working_dir, 'site.js')) # verify that the bundle works with node. First change back to # directory with requirejs library installed. os.chdir(self._env_root) # The execution should then work as expected on the bundle we # have. stdout, stderr = run_node( 'var requirejs = require("requirejs");\n' 'var define = requirejs.define;\n' '%s\n' 'var datepicker = requirejs("widget/datepicker");\n' 'console.log(datepicker.DatePickerWidget);\n', spec['export_target'], ) self.assertEqual(stderr, '') self.assertEqual(stdout, 'widget.datepicker.DatePickerWidget\n')