UNPKG

@api-platform/client-generator

Version:

Generate apps built with Next, Nuxt, Quasar, React, React Native, Vue or Vuetify for any API documented using Hydra or OpenAPI

43 lines 1.98 kB
import { Api, Resource, Field } from "@api-platform/api-doc-parser"; import path from "path"; import { fileURLToPath } from "url"; import fs from "fs"; import tmp from "tmp"; import ReactGenerator from "./ReactGenerator.js"; var dirname = path.dirname(fileURLToPath(import.meta.url)); test("Generate a React app", function () { var generator = new ReactGenerator({ hydraPrefix: "hydra:", templateDirectory: "".concat(dirname, "/../../templates") }); var tmpobj = tmp.dirSync({ unsafeCleanup: true }); var fields = [new Field("bar", { id: "http://schema.org/url", range: "http://www.w3.org/2001/XMLSchema#string", reference: null, required: true, description: "An URL" })]; var resource = new Resource("abc", "http://example.com/foos", { id: "abc", title: "abc", readableFields: fields, writableFields: fields }); var api = new Api("http://example.com", { entrypoint: "http://example.com:8080", title: "My API", resources: [resource] }); generator.generate(api, resource, tmpobj.name); ["/utils/dataAccess.ts", "/utils/types.ts", "/config/entrypoint.ts", "/interfaces/Abc.ts", "/interfaces/Collection.ts", "/components/abc/index.ts", "/components/abc/Create.tsx", "/components/abc/Update.tsx", "/components/abc/type.ts", "/components/Field.tsx", "/components/Links.tsx", "/components/Pagination.tsx", "/routes/abc.tsx", "/hooks/create.ts", "/hooks/delete.ts", "/hooks/fetch.ts", "/hooks/index.ts", "/hooks/list.ts", "/hooks/mercure.ts", "/hooks/retrieve.ts", "/hooks/show.ts", "/hooks/update.ts"].forEach(function (file) { return expect(fs.existsSync(tmpobj.name + file)).toBe(true); }); ["/components/abc/Form.tsx", "/components/abc/List.tsx", "/components/abc/Show.tsx", "/interfaces/Abc.ts"].forEach(function (file) { expect(fs.existsSync(tmpobj.name + file)).toBe(true); expect(fs.readFileSync(tmpobj.name + file, "utf8")).toMatch(/bar/); }); tmpobj.removeCallback(); });