Skip to content
Myr

markers.test.ts

This file

Path

packages/gate/test/markers.test.ts

121 lines · 3.6 KiB · TypeScript

Last changed by

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–121why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { RepoPath } from "@repo/protocol/ids";3import { Option } from "effect";45import { defaultMarkers, markersOf, scanMarkers } from "../src/markers.ts";6import { addedLines, policy } from "./facts.ts";78const texts = defaultMarkers.map((marker) => marker.text);910const lines: readonly (readonly [string, string])[] = [11 [".skip(", ' it.skip("parses week 53", () => {'],12 [".only(", ' describe.only("weeks", () => {'],13 [".todo(", ' it.todo("parses week 54");'],14 ["eslint-disable", "/* eslint-disable no-console */"],15 ["oxlint-disable", "// oxlint-disable-next-line no-explicit-any"],16 ["biome-ignore", "// biome-ignore lint/style: generated"],17 ["@ts-ignore", "// @ts-ignore"],18 ["@ts-expect-error", "// @ts-expect-error"],19 ["@ts-nocheck", "// @ts-nocheck"],20 ["@effect-diagnostics", "// @effect-diagnostics-next-line"],21 ["# noqa", "import os # noqa"],22 ["# type: ignore", "x = parse(y) # type: ignore"],23 ["#[allow(", "#[allow(dead_code)]"],24 ["//nolint", "func parse() { //nolint"],25 ["istanbul ignore", "/* istanbul ignore next */"],26 ["c8 ignore", "/* c8 ignore next */"],27];2829describe(markersOf, () => {30 it("starts from the spec's default list, each marker with the kind of check it turns off", () => {31 expect(32 defaultMarkers.map(({ family, text }) => `${family} ${text}`)33 ).toStrictEqual([34 "test .skip(",35 "test .only(",36 "test .todo(",37 "lint eslint-disable",38 "lint oxlint-disable",39 "lint biome-ignore",40 "types @ts-ignore",41 "types @ts-expect-error",42 "types @ts-nocheck",43 "effect @effect-diagnostics",44 "python # noqa",45 "python # type: ignore",46 "rust #[allow(",47 "go //nolint",48 "coverage istanbul ignore",49 "coverage c8 ignore",50 ]);51 });5253 it("adds the markers a project adds to the defaults, each once", () => {54 expect(55 markersOf({56 ...policy,57 weakening: { markers: ["vi.mock(", ".skip("] },58 })59 ).toStrictEqual([...texts, "vi.mock("]);60 });61});6263describe(scanMarkers, () => {64 it.each(lines)("finds %s where a tool writes it", (marker, text) => {65 const hits = scanMarkers(addedLines(["src/x.ts", 5, text]), texts);6667 expect(hits.map((hit) => hit.marker)).toContain(marker);68 });6970 it("finds a marker in any file, a README's prose included", () => {71 const hits = scanMarkers(72 addedLines(["README.md", 40, "Run `it.only(` to focus a test."]),73 texts74 );7576 expect(hits).toStrictEqual([77 {78 line: 40,79 marker: ".only(",80 path: RepoPath.make("README.md"),81 reason: Option.none(),82 },83 ]);84 });8586 it("reads the reason after ` -- `, without the comment's closer", () => {87 const hits = scanMarkers(88 addedLines(89 ["src/a.ts", 1, "// oxlint-disable-next-line no-x -- reason given"],90 ["src/a.ts", 2, "/* eslint-disable no-y -- generated code */"],91 ["src/a.ts", 3, "// @ts-expect-error -- "],92 ["src/a.ts", 4, "it.skip(--flag)"]93 ),94 texts95 );9697 expect(hits.map((hit) => hit.reason)).toStrictEqual([98 Option.some("reason given"),99 Option.some("generated code"),100 Option.none(),101 Option.none(),102 ]);103 });104105 it("orders what it finds by path, then line", () => {106 const hits = scanMarkers(107 addedLines(108 ["src/b.ts", 9, "it.only("],109 ["src/b.ts", 3, "it.skip("],110 ["src/a.ts", 7, "// @ts-ignore"]111 ),112 texts113 );114115 expect(hits.map(({ line, path }) => `${path}:${line}`)).toStrictEqual([116 "src/a.ts:7",117 "src/b.ts:3",118 "src/b.ts:9",119 ]);120 });121});