Skip to content

Commit

Permalink
test(alias): additional test cases for alias usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Krakazybik committed Jan 31, 2022
1 parent 80e4426 commit 0bf954f
Showing 1 changed file with 51 additions and 40 deletions.
91 changes: 51 additions & 40 deletions rules/public-api/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ describe("PublicAPI import boundaries:", () => {
import { Button } from "shared/ui/button/button";
import { saveOrder } from "entities/order/model/actions";
import { orderModel } from "entities/order/model";
import { TicketCard } from "@app/entities/ticket/ui";
import { Ticket } from "@app/entities/ticket/ui.tsx";
import { TicketCard } from "@src/entities/ticket/ui";
import { Ticket } from "@src/entities/ticket/ui.tsx";
`,
{ filePath: "src/app/ui/index.js" });
assert.strictEqual(report[0].errorCount, 8);
Expand All @@ -29,13 +29,13 @@ describe("PublicAPI import boundaries:", () => {
it("Should lint PublicAPI boundaries without errors.", async () => {
const report = await eslint.lintText(`
import { Issues } from "pages/issues";
import { GoodIssues } from "@app/pages/issues";
import { GoodIssues } from "@src/pages/issues";
import { IssueDetails } from "widgets/issue-details";
import { AuthForm } from "features/auth-form";
import { Button } from "shared/ui/button";
import { orderModel } from "entities/order";
import { TicketCard } from "@/entities/ticket";
import { FixButton } from "@app/shared/ui/fix-button";
import { FixButton } from "@src/shared/ui/fix-button";
`, { filePath: "src/app/ui/index.js" });
assert.strictEqual(report[0].errorCount, 0);
});
Expand All @@ -52,19 +52,19 @@ describe("PublicAPI import boundaries:", () => {
describe("Allow not segments import from slices:", () => {
it("should lint without errors", async () => {
const report = await eslint.lintText(`
import { AuthForm } from "entities/auth";
import { model } from "../model";
import { styles } from "./styles.module.scss";
`, { filePath: "src/features/form/ui/index.js" });
import { AuthForm } from "entities/auth";
import { model } from "../model";
import { styles } from "./styles.module.scss";
`, { filePath: "src/features/form/ui/index.js" });

assert.strictEqual(report[0].errorCount, 0);
});

it("should lint with errors", async () => {
const report = await eslint.lintText(`
import { AuthForm } from "entities/auth/ui";
import { Button } from "shared/button";
`, { filePath: "src/features/form/ui/index.js" });
import { AuthForm } from "entities/auth/ui";
import { Button } from "shared/button";
`, { filePath: "src/features/form/ui/index.js" });

assert.strictEqual(report[0].errorCount, 2);
});
Expand All @@ -73,17 +73,17 @@ describe("PublicAPI import boundaries:", () => {
describe("Allow slices with structure grouping:", () => {
it("should lint with errors", async () => {
const report = await eslint.lintText(`
import { AuthForm } from "entities/auth/form";
`, { filePath: "src/features/form/ui/index.js" });
import { AuthForm } from "entities/auth/form";
`, { filePath: "src/features/form/ui/index.js" });

assert.strictEqual(report[0].errorCount, 0);
});

it("should lint without errors", async () => {
const report = await eslint.lintText(`
import { AuthForm } from "entities/auth/ui";
import { Form } from "shared/button/form";
`, { filePath: "src/features/form/ui/index.js" });
import { AuthForm } from "entities/auth/ui";
import { Form } from "shared/button/form";
`, { filePath: "src/features/form/ui/index.js" });

assert.strictEqual(report[0].errorCount, 2);
});
Expand All @@ -92,32 +92,43 @@ describe("PublicAPI import boundaries:", () => {
describe("Allow not segments import in shared segments:", () => {
it("should lint without errors", async () => {
const report = await eslint.lintText(`
import { Form } from "shared/ui/form";
import { AuthAPI } from "shared/api/auth";
import { useGeo } from "shared/lib/hooks";
import { styles } from "shared/ui/styles";
import { CONNECT_ATTEMPTS } from "shared/config";
`, { filePath: "src/features/form/ui/index.js" });
import { Form } from "shared/ui/form";
import { AuthAPI } from "shared/api/auth";
import { useGeo } from "shared/lib/hooks";
import { styles } from "shared/ui/styles";
import { CONNECT_ATTEMPTS } from "shared/config";
`, { filePath: "src/features/form/ui/index.js" });

assert.strictEqual(report[0].errorCount, 0);
});

it("should lint with errors", async () => {
const report = await eslint.lintText(`
import { Hex } from "shared/api/ui";
import { Form } from "shared/ui/lib";
import { AuthForm } from "shared/api/ui";
import { model } from "shared/ui/model";
`, { filePath: "src/features/form/ui/index.js" });
import { Hex } from "shared/api/ui";
import { Form } from "shared/ui/lib";
import { AuthForm } from "shared/api/ui";
import { model } from "shared/ui/model";
`, { filePath: "src/features/form/ui/index.js" });

assert.strictEqual(report[0].errorCount, 4);
});

it("should lint without errors", async () => {
const report = await eslint.lintText(`
import { FancyLabel } from "../../label";
import { model } from "../model";
`, { filePath: "src/shared/ui/button/index.js" });
import { FancyLabel } from "../../label";
import { model } from "../model";
`, { filePath: "src/shared/ui/button/index.js" });

assert.strictEqual(report[0].errorCount, 0);
});

it("should lint aliases without errors", async () => {
const report = await eslint.lintText(`
import { routeNames } from '@/entities/one';
import { fetchRules } from '@entities/two';
import { Three } from '@features/three';
import { Four } from '@/features/four';
`, { filePath: "src/pages/main/ui/index.js" });

assert.strictEqual(report[0].errorCount, 0);
});
Expand All @@ -126,22 +137,22 @@ describe("PublicAPI import boundaries:", () => {
describe("Import from segments in shared:", () => {
it("should lint without errors", async () => {
const report = await eslint.lintText(`
import { AuthAPI } from "shared/api";
import { FancyLabel } from 'shared/ui';
import { convertToken } from 'shared/lib';
import { CONNECT_ATTEMPTS } from "shared/config";
`, { filePath: "src/pages/main/ui/index.js" });
import { AuthAPI } from "shared/api";
import { FancyLabel } from 'shared/ui';
import { convertToken } from 'shared/lib';
import { CONNECT_ATTEMPTS } from "shared/config";
`, { filePath: "src/pages/main/ui/index.js" });

assert.strictEqual(report[0].errorCount, 0);
});

it("should lint with errors", async () => {
const report = await eslint.lintText(`
import { AuthAPI } from "shared/auth";
import { FancyLabel } from 'shared/label';
import { convertToken } from 'shared/token';
import { CONNECT_ATTEMPTS } from "shared/const";
`, { filePath: "src/pages/main/ui/index.js" });
import { AuthAPI } from "shared/auth";
import { FancyLabel } from 'shared/label';
import { convertToken } from 'shared/token';
import { CONNECT_ATTEMPTS } from "shared/const";
`, { filePath: "src/pages/main/ui/index.js" });

assert.strictEqual(report[0].errorCount, 4);
});
Expand Down

0 comments on commit 0bf954f

Please sign in to comment.