Skip to content

Commit

Permalink
watch cmd: Update out-of-date bundles right away.
Browse files Browse the repository at this point in the history
  • Loading branch information
miracle2k committed Jun 3, 2012
1 parent 98d2d9a commit afd1eda
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/webassets/script.py
Expand Up @@ -231,7 +231,15 @@ def check_for_changes():
return changed_bundles

try:
self.log.info("Watching %d bundles for changes..." % len(self.environment))
# Before starting to watch for changes, also recognize changes
# made while we did not run, and apply those immediately.
for bundle in self.environment:
print 'Bringing up to date: %s' % bundle.output
bundle.build(force=False)

self.log.info("Watching %d bundles for changes..." %
len(self.environment))

while True:
changed_bundles = check_for_changes()
built = []
Expand Down
23 changes: 23 additions & 0 deletions tests/test_script.py
Expand Up @@ -254,3 +254,26 @@ def test_same_file_multiple_bundles(self):
# Both output files have been updated.
assert self.get('out') == 'foo'
assert self.get('out2') == 'foo'

def test_initial_build(self):
"""The watch command also detects changes that were made while it was
not running, and applies those right away on start.
"""
# Register a bundle to watch
bundle = self.mkbundle('in', output='out')
self.env.register('test', bundle)

# Mark the input file has changed before we even run the command.
now = self.setmtime('in')
self.setmtime('out', mtime=now-100)

# Assert initial state
assert self.get('out') == 'bar'

# Run the watch command for a while, but don't make any changes.
with self:
time.sleep(0.2)

# Output file has been updated, not due to a change detected by watch,
# but because watch recognized the initial requirement for a build.
assert self.get('out') == 'foo'

0 comments on commit afd1eda

Please sign in to comment.