def test_webpack_core_compiled(self): remember_cwd(self) chdir(self._env_root) build_dir = mkdtemp(self) src_template = resource_filename( Requirement.parse('nunja'), join('nunja', '_core_', '_default_wrapper_', 'template.nja')) spec = Spec( build_dir=build_dir, loaderplugin_sourcepath={ 'fake!bad': '/some/broken/path', 'text!_core_/_default_wrapper_/template.nja': src_template, 'text!some/template.nja': src_template, 'text!some/other/data.json': src_template, }, bundle_sourcepath={ 'nunjucks': join('node_modules', 'nunjucks', 'nunjucks.js'), }, ) webpack(spec, ()) hex_name = to_hex('_core_/_default_wrapper_') precompiled_path = join(build_dir, hex_name + '.js') self.assertFalse(exists(precompiled_path)) self.assertNotIn('slim', spec['bundle_sourcepath']['nunjucks']) # now trigger the advice spec.handle(BEFORE_COMPILE) self.assertTrue(exists(precompiled_path)) with open(precompiled_path) as fd: precompiled = fd.read() core_path = resource_filename(Requirement.parse('nunja'), join('nunja', '__core__.js')) with open(core_path) as fd: core_compiled = fd.read() # the compiled template should be identical with the one that # is stored in this source tree for the core self.assertEqual(precompiled, core_compiled) self.assertEqual( spec['bundle_sourcepath']['__nunja__/_core_/_default_wrapper_'], precompiled_path, ) # this one untouched. self.assertEqual( spec['loaderplugin_sourcepath'], { 'fake!bad': '/some/broken/path', 'text!_core_/_default_wrapper_/template.nja': src_template, # all other ones that did not pass the test will be filtered # out for other processing 'text!some/template.nja': src_template, 'text!some/other/data.json': src_template, })
def test_rjs_core_compiled_slim(self): remember_cwd(self) chdir(self._env_root) src_template = resource_filename( Requirement.parse('nunja'), join('nunja', '_core_', '_default_wrapper_', 'template.nja')) build_dir = mkdtemp(self) spec = Spec( build_dir=build_dir, plugin_sourcepath={ 'text!_core_/_default_wrapper_/template.nja': src_template, }, bundle_sourcepath={ 'nunjucks': join('node_modules', 'nunjucks', 'nunjucks.js'), }, ) rjs(spec, ('slim', )) hex_name = to_hex('_core_/_default_wrapper_') precompiled_path = join(build_dir, hex_name + '.js') spec.handle(BEFORE_COMPILE) self.assertIn('slim', spec['bundle_sourcepath']['nunjucks']) self.assertTrue(exists(precompiled_path)) self.assertEqual( { '__nunja__/_core_/_default_wrapper_': { 'exports': 'nunjucksPrecompiled' }, }, spec['shim'])
def test_to_hex(self): self.assertEqual(to_hex(u'a'), u'61') self.assertEqual(to_hex(u'\u306a'), u'e381aa')