# test.govlab/quality/core/matchers/target.matcher.test.ts

> 34 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-quality-core-matchers-target-matcher-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/quality/core/matchers/target.matcher.test.ts.txt

Listed in [test.govlab/quality/core/matchers](https://banes-lab.com/api/source/testing/test.govlab/quality/core/matchers.md), after [test.govlab/quality/core/matchers/exclusions.matcher.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/matchers/exclusions.matcher.test.ts.md) and before [test.govlab/quality/core/matchers/word.matcher.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/matchers/word.matcher.test.ts.md).

## Contained in

- [test.govlab/quality/core/matchers](https://banes-lab.com/anatomy/testing/folder-testing-test-govlab-quality-core-matchers.md)

## Source

```typescript
import { describe, expect, it } from "vitest";
import { esTokenYear, findStaleEsTokens } from "@govlab/quality/core/matchers/target.matcher.ts";

const ENFORCED_YEAR = 2025;

const TSCONFIG = `{
    // frontend package
    "compilerOptions": {
        "target": "ES2021",
        "module": "NodeNext",
        "lib": ["ES2021", "DOM", "DOM.Iterable"]
    }
}
`;

describe("esTokenYear", () => {
    it("reads a year token, an edition number and ESNext, and refuses anything else", () => {
        expect(esTokenYear("ES2021")).toBe(2021);
        expect(esTokenYear("ES6")).toBe(2015);
        expect(esTokenYear("ESNext")).toBe(Number.POSITIVE_INFINITY);
        expect(esTokenYear("DOM")).toBeNull();
        expect(esTokenYear("ES20x1")).toBeNull();
    });
});

describe("findStaleEsTokens", () => {
    it("flags target + lib below the enforced revision, ignoring DOM and non-ES strings", () => {
        const stale = findStaleEsTokens(TSCONFIG, ENFORCED_YEAR);
        expect(stale.map((s) => s.token)).toEqual(["ES2021", "ES2021"]);
    });

    it("treats ESNext and the enforced revision itself as not stale", () => {
        const text = `{ "target": "ESNext", "lib": ["ESNext", "DOM"] }`;
        expect(findStaleEsTokens(text, ENFORCED_YEAR)).toHaveLength(0);
    });

    it("normalizes edition shorthands (ES6 === ES2015) as stale", () => {
        expect(findStaleEsTokens(`{ "target": "ES6" }`, ENFORCED_YEAR).map((s) => s.token)).toEqual(["ES6"]);
    });
});
```
