1
import fs from "fs/promises";
2
import glob from "glob";
3
-import invariant from "invariant";
3
import path from "path";
4
import { FILTER_PATH, FIXTURES_PATH } from "./constants";
5
6
+const KIND_DEFAULT = "only";
7
export type TestFilter =
8
| {
9
kind: "only";
10
+ debug: boolean;
11
paths: Array<string>;
12
}
13
| {
14
kind: "skip";
15
+ debug: boolean;
16
paths: Array<string>;
17
};
18
32
33
const input = await fs.readFile(FILTER_PATH, "utf8");
34
const lines = input.trim().split("\n");
33
- if (lines.length < 2) {
34
- console.warn("Misformed filter file. Expected at least two lines.");
35
- return null;
36
- }
35
38
- let filter: "only" | "skip" | null = null;
39
- if (lines[0]!.indexOf("@only") !== -1) {
40
- filter = "only";
41
- }
42
- if (lines[0]!.indexOf("@skip") !== -1) {
43
- filter = "skip";
44
- }
45
- if (filter === null) {
46
- console.warn(
47
- "Misformed filter file. Expected first line to contain @only or @skip"
48
- );
49
- return null;
36
+ let filter: "only" | "skip" = KIND_DEFAULT;
37
+ let debug: boolean = false;
38
+ const line0 = lines[0];
39
+ if (line0 != null) {
40
+ // Try to parse pragmas
41
+ let consumedLine0 = false;
42
+ if (line0.indexOf("@only") !== -1) {
43
+ filter = "only";
44
+ consumedLine0 = true;
45
+ } else if (line0.indexOf("@skip") !== -1) {
46
+ filter = "skip";
47
+ consumedLine0 = true;
48
+ }
49
+ if (line0.indexOf("@debug") !== -1) {
50
+ debug = true;
51
+ consumedLine0 = true;
52
+ }
53
+
54
+ if (consumedLine0) {
55
+ lines.shift();
56
+ }
57
}
51
- lines.shift();
58
return {
59
kind: filter,
60
+ debug,
61
paths: lines,
62
};
63
}