Separate snap flags for watch/update/filter
This is not that big a deal but a constant papercut, i often want to jump directly to watch mode with a filter applied. I know @poteto likes to (or at least used to) run watch with update enabled. Now instead of passing a mode, you can pass `--watch`, `--filter`, and `--update` independently.
Joe Savona committed
Feb 5, 2024 at 15:55 UTC
0277bc4d54437bfb2ff4df7c80b68f3f0eee22a2
1 file changed
+17
-14
compiler/packages/snap/src/runner.ts
+17
-14
@@ -51,7 +51,9 @@ process.on("SIGTERM", function () {
51
type RunnerOptions = {
52
sync: boolean;
53
workerThreads: boolean;
54
- mode: "watch" | "update" | "filter" | null;
54
+ watch: boolean;
55
+ filter: boolean;
56
+ update: boolean;
57
};
58
59
const opts: RunnerOptions = yargs
@@ -67,16 +69,18 @@ const opts: RunnerOptions = yargs
69
"Run compiler in worker threads (instead of subprocesses). Defaults to true."
70
)
71
.default("worker-threads", true)
72
+ .boolean("watch")
73
+ .describe("watch", "Run compiler in watch mode, re-running after changes")
74
+ .default("watch", false)
75
+ .boolean("update")
76
+ .describe("update", "Update fixtures")
77
+ .default("update", false)
78
+ .boolean("filter")
79
.describe(
71
- "mode",
72
- "Snap tester modes:\n" +
73
- " [default] - test all test fixtures\n" +
74
- ` filter - test filtered fixtures ("${FILTER_FILENAME}")\n` +
75
- " update - update all test fixtures)\n" +
76
- " watch - watch for changes"
80
+ "filter",
81
+ "Only run fixtures which match the contents of testfilter.txt"
82
)
78
- .choices("mode", ["watch", "update", "filter", null])
79
- .default("mode", null)
83
+ .default("filter", false)
84
.help("help")
85
.strict()
86
.parseSync(hideBin(process.argv));
@@ -253,7 +257,7 @@ export async function main(opts: RunnerOptions): Promise<void> {
257
worker.end();
258
});
259
256
- if (opts.mode === "watch") {
260
+ if (opts.watch) {
261
// Monotonically increasing integer to describe the 'version' of the compiler.
262
// This is passed to `compile()` (from compiler-worker) when compiling, so
263
// that the worker knows when it has to reset its module cache and when its
@@ -261,7 +265,7 @@ export async function main(opts: RunnerOptions): Promise<void> {
265
let compilerVersion = 0;
266
let isCompilerValid = false;
267
let lastUpdate = -1;
264
- let filterMode: boolean = false;
268
+ let filterMode: boolean = opts.filter;
269
let testFilter: TestFilter | null;
270
271
function isRealUpdate(): boolean {
@@ -410,10 +414,9 @@ export async function main(opts: RunnerOptions): Promise<void> {
414
async (compileSuccess: boolean) => {
415
let isSuccess = compileSuccess;
416
if (compileSuccess) {
413
- const testFilter =
414
- opts.mode === "filter" ? await readTestFilter() : null;
417
+ const testFilter = opts.filter ? await readTestFilter() : null;
418
const results = await run(worker, opts, testFilter, 0);
416
- if (opts.mode === "update") {
419
+ if (opts.update) {
420
update(results);
421
} else {
422
const testSuccess = report(results);