Example #1
0
def run_webpack_compilation(source_maps=False):
    """Runs webpack compilation.

    Args:
        source_maps: bool. Whether to compile with source maps.
    """
    max_tries = 5
    webpack_bundles_dir_name = 'webpack_bundles'

    for _ in range(max_tries):
        try:
            managed_webpack_compiler = (servers.managed_webpack_compiler(
                use_source_maps=source_maps))
            with managed_webpack_compiler as proc:
                proc.wait()
        except subprocess.CalledProcessError as error:
            print(error.output)
            sys.exit(error.returncode)
            return
        if os.path.isdir(webpack_bundles_dir_name):
            break
    else:
        # We didn't break out of the loop, meaning all attempts have failed.
        print('Failed to complete webpack compilation, exiting...')
        sys.exit(1)
Example #2
0
    def test_managed_webpack_compiler_with_max_old_space_size(self):
        popen_calls = self.exit_stack.enter_context(
            self.swap_popen(outputs=[b'Built at: 123']))

        self.exit_stack.enter_context(
            servers.managed_webpack_compiler(max_old_space_size=2056))
        self.exit_stack.close()

        self.assertEqual(len(popen_calls), 1)
        self.assertIn('--max-old-space-size=2056', popen_calls[0].program_args)
Example #3
0
    def test_managed_webpack_compiler_uses_explicit_config_path(self):
        popen_calls = self.exit_stack.enter_context(
            self.swap_popen(outputs=[b'Built at: 123']))

        self.exit_stack.enter_context(
            servers.managed_webpack_compiler(config_path='config.json'))
        self.exit_stack.close()

        self.assertEqual(len(popen_calls), 1)
        self.assertEqual(
            popen_calls[0].program_args, '%s %s --config config.json' %
            (common.NODE_BIN_PATH, common.WEBPACK_BIN_PATH))
Example #4
0
    def test_managed_webpack_compiler_uses_dev_config(self):
        popen_calls = self.exit_stack.enter_context(
            self.swap_popen(outputs=[b'Built at: 123']))

        self.exit_stack.enter_context(
            servers.managed_webpack_compiler(use_prod_env=False,
                                             use_source_maps=False))
        self.exit_stack.close()

        self.assertEqual(len(popen_calls), 1)
        self.assertEqual(
            popen_calls[0].program_args, '%s %s --config %s' %
            (common.NODE_BIN_PATH, common.WEBPACK_BIN_PATH,
             common.WEBPACK_DEV_CONFIG))
def run_webpack_compilation():
    """Runs webpack compilation."""
    max_tries = 5
    webpack_bundles_dir_name = 'webpack_bundles'
    for _ in range(max_tries):
        try:
            with servers.managed_webpack_compiler() as proc:
                proc.wait()
        except subprocess.CalledProcessError as error:
            print(error.output)
            sys.exit(error.returncode)
        if os.path.isdir(webpack_bundles_dir_name):
            break
    if not os.path.isdir(webpack_bundles_dir_name):
        print('Failed to complete webpack compilation, exiting...')
        sys.exit(1)
Example #6
0
    def test_managed_webpack_compiler_in_watch_mode_raises_when_not_built(self):
        # NOTE: The 'Built at: ' message is never printed.
        self.exit_stack.enter_context(self.swap_popen(outputs=[b'abc', b'def']))
        str_io = python_utils.string_io()
        self.exit_stack.enter_context(python_utils.redirect_stdout(str_io))

        self.assertRaisesRegexp(
            IOError, 'First build never completed',
            lambda: self.exit_stack.enter_context(
                servers.managed_webpack_compiler(watch_mode=True)))
        self.assert_matches_regexps(str_io.getvalue().strip().split('\n'), [
            'Starting new Webpack Compiler',
            'abc',
            'def',
            'Stopping Webpack Compiler',
        ])
Example #7
0
    def test_managed_webpack_compiler_in_watch_mode_when_build_succeeds(self):
        popen_calls = self.exit_stack.enter_context(
            self.swap_popen(outputs=[b'abc', b'Built at: 123', b'def']))
        str_io = io.StringIO()
        self.exit_stack.enter_context(contextlib.redirect_stdout(str_io))
        logs = self.exit_stack.enter_context(self.capture_logging())

        proc = self.exit_stack.enter_context(
            servers.managed_webpack_compiler(watch_mode=True))
        self.exit_stack.close()

        self.assert_proc_was_managed_as_expected(logs, proc.pid)
        self.assertEqual(len(popen_calls), 1)
        self.assertIn('--color', popen_calls[0].program_args)
        self.assertIn('--watch', popen_calls[0].program_args)
        self.assertIn('--progress', popen_calls[0].program_args)
        self.assert_matches_regexps(str_io.getvalue().strip().split('\n'), [
            'Starting new Webpack Compiler',
            'abc',
            'Built at: 123',
            'def',
            'Stopping Webpack Compiler',
        ])