feat(core-eslint): workspace helper for conformance rules
This commit is contained in:
34
packages/core-eslint/rules/_workspace.test.js
Normal file
34
packages/core-eslint/rules/_workspace.test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import path from "node:path";
|
||||
import os from "node:os";
|
||||
import fs from "node:fs";
|
||||
import { readWorkspacePackages } from "./_workspace.js";
|
||||
|
||||
function writeWorkspaceYaml(contents) {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "workspace-"));
|
||||
const filepath = path.join(dir, "pnpm-workspace.yaml");
|
||||
fs.writeFileSync(filepath, contents);
|
||||
return { dir, filepath };
|
||||
}
|
||||
|
||||
describe("_workspace", () => {
|
||||
it("returns the list of declared package globs", () => {
|
||||
const { dir } = writeWorkspaceYaml(
|
||||
`packages:
|
||||
- "apps/*"
|
||||
- "packages/*"
|
||||
`,
|
||||
);
|
||||
expect(readWorkspacePackages(dir)).toEqual(["apps/*", "packages/*"]);
|
||||
});
|
||||
|
||||
it("returns [] when pnpm-workspace.yaml is missing", () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "workspace-"));
|
||||
expect(readWorkspacePackages(dir)).toEqual([]);
|
||||
});
|
||||
|
||||
it("returns [] when packages key is absent", () => {
|
||||
const { dir } = writeWorkspaceYaml(`# empty\n`);
|
||||
expect(readWorkspacePackages(dir)).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user