def test_generated_service_worker(self):
"""Tests that the generated service worker is as expected."""
output_sw_path = os.path.join(self.output_dir, caterpillar.SW_SCRIPT_NAME)
reference_sw_path = os.path.join(
TTS_REFERENCE_PATH, caterpillar.SW_SCRIPT_NAME)
with open(output_sw_path) as output_file:
with open(reference_sw_path) as reference_file:
output_data = output_file.read().decode('utf-8')
reference_data = reference_file.read().decode('utf-8')
# The cache version is randomly generated in the output service worker,
# so reset it to be 0, the same cache version as the reference service
# worker.
output_data = re.sub(
r'CACHE_VERSION = \d+', 'CACHE_VERSION = 0', output_data)
self.assertEqual(output_data, reference_data,
'Difference found in file `{}`.\n{}'.format(
caterpillar.SW_SCRIPT_NAME,
'\n'.join(difflib.unified_diff(
output_data.split('\n'),
reference_data.split('\n'),
fromfile=reference_sw_path,
tofile=output_sw_path,
n=0))))
评论列表
文章目录