# test.govlab/quality/core/stylelint/custom-property-order.stylelint.rule.test.ts

> 26 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-quality-core-stylelint-custom-property-order-stylelint-rule-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/quality/core/stylelint/custom-property-order.stylelint.rule.test.ts.txt

Listed in [test.govlab/quality/core/stylelint](https://banes-lab.com/api/source/testing/test.govlab/quality/core/stylelint.md), after [test.govlab/quality/core/stylelint/consistent-naming.stylelint.rule.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/stylelint/consistent-naming.stylelint.rule.test.ts.md) and before [test.govlab/quality/core/stylelint/custom-property-unit-mismatch.stylelint.rule.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/stylelint/custom-property-unit-mismatch.stylelint.rule.test.ts.md).

## Contained in

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

## Source

```typescript
import { describe, expect, it } from "vitest";
import customPropertyOrder, { RULE_META } from "@govlab/quality/core/stylelint/custom-property-order.stylelint.rule.ts";
import stylelint from "stylelint";

const TOKENS_FILE = "tokens.css";

const lint = async function lint(code: string, codeFilename: string): Promise<readonly string[]> {
    const result = await stylelint.lint({
        code,
        codeFilename,
        config: {
            plugins: [customPropertyOrder],
            rules: { [RULE_META.ruleName]: [true, { tokensFile: TOKENS_FILE }] },
        },
    });
    return result.results.flatMap((entry) => entry.warnings.map((warning) => warning.rule));
};

describe("govlab/custom-property-order", () => {
    it("reports a same-prefix token declared after a larger one in the tokens file", async () => {
        expect(await lint(":root { --font-sm: 1rem; --font-md: 0.8rem; }", TOKENS_FILE)).toStrictEqual([
            RULE_META.ruleName,
        ]);
    });

    it("allows ascending tokens, and ignores files outside the tokens layer", async () => {
        expect(await lint(":root { --font-sm: 0.8rem; --font-md: 1rem; }", TOKENS_FILE)).toStrictEqual([]);
        expect(await lint(":root { --font-sm: 1rem; --font-md: 0.8rem; }", "page.css")).toStrictEqual([]);
    });
});
```
