Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): Add @fern-api/ir-generator-tests #5291

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/path-utils";

export const DYNAMIC_IR_TEST_DEFINITIONS_DIRECTORY = AbsoluteFilePath.of(
`${__dirname}/../../../../../../packages/cli/generation/ir-generator/src/dynamic-snippets/__test__/test-definitions`
`${__dirname}/../../../../../../packages/cli/generation/ir-generator-tests/src/dynamic-snippets/__test__/test-definitions`
);
10 changes: 10 additions & 0 deletions packages/cli/generation/ir-generator-tests/.depcheckrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ignores": [
"@types/jest",
"globals",
"@types/node"
],
"ignore-patterns": [
"lib"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("../../../../.prettierrc.json");
48 changes: 48 additions & 0 deletions packages/cli/generation/ir-generator-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@fern-api/ir-generator-tests",
"version": "0.0.0",
"repository": {
"type": "git",
"url": "https://github.com/fern-api/fern.git",
"directory": "packages/cli/generation/ir-generator-tests"
},
"private": true,
"files": [
"lib"
],
"type": "module",
"source": "src/index.ts",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"sideEffects": false,
"scripts": {
"clean": "rm -rf ./lib && tsc --build --clean",
"compile": "tsc --build",
"test": "vitest --passWithNoTests --run",
"test:update": "vitest --passWithNoTests --run -u",
"lint:eslint": "eslint --max-warnings 0 . --ignore-path=../../../../.eslintignore",
"lint:eslint:fix": "yarn lint:eslint --fix",
"format": "prettier --write --ignore-unknown --ignore-path ../../../../shared/.prettierignore \"**\"",
"format:check": "prettier --check --ignore-unknown --ignore-path ../../../../shared/.prettierignore \"**\"",
"organize-imports": "organize-imports-cli tsconfig.json",
"depcheck": "depcheck"
},
"dependencies": {
"@fern-api/configuration": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/ir-generator": "workspace:*",
"@fern-api/ir-sdk": "workspace:*",
"@fern-api/project-loader": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@fern-api/workspace-loader": "workspace:*",
"prettier": "^2.7.1"
},
"devDependencies": {
"@types/node": "18.7.18",
"depcheck": "^1.4.6",
"eslint": "^8.56.0",
"organize-imports-cli": "^0.10.0",
"typescript": "4.6.4",
"vitest": "^2.0.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { serialization as IrSerialization } from "@fern-api/ir-sdk";
import { createMockTaskContext } from "@fern-api/task-context";
import { AbstractAPIWorkspace } from "@fern-api/workspace-loader";
import { writeFile } from "fs/promises";
import { generateIntermediateRepresentation } from "../../generateIntermediateRepresentation";
import { convertIrToDynamicSnippetsIr } from "../convertIrToDynamicSnippetsIr";
import { convertIrToDynamicSnippetsIr, generateIntermediateRepresentation } from "@fern-api/ir-generator";

export async function generateAndSnapshotDynamicIR({
workspace,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Name } from "@fern-api/ir-sdk";
import { constructCasingsGenerator } from "../casings/CasingsGenerator";
import { constructCasingsGenerator } from "@fern-api/ir-generator";

describe("casingsGenerator", () => {
const casingsGenerator = constructCasingsGenerator({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpPath } from "@fern-api/ir-sdk";
import { constructHttpPath } from "../converters/services/constructHttpPath";
import { constructHttpPath } from "@fern-api/ir-generator";

describe("constructHttpPath", () => {
it("/hello/{world}", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { RelativeFilePath } from "@fern-api/fs-utils";
import { ResponseErrors } from "@fern-api/ir-sdk";
import { constructCasingsGenerator } from "../casings/CasingsGenerator";
import { convertResponseErrors } from "../converters/services/convertResponseErrors";
import { constructFernFileContext } from "../FernFileContext";
import { convertToFernFilepath } from "../utils/convertToFernFilepath";
import {
constructCasingsGenerator,
constructFernFileContext,
convertResponseErrors,
convertToFernFilepath
} from "@fern-api/ir-generator";

describe("convertResponseErrors", () => {
it("reference to an error in another file", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { serialization as IrSerialization } from "@fern-api/ir-sdk";
import { createMockTaskContext } from "@fern-api/task-context";
import { AbstractAPIWorkspace, loadAPIWorkspace } from "@fern-api/workspace-loader";
import { writeFile } from "fs/promises";
import { generateIntermediateRepresentation } from "../generateIntermediateRepresentation";
import { generateIntermediateRepresentation } from "@fern-api/ir-generator";

export async function generateAndSnapshotIRFromPath({
absolutePathToWorkspace,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TypeResolver } from "../../resolvers/TypeResolver";
import { TypeResolver } from "@fern-api/ir-generator";

export const MockTypeResolver: TypeResolver = {
getDeclarationOfNamedType: () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { RelativeFilePath } from "@fern-api/fs-utils";
import { ContainerType, serialization as IrSerialization, TypeReference } from "@fern-api/ir-sdk";
import { constructCasingsGenerator } from "../casings/CasingsGenerator";
import { constructFernFileContext } from "../FernFileContext";
import { convertToFernFilepath } from "../utils/convertToFernFilepath";
import { parseInlineType } from "../utils/parseInlineType";
import {
constructCasingsGenerator,
constructFernFileContext,
convertToFernFilepath,
parseInlineType
} from "@fern-api/ir-generator";

describe("parse inline types", () => {
it("nested containers", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { AbsoluteFilePath, join, RelativeFilePath } from "@fern-api/fs-utils";
import { createMockTaskContext } from "@fern-api/task-context";
import { loadAPIWorkspace } from "@fern-api/workspace-loader";
import { constructCasingsGenerator } from "../../../casings/CasingsGenerator";
import { constructFernFileContext } from "../../../FernFileContext";
import { SourceResolverImpl } from "../../SourceResolver";
import { constructCasingsGenerator, constructFernFileContext, SourceResolverImpl } from "@fern-api/ir-generator";

describe("SourceResolver", () => {
it("non-existant proto source throws", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { AbsoluteFilePath, join, RelativeFilePath } from "@fern-api/fs-utils";
import { createMockTaskContext } from "@fern-api/task-context";
import { loadAPIWorkspace } from "@fern-api/workspace-loader";
import { constructCasingsGenerator } from "../../../casings/CasingsGenerator";
import { constructFernFileContext } from "../../../FernFileContext";
import { TypeResolverImpl } from "../../TypeResolver";
import { constructCasingsGenerator, constructFernFileContext, TypeResolverImpl } from "@fern-api/ir-generator";

describe("TypeResolver", () => {
it("illogical self-referencing types", async () => {
Expand Down
43 changes: 43 additions & 0 deletions packages/cli/generation/ir-generator-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"extends": "../../../../shared/tsconfig.shared.json",
"compilerOptions": {
"composite": true,
"outDir": "lib",
"rootDir": "src"
},
"include": [
"./src/**/*"
],
"references": [
{
"path": "../../../commons/core-utils"
},
{
"path": "../../../commons/fs-utils"
},
{
"path": "../../../ir-sdk"
},
{
"path": "../../configuration"
},
{
"path": "../../project-loader"
},
{
"path": "../../task-context"
},
{
"path": "../../workspace-loader"
},
{
"path": "../../workspace-commons"
},
{
"path": "../../fern-definition/schema"
},
{
"path": "../ir-generator"
},
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "../../../../shared/vitest.config";
6 changes: 2 additions & 4 deletions packages/cli/generation/ir-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"scripts": {
"clean": "rm -rf ./lib && tsc --build --clean",
"compile": "tsc --build",
"test": "vitest --run",
"test:update": "vitest --run -u",
"test": "vitest --passWithNoTests --run",
"test:update": "vitest --passWithNoTests --run -u",
"lint:eslint": "eslint --max-warnings 0 . --ignore-path=../../../../.eslintignore",
"lint:eslint:fix": "yarn lint:eslint --fix",
"format": "prettier --write --ignore-unknown --ignore-path ../../../../shared/.prettierignore \"**\"",
Expand All @@ -32,9 +32,7 @@
"@fern-api/core-utils": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/ir-sdk": "workspace:*",
"@fern-api/project-loader": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@fern-api/workspace-loader": "workspace:*",
"@fern-api/api-workspace-commons": "workspace:*",
"@fern-api/fern-definition-schema": "workspace:*",
"lodash-es": "^4.17.21",
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/generation/ir-generator/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { constructCasingsGenerator, type CasingsGenerator } from "./casings/CasingsGenerator";
export { constructHttpPath } from "./converters/services/constructHttpPath";
export { convertResponseErrors } from "./converters/services/convertResponseErrors";
export {
DEFAULT_BODY_PROPERTY_KEY_IN_WRAPPER,
DEFAULT_REQUEST_PARAMETER_NAME,
Expand All @@ -22,6 +23,7 @@ export { ErrorResolverImpl, type ErrorResolver } from "./resolvers/ErrorResolver
export { ExampleResolverImpl, type ExampleResolver } from "./resolvers/ExampleResolver";
export { type ResolvedEndpoint } from "./resolvers/ResolvedEndpoint";
export { type ResolvedContainerType, type ResolvedType } from "./resolvers/ResolvedType";
export { SourceResolverImpl, type SourceResolver } from "./resolvers/SourceResolver";
export { TypeResolverImpl, type TypeResolver } from "./resolvers/TypeResolver";
export { VariableResolverImpl, type VariableResolver } from "./resolvers/VariableResolver";
export {
Expand All @@ -32,6 +34,7 @@ export {
} from "./utils/getAllPropertiesForObject";
export { getResolvedPathOfImportedFile } from "./utils/getResolvedPathOfImportedFile";
export { parseReferenceToEndpointName, type ReferenceToEndpointName } from "./utils/parseReferenceToEndpointName";
export { parseInlineType } from "./utils/parseInlineType";
export { parseReferenceToTypeName, type ReferenceToTypeName } from "./utils/parseReferenceToTypeName";
export { IdGenerator } from "./IdGenerator";
export { convertToFernFilepath } from "./utils/convertToFernFilepath";
Expand Down
42 changes: 30 additions & 12 deletions packages/cli/generation/ir-generator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
{
"extends": "../../../../shared/tsconfig.shared.json",
"compilerOptions": { "composite": true, "outDir": "lib", "rootDir": "src" },
"include": ["./src/**/*"],
"compilerOptions": {
"composite": true,
"outDir": "lib",
"rootDir": "src"
},
"include": [
"./src/**/*"
],
"references": [
{ "path": "../../../commons/core-utils" },
{ "path": "../../../commons/fs-utils" },
{ "path": "../../../ir-sdk" },
{ "path": "../../configuration" },
{ "path": "../../project-loader" },
{ "path": "../../task-context" },
{ "path": "../../workspace-loader" },
{ "path": "../../workspace-commons" },
{ "path": "../../fern-definition/schema" }
{
"path": "../../../commons/core-utils"
},
{
"path": "../../../commons/fs-utils"
},
{
"path": "../../../ir-sdk"
},
{
"path": "../../configuration"
},
{
"path": "../../task-context"
},
{
"path": "../../workspace-commons"
},
{
"path": "../../fern-definition/schema"
}
]
}
}
52 changes: 46 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading