def testScriptOrderingWithIncludeTag(self):
     with self.fs:
         load_sequence = self.project.CalcLoadSequenceForModuleNames(
             [os.path.normpath('foo.inline_and_external_module')])
         result = generate.GenerateJS(load_sequence,
                                      use_include_tags_for_scripts=True,
                                      dir_for_include_tag_root='/x/')
         script1_pos = result.index('Script1()')
         script2_pos = result.index('Script2()')
         external_path = os.path.join('foo', 'external_script.js')
         external_pos = result.index(
             '<include src="{0}">'.format(external_path))
         self.assertTrue(script1_pos < external_pos < script2_pos)
Exemple #2
0
    def testBasicModuleGeneration(self):
        file_contents = {}
        file_contents[os.path.normpath('/tmp/a/b/start.html')] = """
<!DOCTYPE html>
<link rel="import" href="/widget.html">
<link rel="stylesheet" href="../common.css">
<script src="/raw_script.js"></script>
<script src="/excluded_script.js"></script>
<dom-module id="start">
  <template>
  </template>
  <script>
    'use strict';
    console.log('inline script for start.html got written');
  </script>
</dom-module>
"""
        file_contents[os.path.normpath(
            '/py_vulcanize/py_vulcanize.html')] = """<!DOCTYPE html>
"""
        file_contents[os.path.normpath('/components/widget.html')] = """
<!DOCTYPE html>
<link rel="import" href="/py_vulcanize.html">
<widget name="widget.html"></widget>
<script>
'use strict';
console.log('inline script for widget.html');
</script>
"""
        file_contents[os.path.normpath('/tmp/a/common.css')] = """
/* /tmp/a/common.css was written */
"""
        file_contents[os.path.normpath('/raw/raw_script.js')] = """
console.log('/raw/raw_script.js was written');
"""
        file_contents[os.path.normpath(
            '/raw/components/polymer/polymer.min.js')] = """
"""

        with fake_fs.FakeFS(file_contents):
            project = project_module.Project([
                os.path.normpath('/py_vulcanize/'),
                os.path.normpath('/tmp/'),
                os.path.normpath('/components/'),
                os.path.normpath('/raw/')
            ])
            loader = resource_loader.ResourceLoader(project)
            a_b_start_module = loader.LoadModule(
                module_name='a.b.start',
                excluded_scripts=['\/excluded_script.js'])
            load_sequence = project.CalcLoadSequenceForModules(
                [a_b_start_module])

            # Check load sequence names.
            load_sequence_names = [x.name for x in load_sequence]
            self.assertEquals(['py_vulcanize', 'widget', 'a.b.start'],
                              load_sequence_names)

            # Check module_deps on a_b_start_module
            def HasDependentModule(module, name):
                return [x for x in module.dependent_modules if x.name == name]

            assert HasDependentModule(a_b_start_module, 'widget')

            # Check JS generation.
            js = generate.GenerateJS(load_sequence)
            assert 'inline script for start.html' in js
            assert 'inline script for widget.html' in js
            assert '/raw/raw_script.js' in js
            assert 'excluded_script.js' not in js

            # Check HTML generation.
            html = generate.GenerateStandaloneHTMLAsString(
                load_sequence, title='', flattened_js_url='/blah.js')
            assert '<dom-module id="start">' in html
            assert 'inline script for widget.html' not in html
            assert 'common.css' in html
 def testJSGeneration(self):
     with self.fs:
         load_sequence = self.project.CalcLoadSequenceForModuleNames(
             [os.path.normpath('foo.my_module')])
         generate.GenerateJS(load_sequence)