def test_reporting_errors(self):
     # TODO:
     self.compile_bundles("webpack.config.error.js")
     try:
         get_bundle("main", get_config(DEFAULT_CONFIG))
     except WebpackError as e:
         self.assertIn("Cannot resolve module 'the-library-that-did-not-exist'", str(e))
 def test_missing_stats_file(self):
     os.remove(settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'])
     try:
         get_assets(get_config(DEFAULT_CONFIG))
     except IOError as e:
         expected = 'Error reading {}. Are you sure webpack has generated the file and the path is correct?'.format(settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'])
         self.assertIn(expected, str(e))
 def test_missing_stats_file(self):
     os.remove(settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'])
     try:
         get_assets(get_config(DEFAULT_CONFIG))
     except IOError as e:
         expected = 'Error reading {}. Are you sure webpack has generated the file and the path is correct?'.format(
             settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'])
         self.assertIn(expected, str(e))
 def test_reporting_errors(self):
     #TODO:
     self.compile_bundles('webpack.config.error.js')
     try:
         get_bundle('main', get_config(DEFAULT_CONFIG))
     except WebpackError as e:
         self.assertIn(
             "Cannot resolve module 'the-library-that-did-not-exist'",
             str(e))
 def test_bad_status_in_production(self):
     stats_file = open(
         settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'], 'w')
     stats_file.write(json.dumps({'status': 'unexpected-status'}))
     stats_file.close()
     try:
         get_bundle('main', get_config(DEFAULT_CONFIG))
     except WebpackLoaderBadStatsError as e:
         self.assertIn(
             ("The stats file does not contain valid data. Make sure "
              "webpack-bundle-tracker plugin is enabled and try to run"
              " webpack again."), str(e))
    def test_simple_and_css_extract(self):
        self.compile_bundles("webpack.config.simple.js")
        assets = get_assets(get_config(DEFAULT_CONFIG))
        self.assertEqual(assets["status"], "done")
        self.assertIn("chunks", assets)

        chunks = assets["chunks"]
        self.assertIn("main", chunks)
        self.assertEqual(len(chunks), 1)

        main = chunks["main"]
        self.assertEqual(main[0]["path"], os.path.join(settings.BASE_DIR, "assets/bundles/main.js"))
        self.assertEqual(main[1]["path"], os.path.join(settings.BASE_DIR, "assets/bundles/styles.css"))
    def test_simple_and_css_extract(self):
        self.compile_bundles('webpack.config.simple.js')
        assets = get_assets(get_config(DEFAULT_CONFIG))
        self.assertEqual(assets['status'], 'done')
        self.assertIn('chunks', assets)

        chunks = assets['chunks']
        self.assertIn('main', chunks)
        self.assertEqual(len(chunks), 1)

        main = chunks['main']
        self.assertEqual(main[0]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/main.js'))
        self.assertEqual(main[1]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/styles.css'))
 def test_bad_status_in_production(self):
     stats_file = open(
         settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'], 'w'
     )
     stats_file.write(json.dumps({'status': 'unexpected-status'}))
     stats_file.close()
     try:
         get_bundle('main', get_config(DEFAULT_CONFIG))
     except WebpackLoaderBadStatsError as e:
         self.assertIn((
             "The stats file does not contain valid data. Make sure "
             "webpack-bundle-tracker plugin is enabled and try to run"
             " webpack again."
         ), str(e))
    def test_code_spliting(self):
        self.compile_bundles("webpack.config.split.js")
        assets = get_assets(get_config(DEFAULT_CONFIG))
        self.assertEqual(assets["status"], "done")
        self.assertIn("chunks", assets)

        chunks = assets["chunks"]
        self.assertIn("main", chunks)
        self.assertEquals(len(chunks), 2)

        main = chunks["main"]
        self.assertEqual(main[0]["path"], os.path.join(settings.BASE_DIR, "assets/bundles/main.js"))

        vendor = chunks["vendor"]
        self.assertEqual(vendor[0]["path"], os.path.join(settings.BASE_DIR, "assets/bundles/vendor.js"))
    def test_code_spliting(self):
        self.compile_bundles('webpack.config.split.js')
        assets = get_assets(get_config(DEFAULT_CONFIG))
        self.assertEqual(assets['status'], 'done')
        self.assertIn('chunks', assets)

        chunks = assets['chunks']
        self.assertIn('main', chunks)
        self.assertEquals(len(chunks), 2)

        main = chunks['main']
        self.assertEqual(main[0]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/main.js'))

        vendor = chunks['vendor']
        self.assertEqual(vendor[0]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/vendor.js'))
    def test_simple_and_css_extract(self):
        self.compile_bundles('webpack.config.simple.js')
        assets = get_assets(get_config(DEFAULT_CONFIG))
        self.assertEqual(assets['status'], 'done')
        self.assertIn('chunks', assets)

        chunks = assets['chunks']
        self.assertIn('main', chunks)
        self.assertEqual(len(chunks), 1)

        main = chunks['main']
        self.assertEqual(
            main[0]['path'],
            os.path.join(settings.BASE_DIR, 'assets/bundles/main.js'))
        self.assertEqual(
            main[1]['path'],
            os.path.join(settings.BASE_DIR, 'assets/bundles/styles.css'))
    def test_code_spliting(self):
        self.compile_bundles('webpack.config.split.js')
        assets = get_assets(get_config(DEFAULT_CONFIG))
        self.assertEqual(assets['status'], 'done')
        self.assertIn('chunks', assets)

        chunks = assets['chunks']
        self.assertIn('main', chunks)
        self.assertEquals(len(chunks), 2)

        main = chunks['main']
        self.assertEqual(
            main[0]['path'],
            os.path.join(settings.BASE_DIR, 'assets/bundles/main.js'))

        vendor = chunks['vendor']
        self.assertEqual(
            vendor[0]['path'],
            os.path.join(settings.BASE_DIR, 'assets/bundles/vendor.js'))
 def test_static_url(self):
     self.compile_bundles('webpack.config.publicPath.js')
     assets = get_assets(get_config(DEFAULT_CONFIG))
     self.assertEqual(assets['status'], 'done')
     self.assertEqual(assets['publicPath'],
                      'http://custom-static-host.com/')
 def test_static_url(self):
     self.compile_bundles("webpack.config.publicPath.js")
     assets = get_assets(get_config(DEFAULT_CONFIG))
     self.assertEqual(assets["status"], "done")
     self.assertEqual(assets["publicPath"], "http://custom-static-host.com/")
 def test_static_url(self):
     self.compile_bundles('webpack.config.publicPath.js')
     assets = get_assets(get_config(DEFAULT_CONFIG))
     self.assertEqual(assets['status'], 'done')
     self.assertEqual(assets['publicPath'], 'http://custom-static-host.com/')