Skip to content

Commit

Permalink
Fix freshness and watch tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rictic committed Aug 27, 2023
1 parent 0056c0a commit 6bf98c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 9 additions & 11 deletions src/test/freshness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1877,15 +1877,17 @@ test(
const inv = await main.nextInvocation();
// Write some output.
await rig.write('output/subdir/foo', '1');
await exec.waitForLog(/0% \[0 \/ 1\] \[1 running\] main/); //
inv.exit(0);
assert.equal((await exec.exit).code, 0);
assert.equal(main.numInvocations, 1);
await exec.waitForLog(/Ran 1 script and skipped 0/);
}

// Fresh because nothing changed.
{
const exec = rig.exec('npm run main');
await exec.waitForLog(/Already fresh/);
await exec.waitForLog(/Ran 0 scripts and skipped 1/);
assert.equal((await exec.exit).code, 0);
assert.equal(main.numInvocations, 1);
}
Expand All @@ -1900,19 +1902,18 @@ test(
WIREIT_CACHE: 'none',
},
});
await exec.waitForLog(
/Output files were modified since the previous run/
);
await exec.waitForLog(/0% \[0 \/ 1\] \[1 running\] main/); //
const inv = await main.nextInvocation();
inv.exit(0);
assert.equal((await exec.exit).code, 0);
assert.equal(main.numInvocations, 2);
await exec.waitForLog(/Ran 1 script and skipped 0/);
}

// Fresh again because nothing changed.
{
const exec = rig.exec('npm run main');
await exec.waitForLog(/Already fresh/);
await exec.waitForLog(/Ran 0 scripts and skipped 1/);
assert.equal((await exec.exit).code, 0);
assert.equal(main.numInvocations, 2);
}
Expand All @@ -1923,10 +1924,7 @@ test(
await rig.write('output/subdir/bar', '0');
// Don't disable caching this time.
const exec = rig.exec('npm run main');
await exec.waitForLog(
/Output files were modified since the previous run/
);
await exec.waitForLog(/Restored from cache/);
await exec.waitForLog(/Ran 0 scripts and skipped 1/);
assert.equal((await exec.exit).code, 0);
assert.equal(main.numInvocations, 2);
assert.equal(await rig.read('output/subdir/foo'), '1');
Expand All @@ -1936,7 +1934,7 @@ test(
// Fresh again because nothing changed.
{
const exec = rig.exec('npm run main');
await exec.waitForLog(/Already fresh/);
await exec.waitForLog(/Ran 0 scripts and skipped 1/);
assert.equal((await exec.exit).code, 0);
assert.equal(main.numInvocations, 2);
assert.equal(await rig.read('output/subdir/foo'), '1');
Expand All @@ -1948,7 +1946,7 @@ test(
{
await rig.touch('output/subdir/excluded');
const exec = rig.exec('npm run main');
await exec.waitForLog(/Already fresh/);
await exec.waitForLog(/Ran 0 scripts and skipped 1/);
assert.equal((await exec.exit).code, 0);
assert.equal(main.numInvocations, 2);
}
Expand Down
20 changes: 11 additions & 9 deletions src/test/watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ test(
},
});
(await a.nextInvocation()).exit(0);
await wireit.waitForLog(/\[a\] Executed successfully/);
await wireit.waitForLog(/Ran 1 script and skipped 0/);

// Add a dependency on another package, but the other package.json has
// invalid JSON.
Expand Down Expand Up @@ -591,10 +591,11 @@ test(
},
},
});
await wireit.waitForLog(/0% \[0 \/ 2\] \[1 running\]/);
(await b.nextInvocation()).exit(0);
await wireit.waitForLog(/\[other:b\] Executed successfully/);
await wireit.waitForLog(/50% \[1 \/ 2\] \[1 running\] a/);
(await a.nextInvocation()).exit(0);
await wireit.waitForLog(/\[a\] Executed successfully/);
await wireit.waitForLog(/Ran 2 scripts and skipped 0/);

wireit.kill();
await wireit.exit;
Expand Down Expand Up @@ -787,7 +788,7 @@ test(
// Wait until wireit is in the "watching" state, otherwise the double file
// change events would occur in the "running" state, which wouldn't trigger
// the double runs.
await exec.waitForLog(/Watching for file changes/);
await exec.waitForLog(/Ran 2 scripts and skipped 0/);

// Changing an input file should cause one more run.
{
Expand All @@ -798,7 +799,7 @@ test(
(await cmdA.nextInvocation()).exit(0);
}

await exec.waitForLog(/Watching for file changes/);
await exec.waitForLog(/Ran 2 scripts and skipped 0/);

// Wait a moment to ensure a third run doesn't occur.
await new Promise((resolve) => setTimeout(resolve, 100));
Expand Down Expand Up @@ -856,6 +857,9 @@ test(
test(
'script fails but still emits output consumed by another script',
timeout(async ({rig}) => {
// This test relies on the simple logger.
rig.env['WIREIT_LOGGER'] = 'simple';

const cmdA = await rig.newCommand();
const cmdB = await rig.newCommand();
await rig.writeAtomic({
Expand Down Expand Up @@ -939,19 +943,17 @@ test(
const exec = rig.exec('npm run a --watch');
const inv = await cmdA.nextInvocation();
inv.exit(0);
await exec.waitForLog(/Ran 1 script and skipped 0/);

// Write an input file, but it's the same content. This will cause the file
// watcher to trigger, and will start an execution, but the execution will
// ultimately do nothing interesting because the fingerprint is the same, so
// we shouldn't actually expect any logging.
await rig.writeAtomic('input', 'foo');
// Wait a moment to give the watcher time to react.
await new Promise((resolve) => setTimeout(resolve, 100));
await exec.waitForLog(/Ran 0 scripts and skipped 1/);

exec.kill();
const {stdout} = await exec.exit;
assert.equal(cmdA.numInvocations, 1);
assert.equal([...stdout.matchAll(/Watching for file changes/gi)].length, 1);
})
);

Expand Down

0 comments on commit 6bf98c9

Please sign in to comment.