Пример #1
0
 def test_create_spec_with_calmjs_webpack_output_library_warning(self):
     with pretty_logging(stream=StringIO()) as stream:
         create_spec(['calmjs.webpack'], webpack_output_library='entry')
     log = stream.getvalue()
     self.assertIn(
         "webpack_entry_point and/or webpack_output_library is assigned "
         "a different value than their defaults while calmjs_compat is set "
         "to True ", log)
Пример #2
0
    def create_spec(
            self, source_package_names=(), export_target=None,
            working_dir=None,
            build_dir=None,
            calmjs_module_registry_names=None,
            source_registry_method='all',
            sourcepath_method='all', bundlepath_method='all',
            calmjs_compat=True,
            webpack_entry_point=DEFAULT_BOOTSTRAP_EXPORT,
            webpack_optimize_minimize=False,
            verify_imports=True,
            toolchain=None, **kwargs):
        """
        Accept all arguments, but also the explicit set of arguments
        that get passed down onto the toolchain.
        """

        # the spec takes a different set of keys as it will ultimately
        # derive the final values for the standardized spec keys.
        return create_spec(
            package_names=source_package_names,
            export_target=export_target,
            working_dir=working_dir,
            build_dir=build_dir,
            source_registry_method=source_registry_method,
            source_registries=calmjs_module_registry_names,
            sourcepath_method=sourcepath_method,
            bundlepath_method=bundlepath_method,
            calmjs_compat=calmjs_compat,
            webpack_entry_point=webpack_entry_point,
            webpack_optimize_minimize=webpack_optimize_minimize,
            verify_imports=verify_imports,
        )
Пример #3
0
def complete_webpack(package_names, export_target):
    """
    Return the toolchain and a spec that when executed together, will
    result in a complete artifact using the provided package names onto
    the export_target.
    """

    return default_toolchain, create_spec(package_names, export_target)
Пример #4
0
    def test_create_spec_with_calmjs_webpack_manual_working_dir(self):
        working_dir = mkdtemp(self)
        with pretty_logging(stream=StringIO()) as stream:
            spec = create_spec(['calmjs.webpack'], working_dir=working_dir)

        self.assertTrue(isinstance(spec, Spec))
        self.assertEqual(spec['export_target'],
                         join(working_dir, 'calmjs.webpack.js'))
        log = stream.getvalue()
        self.assertIn("'export_target' is now set to", log)
Пример #5
0
def optimize_webpack(package_names, export_target):
    """
    Return the toolchain and a spec that when executed together, will
    result in a complete artifact using the provided package names onto
    the export_target, with the optimize options enabled.
    """

    return default_toolchain, create_spec(
        package_names, export_target,
        webpack_optimize_minimize=True,
    )
Пример #6
0
    def test_create_spec_with_calmjs_webpack_manual_export_target(self):
        with pretty_logging(stream=StringIO()) as stream:
            spec = create_spec(
                ['calmjs.webpack'],
                export_target='somewhere.js',
            )

        self.assertTrue(isinstance(spec, Spec))
        self.assertEqual(spec['export_target'], 'somewhere.js')
        log = stream.getvalue()
        self.assertNotIn("'export_target' autoconfig to", log)
Пример #7
0
    def test_create_spec_with_calmjs_webpack_no_registry(self):
        with pretty_logging(stream=StringIO()) as stream:
            spec = create_spec(['calmjs.webpack'],
                               source_registry_method='none')
        self.assertTrue(isinstance(spec, Spec))
        self.assertEqual(spec['export_target'],
                         join(self.cwd, 'calmjs.webpack.js'))
        self.assertEqual(spec['calmjs_module_registry_names'], [])
        self.assertEqual(spec['source_package_names'], ['calmjs.webpack'])

        log = stream.getvalue()
        self.assertIn(
            "no module registry declarations found using packages "
            "['calmjs.webpack'] using acquisition method 'none'", log)
Пример #8
0
    def test_create_spec_empty_calmjs_compat_disable(self):
        with pretty_logging(stream=StringIO()) as stream:
            spec = create_spec([], calmjs_compat=False)

        self.assertNotIn('packages []', stream.getvalue())
        self.assertIn('no packages specified', stream.getvalue())
        self.assertIn(
            "calmjs_compat is disabled; webpack.output.library automatically "
            "set to 'calmjs.webpack.export', derived from input package names "
            "and export filename as the entry point is defined to be the "
            "simplified calmjs bootstrap.", stream.getvalue())
        self.assertTrue(isinstance(spec, Spec))
        self.assertNotIn('webpack_externals', spec)
        self.assertEqual(spec['webpack_output_library'],
                         'calmjs.webpack.export')
Пример #9
0
    def test_create_spec_empty(self):
        with pretty_logging(stream=StringIO()) as stream:
            spec = create_spec([])

        self.assertNotIn('packages []', stream.getvalue())
        self.assertIn('no packages specified', stream.getvalue())
        self.assertIn(
            "using calmjs bootstrap; webpack.output.library set to "
            "'__calmjs__'", stream.getvalue())
        self.assertTrue(isinstance(spec, Spec))
        self.assertEqual(spec['working_dir'], self.cwd)
        self.assertEqual(spec['export_target'],
                         join(self.cwd, 'calmjs.webpack.export.js'))
        self.assertEqual(spec['calmjs_module_registry_names'], [])
        self.assertIn('webpack_externals', spec)
        self.assertEqual(spec['webpack_output_library'], '__calmjs__')
Пример #10
0
 def test_create_spec_with_calmjs_webpack_output_library_disable(self):
     with pretty_logging(stream=StringIO()) as stream:
         spec = create_spec(
             ['calmjs.webpack'],
             calmjs_compat=False,
             webpack_entry_point='custom_entry',
             webpack_output_library=False,
         )
     log = stream.getvalue()
     self.assertNotIn(
         "webpack_entry_point is ignored; set calmjs_compat to false "
         "to enable manual webpack.entry specification", log)
     self.assertIn("webpack.output.library is disabled; it will be unset.",
                   log)
     self.assertEqual(spec['webpack_entry_point'], 'custom_entry')
     self.assertNotIn('webpack_output_library', spec)
Пример #11
0
    def test_create_spec_with_calmjs_webpack(self):
        with pretty_logging(stream=StringIO()) as stream:
            spec = create_spec(['calmjs.webpack'])
        self.assertTrue(isinstance(spec, Spec))
        self.assertEqual(spec['export_target'],
                         join(self.cwd, 'calmjs.webpack.js'))
        self.assertEqual(spec.get('webpack_entry_point'), '__calmjs__')
        self.assertEqual(spec['calmjs_module_registry_names'],
                         ['calmjs.module'])
        self.assertEqual(spec['source_package_names'], ['calmjs.webpack'])

        log = stream.getvalue()
        self.assertIn(
            "automatically picked registries ['calmjs.module'] for "
            "sourcepaths",
            log,
        )
Пример #12
0
 def test_create_spec_with_calmjs_webpack_entry_point_no_compat(self):
     with pretty_logging(stream=StringIO()) as stream:
         spec = create_spec(
             ['calmjs.webpack'],
             calmjs_compat=False,
             webpack_entry_point='custom_webpack',
         )
     log = stream.getvalue()
     self.assertNotIn(
         "webpack_entry_point is ignored; set calmjs_compat to false "
         "to enable manual webpack.entry specification", log)
     self.assertIn(
         "calmjs_compat is disabled; webpack.output.library automatically "
         "set to 'custom_webpack' as this is the explicit webpack entry "
         "point specified", log)
     self.assertEqual(spec['webpack_entry_point'], 'custom_webpack')
     self.assertEqual(spec.get('webpack_output_library'), 'custom_webpack')
Пример #13
0
    def test_create_spec_with_calmjs_webpack_manual_source(self):
        with pretty_logging(stream=StringIO()) as stream:
            spec = create_spec(['calmjs.webpack'],
                               source_registries=['calmjs.module.tests'])
        self.assertTrue(isinstance(spec, Spec))
        self.assertEqual(spec['export_target'],
                         join(self.cwd, 'calmjs.webpack.js'))
        self.assertEqual(spec['calmjs_module_registry_names'],
                         ['calmjs.module.tests'])
        self.assertEqual(spec['source_package_names'], ['calmjs.webpack'])

        log = stream.getvalue()
        self.assertIn(
            "using manually specified registries ['calmjs.module.tests'] for "
            "sourcepaths",
            log,
        )
Пример #14
0
    def test_create_spec_with_calmjs_webpack_entry_point_only(self):
        with pretty_logging(stream=StringIO()) as stream:
            spec = create_spec(['calmjs.webpack'], webpack_entry_point='entry')
        self.assertTrue(isinstance(spec, Spec))
        self.assertEqual(spec['export_target'],
                         join(self.cwd, 'calmjs.webpack.js'))
        self.assertEqual(spec['calmjs_module_registry_names'],
                         ['calmjs.module'])
        self.assertEqual(spec['source_package_names'], ['calmjs.webpack'])

        # ensure the warning message, too.
        log = stream.getvalue()
        self.assertIn(
            "webpack_entry_point and/or webpack_output_library is assigned "
            "a different value than their defaults while calmjs_compat is set "
            "to True ", log)
        self.assertEqual(spec.get('webpack_entry_point'), '__calmjs__')
Пример #15
0
    def test_create_spec_entry_point_compat_enabled(self):
        with pretty_logging(stream=StringIO()) as stream:
            spec = create_spec(
                [],
                calmjs_compat=True,
                webpack_entry_point='foo',
                webpack_output_library='foo',
            )

        self.assertNotIn('packages []', stream.getvalue())
        self.assertIn('no packages specified', stream.getvalue())
        self.assertIn(
            "webpack_entry_point and/or webpack_output_library is assigned a "
            "different value than their defaults while calmjs_compat is set "
            "to True in function calmjs.webpack.cli.create_spec; to have "
            "those values take effect, ensure the calmjs_compat argument is "
            "set to False", stream.getvalue())
        self.assertTrue(isinstance(spec, Spec))
        self.assertEqual(spec['webpack_output_library'], '__calmjs__')
        self.assertEqual(spec['webpack_entry_point'], '__calmjs__')
Пример #16
0
 def test_create_spec_with_calmjs_webpack_output_library_enabled(self):
     with pretty_logging(stream=StringIO()) as stream:
         spec = create_spec(
             ['calmjs.webpack'],
             calmjs_compat=False,
             webpack_output_library=True,
         )
     log = stream.getvalue()
     self.assertNotIn(
         "webpack_entry_point is ignored; set calmjs_compat to false "
         "to enable manual webpack.entry specification", log)
     self.assertNotIn(
         "webpack.output.library is disabled; it will be unset.", log)
     self.assertIn(
         "calmjs_compat is disabled; webpack.output.library "
         "automatically set to 'calmjs.webpack', derived from input "
         "package names and export filename", log)
     # note that this is probably an invalid value.
     self.assertEqual(spec['webpack_entry_point'], '__calmjs__')
     self.assertEqual(spec['webpack_output_library'], 'calmjs.webpack')