RunEffectQuickFixTest executes a single Effect quick-fix baseline test case. It creates a fourslash test instance, collects quick-fix inventory and application results, and generates a *.quickfixes.txt baseline.
(t *testing.T, version bundledeffect.EffectVersion, testFile string)
| 23 | // It creates a fourslash test instance, collects quick-fix inventory and application |
| 24 | // results, and generates a *.quickfixes.txt baseline. |
| 25 | func RunEffectQuickFixTest(t *testing.T, version bundledeffect.EffectVersion, testFile string) { |
| 26 | AcquireProgram() |
| 27 | defer ReleaseProgram() |
| 28 | |
| 29 | // Read the test file |
| 30 | content, err := os.ReadFile(testFile) |
| 31 | if err != nil { |
| 32 | t.Fatal("Failed to read test file:", err) |
| 33 | } |
| 34 | |
| 35 | // Parse test file into units (handles @filename directives) |
| 36 | defaultFileName := tspath.GetBaseFileName(testFile) |
| 37 | units := parseTestUnits(string(content), defaultFileName) |
| 38 | |
| 39 | // Build fourslash content with @filename directives |
| 40 | var sb strings.Builder |
| 41 | currentDirectory := "/.src" |
| 42 | |
| 43 | // Check if a tsconfig is provided |
| 44 | hasTsConfig := false |
| 45 | for _, unit := range units { |
| 46 | unitName := tspath.GetNormalizedAbsolutePath(unit.name, currentDirectory) |
| 47 | if strings.HasSuffix(strings.ToLower(unitName), "tsconfig.json") || strings.HasSuffix(strings.ToLower(unitName), "jsconfig.json") { |
| 48 | hasTsConfig = true |
| 49 | break |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // Inject default tsconfig if none was provided |
| 54 | if !hasTsConfig { |
| 55 | sb.WriteString("// @filename: ") |
| 56 | sb.WriteString(tspath.GetNormalizedAbsolutePath("tsconfig.json", currentDirectory)) |
| 57 | sb.WriteString("\n") |
| 58 | sb.WriteString(DefaultTsConfig) |
| 59 | sb.WriteString("\n") |
| 60 | } |
| 61 | |
| 62 | // Collect test file paths for later use |
| 63 | var testFileNames []string |
| 64 | |
| 65 | // Add all test units as fourslash files |
| 66 | for _, unit := range units { |
| 67 | unitName := tspath.GetNormalizedAbsolutePath(unit.name, currentDirectory) |
| 68 | sb.WriteString("// @filename: ") |
| 69 | sb.WriteString(unitName) |
| 70 | sb.WriteString("\n") |
| 71 | sb.WriteString(unit.content) |
| 72 | sb.WriteString("\n") |
| 73 | |
| 74 | // Track non-config files |
| 75 | if !strings.HasSuffix(strings.ToLower(unitName), "tsconfig.json") && !strings.HasSuffix(strings.ToLower(unitName), "jsconfig.json") { |
| 76 | testFileNames = append(testFileNames, unitName) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // Create fourslash test instance |
| 81 | f, done := fourslash.NewFourslash(t, nil, sb.String()) |
| 82 | defer done() |