# Path: webpack/compiler.py
# def webpack(config_file, context=None, settings=None, manifest=manifest_reader, compiler=build_server):
#     use_manifest = conf.settings.USE_MANIFEST
# 
#     # Allow the USE_MANIFEST setting to be overridden when populating the manifest
#     if settings:
#         use_manifest = settings.get('USE_MANIFEST', use_manifest)
# 
#     if use_manifest:
#         return manifest.read(config_file, context)
# 
#     return compiler.build(
#         config_file=config_file,
#         extra_context=context,
#         setting_overrides=settings,
#     )
# 
# Path: tests/settings.py
# BUNDLES = os.path.join(BASE_DIR, 'bundles',)
# 
# Path: tests/utils.py
# def write_file(file_name, content):
#     with open(file_name, 'w') as _file:
#         _file.write(content)
# 
# def read_file(file_name):
#     with open(file_name, 'r') as _file:
#         return _file.read()
# 
# def clean_output_root():
#     # Clean out any files generated from previous test runs
#     if os.path.exists(settings.OUTPUT_ROOT):
#         shutil.rmtree(settings.OUTPUT_ROOT)


import os
import unittest
import time
from webpack.compiler import webpack
from .settings import BUNDLES
from .utils import write_file, read_file, clean_output_root
PATH_TO_WATCHED_SOURCE_ENTRY = os.path.join(BUNDLES, 'watched_source', 'app', 'entry.js')

WATCHED_CONFIG_CONTENT = """
var path = require('path');

module.exports = {
    context: path.join(__dirname, 'app'),
    entry: './entry1.js',
    output: {
        filename: 'bundle-[hash].js'
    }
};
"""

WATCHED_SOURCE_CONTENT = """module.exports = '__DJANGO_WEBPACK_WATCH_SOURCE_ONE__';"""


# Ensure that the files are in the state that we expect
write_file(PATH_TO_WATCHED_SOURCE_ENTRY, WATCHED_SOURCE_CONTENT)


class TestWatching(unittest.TestCase):
    _PRODUCTION = True

    @classmethod
    def setUpClass(cls):
        clean_output_root()

    @classmethod
    def tearDownClass(cls):

# Path: webpack/compiler.py
# def webpack(config_file, context=None, settings=None, manifest=manifest_reader, compiler=build_server):
#     use_manifest = conf.settings.USE_MANIFEST
# 
#     # Allow the USE_MANIFEST setting to be overridden when populating the manifest
#     if settings:
#         use_manifest = settings.get('USE_MANIFEST', use_manifest)
# 
#     if use_manifest:
#         return manifest.read(config_file, context)
# 
#     return compiler.build(
#         config_file=config_file,
#         extra_context=context,
#         setting_overrides=settings,
#     )
# 
# Path: tests/settings.py
# BUNDLES = os.path.join(BASE_DIR, 'bundles',)
# 
# Path: tests/utils.py
# def write_file(file_name, content):
#     with open(file_name, 'w') as _file:
#         _file.write(content)
# 
# def read_file(file_name):
#     with open(file_name, 'r') as _file:
#         return _file.read()
# 
# def clean_output_root():
#     # Clean out any files generated from previous test runs
#     if os.path.exists(settings.OUTPUT_ROOT):
#         shutil.rmtree(settings.OUTPUT_ROOT)


# Path: tests/test_watching.py
import os
import unittest
import time
from webpack.compiler import webpack
from .settings import BUNDLES
from .utils import write_file, read_file, clean_output_root

PATH_TO_WATCHED_SOURCE_ENTRY = os.path.join(BUNDLES, 'watched_source', 'app', 'entry.js')

WATCHED_CONFIG_CONTENT = """
var path = require('path');

module.exports = {
    context: path.join(__dirname, 'app'),
    entry: './entry1.js',
    output: {
        filename: 'bundle-[hash].js'
    }
};
"""

WATCHED_SOURCE_CONTENT = """module.exports = '__DJANGO_WEBPACK_WATCH_SOURCE_ONE__';"""


# Ensure that the files are in the state that we expect
write_file(PATH_TO_WATCHED_SOURCE_ENTRY, WATCHED_SOURCE_CONTENT)


class TestWatching(unittest.TestCase):
    _PRODUCTION = True

    @classmethod
    def setUpClass(cls):
        clean_output_root()

    @classmethod
    def tearDownClass(cls):

        clean_output_root()