def test_background_script_imports(self): """Tests that background scripts are imported.""" chrome_app_manifest = { 'app': {'background': {'scripts': ['my.jss', 'góod.aspx', 'script.py']}} } service_worker = caterpillar.generate_service_worker( self.output_path, chrome_app_manifest, [], BOILERPLATE_DIR) for script in chrome_app_manifest['app']['background']['scripts']: self.assertIn("importScripts('{}');".format(script), service_worker, '{} not imported.'.format(script))
def test_polyfill_imports(self): """Tests that polyfills are imported.""" chrome_app_manifest = {'app': {'background': {}}} polyfills = ['póly.polyfill.js', 'fill.polyfill.js'] service_worker = caterpillar.generate_service_worker( self.output_path, chrome_app_manifest, polyfills, BOILERPLATE_DIR) for polyfill in polyfills: relpath = os.path.join(BOILERPLATE_DIR, polyfill) self.assertIn("importScripts('{}');".format(relpath), service_worker, '{} not imported.'.format(relpath))
def test_polyfill_imports(self): """Tests that polyfills are imported.""" chrome_app_manifest = { 'app': {'background': {}} } polyfills = ['póly.polyfill.js', 'fill.polyfill.js'] service_worker = caterpillar.generate_service_worker( self.output_path, chrome_app_manifest, polyfills, BOILERPLATE_DIR) for polyfill in polyfills: relpath = os.path.join(BOILERPLATE_DIR, polyfill) self.assertIn("importScripts('{}');".format(relpath), service_worker, '{} not imported.'.format(relpath))
def test_background_script_imports(self): """Tests that background scripts are imported.""" chrome_app_manifest = { 'app': { 'background': { 'scripts': ['my.jss', 'góod.aspx', 'script.py'] } } } service_worker = caterpillar.generate_service_worker( self.output_path, chrome_app_manifest, [], BOILERPLATE_DIR) for script in chrome_app_manifest['app']['background']['scripts']: self.assertIn("importScripts('{}');".format(script), service_worker, '{} not imported.'.format(script))
def test_all_files_cached(self): """Tests that the generated service worker caches all files.""" chrome_app_manifest = {'app': {'background': {}}} service_worker = caterpillar.generate_service_worker( self.output_path, chrome_app_manifest, [], BOILERPLATE_DIR) cache_list = re.search(r'CACHED_FILES = (\[[^\]]*?\])', service_worker).group(1) cache_list_json = cache_list.replace("'", '"') cached_files = json.loads(cache_list_json) expected_cached_files = [] for root, _, files in os.walk(self.output_path): for name in files: relpath = os.path.relpath(os.path.join(root, name), self.output_path) expected_cached_files.append(relpath) self.assertItemsEqual(cached_files, expected_cached_files)
def test_all_files_cached(self): """Tests that the generated service worker caches all files.""" chrome_app_manifest = { 'app': {'background': {}} } service_worker = caterpillar.generate_service_worker( self.output_path, chrome_app_manifest, [], BOILERPLATE_DIR) cache_list = re.search( r'CACHED_FILES = (\[[^\]]*?\])', service_worker).group(1) cache_list_json = cache_list.replace("'", '"') cached_files = json.loads(cache_list_json) expected_cached_files = [] for root, _, files in os.walk(self.output_path): for name in files: relpath = os.path.relpath(os.path.join(root, name), self.output_path) expected_cached_files.append(relpath) self.assertItemsEqual(cached_files, expected_cached_files)