From 0118ab7b63fe81d60e842830dd4d76f1f158dd80 Mon Sep 17 00:00:00 2001 From: Romain Lenzotti Date: Sun, 3 Mar 2024 09:41:45 +0100 Subject: [PATCH] feat(cli-plugin-vitest): add new plugin to generate project with vitest --- .nycrc | 23 ------ docs/.vuepress/config.js | 4 + docs/.vuepress/public/vitest.png | Bin 0 -> 10823 bytes docs/readme.md | 5 +- packages/cli-plugin-vitest/.eslintignore | 13 +++ packages/cli-plugin-vitest/.eslintrc.js | 1 + packages/cli-plugin-vitest/.npmignore | 4 + packages/cli-plugin-vitest/jest.config.js | 15 ++++ packages/cli-plugin-vitest/package.json | 35 ++++++++ packages/cli-plugin-vitest/readme.md | 31 ++++++++ .../scripts/templateDir.esm.js | 5 ++ .../src/CliPluginVitestModule.ts | 42 ++++++++++ .../src/hooks/VitestGenerateHook.ts | 68 ++++++++++++++++ .../src/hooks/VitestInitHook.ts | 39 +++++++++ packages/cli-plugin-vitest/src/index.ts | 5 ++ .../src/utils/templateDir.ts | 3 + .../generate/decorator.class.spec.hbs | 12 +++ .../generate/decorator.endpoint.spec.hbs | 16 ++++ .../generate/decorator.method.spec.hbs | 14 ++++ .../generate/decorator.param.spec.hbs | 15 ++++ .../generate/decorator.parameter.spec.hbs | 13 +++ .../generate/decorator.prop.spec.hbs | 16 ++++ .../generate/decorator.property.spec.hbs | 14 ++++ .../generate/generic.integration.hbs | 21 +++++ .../templates/generate/generic.spec.hbs | 15 ++++ .../templates/generate/server.integration.hbs | 21 +++++ .../templates/init/vitest.config.mts.hbs | 16 ++++ .../generate.controller.integration.spec.ts | 75 ++++++++++++++++++ packages/cli-plugin-vitest/tsconfig.esm.json | 39 +++++++++ packages/cli-plugin-vitest/tsconfig.json | 39 +++++++++ .../commands/init/config/FeaturesPrompt.ts | 41 ++-------- .../init/prompts/getFeaturesPrompt.spec.ts | 7 ++ tsconfig.json | 3 + yarn.lock | 26 ++++-- 34 files changed, 634 insertions(+), 62 deletions(-) delete mode 100644 .nycrc create mode 100644 docs/.vuepress/public/vitest.png create mode 100644 packages/cli-plugin-vitest/.eslintignore create mode 100644 packages/cli-plugin-vitest/.eslintrc.js create mode 100644 packages/cli-plugin-vitest/.npmignore create mode 100644 packages/cli-plugin-vitest/jest.config.js create mode 100644 packages/cli-plugin-vitest/package.json create mode 100644 packages/cli-plugin-vitest/readme.md create mode 100644 packages/cli-plugin-vitest/scripts/templateDir.esm.js create mode 100644 packages/cli-plugin-vitest/src/CliPluginVitestModule.ts create mode 100644 packages/cli-plugin-vitest/src/hooks/VitestGenerateHook.ts create mode 100644 packages/cli-plugin-vitest/src/hooks/VitestInitHook.ts create mode 100644 packages/cli-plugin-vitest/src/index.ts create mode 100644 packages/cli-plugin-vitest/src/utils/templateDir.ts create mode 100644 packages/cli-plugin-vitest/templates/generate/decorator.class.spec.hbs create mode 100644 packages/cli-plugin-vitest/templates/generate/decorator.endpoint.spec.hbs create mode 100644 packages/cli-plugin-vitest/templates/generate/decorator.method.spec.hbs create mode 100644 packages/cli-plugin-vitest/templates/generate/decorator.param.spec.hbs create mode 100644 packages/cli-plugin-vitest/templates/generate/decorator.parameter.spec.hbs create mode 100644 packages/cli-plugin-vitest/templates/generate/decorator.prop.spec.hbs create mode 100644 packages/cli-plugin-vitest/templates/generate/decorator.property.spec.hbs create mode 100644 packages/cli-plugin-vitest/templates/generate/generic.integration.hbs create mode 100644 packages/cli-plugin-vitest/templates/generate/generic.spec.hbs create mode 100644 packages/cli-plugin-vitest/templates/generate/server.integration.hbs create mode 100644 packages/cli-plugin-vitest/templates/init/vitest.config.mts.hbs create mode 100644 packages/cli-plugin-vitest/test/integrations/generate/generate.controller.integration.spec.ts create mode 100644 packages/cli-plugin-vitest/tsconfig.esm.json create mode 100644 packages/cli-plugin-vitest/tsconfig.json diff --git a/.nycrc b/.nycrc deleted file mode 100644 index 4ea327727..000000000 --- a/.nycrc +++ /dev/null @@ -1,23 +0,0 @@ -{ - "include": [ - "packages/*/src/**/*.ts" - ], - "exclude": [ - "**/index.ts", - "**/index.js", - "**/interfaces/*.js" - ], - "reporter": [ - "text-summary", - "html", - "lcov" - ], - "extension": [ - ".ts" - ], - "/check-coverage": true, - "/lines": 93, - "/statements": 92, - "/functions": 86, - "/branches": 71.93 -} diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index c6c0112af..89b99f2e0 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -97,6 +97,10 @@ module.exports = { text: 'Eslint', link: 'https://github.com/tsedio/tsed-cli/tree/master/packages/cli-plugin-eslint' }, + { + text: 'Vitest', + link: 'https://github.com/tsedio/tsed-cli/tree/master/packages/cli-plugin-vitest' + }, { text: 'Jest', link: 'https://github.com/tsedio/tsed-cli/tree/master/packages/cli-plugin-jest' diff --git a/docs/.vuepress/public/vitest.png b/docs/.vuepress/public/vitest.png new file mode 100644 index 0000000000000000000000000000000000000000..c25274917ad772f563604c04ef00e64e790742c9 GIT binary patch literal 10823 zcmbt)i9eLz7yn=|vW-FZ%rKTLW#2+$OtK})kU@xQ>|2thY-1;kEo4vGm8@mSZY_uLz4XmFG90`~@2qea&gV8X4cK>fCW4zrsc24A8O_erIC)z~Z{`%Xwui73K4-xiHKbh9N z=exkma3CoBG_>vxdr<35(Jyoq0oD!;Ba%U-)`@RGcRLljho1~QFbrgqK15wnXSkB` zi_6hHM_*{-o=1*_f^`S6?5~f{yT>jAzjnSp-RP5_X% ztPMlcV0h7OW53xe?$!Od)9i&{;+y&TbZs{OX54+RKNBCsC8dadS}-!_APWR$Q;E%` zqCvA&nDo;G%K47_j+`_ZpYh0`H3j_`zk>W&>gRmf( zSmXpCr?hlj9O34Vn~pbsw%tU=Ok}ZCL^=KC0&B>M(jm=kLHPdATUs+n+VW2)1=!dZIYqfK3+l!gqyKx;R)i^2$$h@AC<+cMem53tr?nCALh|uBU zTz%%Mw?2c{kKq75I|ct)AJF7+>Ouo(sING+0woZ4ZL^wWF;RI5m1Q>?)JDYK!pH8LhQ;Uk)*emC)9g_axBgt`*VpI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://koajs.com/ src: /koa.svg +- title: Vitest + href: https://vitest.dev/ + src: /vitest.svg - title: Jest href: https://jestjs.io/ src: /jest.svg diff --git a/packages/cli-plugin-vitest/.eslintignore b/packages/cli-plugin-vitest/.eslintignore new file mode 100644 index 000000000..2aab498ae --- /dev/null +++ b/packages/cli-plugin-vitest/.eslintignore @@ -0,0 +1,13 @@ +node_modules +docs +docs-references +lib +dist +coverage +.nyc_output +*-lock.json +*.lock +benchmarks.* +**/generated + +**/*.js diff --git a/packages/cli-plugin-vitest/.eslintrc.js b/packages/cli-plugin-vitest/.eslintrc.js new file mode 100644 index 000000000..802f86f8b --- /dev/null +++ b/packages/cli-plugin-vitest/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require("@tsed/eslint/node.js"); diff --git a/packages/cli-plugin-vitest/.npmignore b/packages/cli-plugin-vitest/.npmignore new file mode 100644 index 000000000..7f50c0fb8 --- /dev/null +++ b/packages/cli-plugin-vitest/.npmignore @@ -0,0 +1,4 @@ +src +test +tsconfig.compile.json +tsconfig.json diff --git a/packages/cli-plugin-vitest/jest.config.js b/packages/cli-plugin-vitest/jest.config.js new file mode 100644 index 000000000..70dcc4a9d --- /dev/null +++ b/packages/cli-plugin-vitest/jest.config.js @@ -0,0 +1,15 @@ +// For a detailed explanation regarding each configuration property, visit: +// https://jestjs.io/docs/en/configuration.html + +module.exports = { + ...require("@tsed/jest-config"), + roots: ["/src", "/test"], + coverageThreshold: { + global: { + statements: 78.94, + branches: 37.5, + functions: 60, + lines: 78.94 + } + } +}; diff --git a/packages/cli-plugin-vitest/package.json b/packages/cli-plugin-vitest/package.json new file mode 100644 index 000000000..0e9aa5f21 --- /dev/null +++ b/packages/cli-plugin-vitest/package.json @@ -0,0 +1,35 @@ +{ + "name": "@tsed/cli-plugin-vitest", + "version": "5.0.2", + "description": "Ts.ED CLI plugin. Add Jest support", + "source": "./src/index.ts", + "main": "./lib/cjs/index.js", + "module": "./lib/esm/index.js", + "typings": "./lib/types/index.d.ts", + "exports": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/cjs/index.js", + "default": "./lib/esm/index.js" + }, + "scripts": { + "build": "yarn build:ts", + "build:ts": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json && cp scripts/templateDir.esm.js lib/esm/utils/templateDir.js", + "lint": "eslint '**/*.{ts,js}'", + "lint:fix": "eslint '**/*.{ts,js}' --fix", + "test": "cross-env NODE_ENV=test yarn jest --max-workers=2 --passWithNoTests && jest-coverage-thresholds-bumper" + }, + "devDependencies": { + "@tsed/cli": "workspace:*", + "@tsed/cli-core": "workspace:*", + "@tsed/eslint": "workspace:*", + "@tsed/jest-config": "workspace:*", + "@tsed/typescript": "workspace:*", + "cross-env": "7.0.3", + "eslint": "8.22.0", + "jest": "29.5.0" + }, + "dependencies": { + "tslib": "2.3.1" + } +} diff --git a/packages/cli-plugin-vitest/readme.md b/packages/cli-plugin-vitest/readme.md new file mode 100644 index 000000000..b9a261af2 --- /dev/null +++ b/packages/cli-plugin-vitest/readme.md @@ -0,0 +1,31 @@ +# @tsed/cli-plugin-jest + +

+ Ts.ED logo +

+ +[![Build & Release](https://github.com/tsedio/tsed-cli/workflows/Build%20&%20Release/badge.svg?branch=master)](https://github.com/tsedio/tsed-cli/actions?query=workflow%3A%22Build+%26+Release%22) + +> Ts.ED CLI plugin. Add Jest support + +## Features + +Please refer to the [documentation](https://cli.tsed.io/) for more details. + +## Installation + +```bash +npm install -g @tsed/cli-plugin-jest +``` + +## Contributors +Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html) + + + + +## Backers + +Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)] + + diff --git a/packages/cli-plugin-vitest/scripts/templateDir.esm.js b/packages/cli-plugin-vitest/scripts/templateDir.esm.js new file mode 100644 index 000000000..e6cd43d32 --- /dev/null +++ b/packages/cli-plugin-vitest/scripts/templateDir.esm.js @@ -0,0 +1,5 @@ +import {getTemplateDirectory} from "@tsed/cli-core"; +import path from "node:path"; +import {fileURLToPath} from "node:url"; + +export const TEMPLATE_DIR = getTemplateDirectory(path.dirname(fileURLToPath(import.meta.url))); diff --git a/packages/cli-plugin-vitest/src/CliPluginVitestModule.ts b/packages/cli-plugin-vitest/src/CliPluginVitestModule.ts new file mode 100644 index 000000000..919a74e3e --- /dev/null +++ b/packages/cli-plugin-vitest/src/CliPluginVitestModule.ts @@ -0,0 +1,42 @@ +import {Module, OnAdd, ProjectPackageJson} from "@tsed/cli-core"; +import {RuntimesModule} from "@tsed/cli"; +import {Inject} from "@tsed/di"; +import {VitestGenerateHook} from "./hooks/VitestGenerateHook"; +import {VitestInitHook} from "./hooks/VitestInitHook"; + +@Module({ + imports: [VitestInitHook, VitestGenerateHook] +}) +export class CliPluginVitestModule { + @Inject() + runtimes: RuntimesModule; + + @Inject() + packageJson: ProjectPackageJson; + + @OnAdd("@tsed/cli-plugin-vitest") + install() { + this.addScripts(); + this.addDevDependencies(); + } + + addScripts() { + const runtime = this.runtimes.get(); + + this.packageJson.addScripts({ + test: `${runtime.run("test:lint")} && ${runtime.run("test:coverage")} `, + "test:unit": "cross-env NODE_ENV=test vitest run", + "test:watch": "cross-env NODE_ENV=test vitest", + "test:coverage": `cross-env NODE_ENV=test vitest run --coverage` + }); + } + + addDevDependencies() { + this.packageJson.addDevDependencies({ + vitest: "latest", + "unplugin-swc": "latest", + "@vitest/coverage-v8": "latest", + "@swc/core": "latest" + }); + } +} diff --git a/packages/cli-plugin-vitest/src/hooks/VitestGenerateHook.ts b/packages/cli-plugin-vitest/src/hooks/VitestGenerateHook.ts new file mode 100644 index 000000000..1fd683b22 --- /dev/null +++ b/packages/cli-plugin-vitest/src/hooks/VitestGenerateHook.ts @@ -0,0 +1,68 @@ +import {GenerateCmdContext} from "@tsed/cli"; +import normalizePath from "normalize-path"; +import {Inject, Injectable, OnExec, SrcRendererService, Tasks} from "@tsed/cli-core"; + +import {TEMPLATE_DIR} from "../utils/templateDir"; + +@Injectable() +export class VitestGenerateHook { + @Inject() + srcRenderService: SrcRendererService; + + @OnExec("generate") + onGenerateExec(ctx: GenerateCmdContext): Tasks { + const {symbolPath} = ctx; + const {specTemplate, integrationTemplate, relativeSrcPath} = this.mapOptions(ctx); + + return [ + { + title: `Generate ${ctx.type} spec file to '${symbolPath}.spec.ts'`, + enabled() { + return !(ctx.type === "server" || ctx.type.includes(":dataSource") || ctx.type.includes(":connection")); + }, + task: () => + this.srcRenderService.render( + specTemplate, + {...ctx, relativeSrcPath}, + { + output: `${symbolPath}.spec.ts`, + templateDir: TEMPLATE_DIR + } + ) + }, + { + title: `Generate ${ctx.type} integration file '${symbolPath}.integration.spec.ts'`, + enabled() { + return ["controller", "server"].includes(ctx.type); + }, + task: () => + this.srcRenderService.render( + integrationTemplate, + {...ctx, relativeSrcPath}, + { + output: `${symbolPath}.integration.spec.ts`, + templateDir: TEMPLATE_DIR + } + ) + } + ]; + } + + private mapOptions(options: GenerateCmdContext) { + const type = [options.type, options.templateType].filter(Boolean).join("."); + + const specTemplate = this.srcRenderService.templateExists(`generate/${type}.spec.hbs`, {templateDir: TEMPLATE_DIR}) + ? `generate/${type}.spec.hbs` + : "generate/generic.spec.hbs"; + + const integrationTemplate = this.srcRenderService.templateExists(`generate/${type}.integration.hbs`, {templateDir: TEMPLATE_DIR}) + ? `generate/${type}.integration.hbs` + : "generate/generic.integration.hbs"; + + return { + specTemplate, + integrationTemplate, + relativeSrcPath: normalizePath(this.srcRenderService.relativeFrom(`${options.symbolPath}.integration.spec.ts`)) + }; + } +} diff --git a/packages/cli-plugin-vitest/src/hooks/VitestInitHook.ts b/packages/cli-plugin-vitest/src/hooks/VitestInitHook.ts new file mode 100644 index 000000000..572262bce --- /dev/null +++ b/packages/cli-plugin-vitest/src/hooks/VitestInitHook.ts @@ -0,0 +1,39 @@ +import { + Inject, + Injectable, + OnExec, + ProjectPackageJson, + RootRendererService, + ScriptsRendererService, + SrcRendererService +} from "@tsed/cli-core"; +import {TEMPLATE_DIR} from "../utils/templateDir"; + +@Injectable() +export class VitestInitHook { + @Inject() + protected packageJson: ProjectPackageJson; + + @Inject() + protected srcRenderer: SrcRendererService; + + @Inject() + protected rootRenderer: RootRendererService; + + @Inject() + protected scriptsRenderer: ScriptsRendererService; + + @OnExec("init") + onInitExec() { + return [ + { + title: "Generate files for vitest", + task: (ctx: any) => { + return this.rootRenderer.renderAll(["vitest.config.ts.hbs"], ctx, { + templateDir: `${TEMPLATE_DIR}/init` + }); + } + } + ]; + } +} diff --git a/packages/cli-plugin-vitest/src/index.ts b/packages/cli-plugin-vitest/src/index.ts new file mode 100644 index 000000000..f866a8f1a --- /dev/null +++ b/packages/cli-plugin-vitest/src/index.ts @@ -0,0 +1,5 @@ +import {CliPluginVitestModule} from "./CliPluginVitestModule"; + +export * from "./utils/templateDir"; + +export default CliPluginVitestModule; diff --git a/packages/cli-plugin-vitest/src/utils/templateDir.ts b/packages/cli-plugin-vitest/src/utils/templateDir.ts new file mode 100644 index 000000000..911a16584 --- /dev/null +++ b/packages/cli-plugin-vitest/src/utils/templateDir.ts @@ -0,0 +1,3 @@ +import {getTemplateDirectory} from "@tsed/cli-core"; + +export const TEMPLATE_DIR = getTemplateDirectory(__dirname); diff --git a/packages/cli-plugin-vitest/templates/generate/decorator.class.spec.hbs b/packages/cli-plugin-vitest/templates/generate/decorator.class.spec.hbs new file mode 100644 index 000000000..69c1d45d6 --- /dev/null +++ b/packages/cli-plugin-vitest/templates/generate/decorator.class.spec.hbs @@ -0,0 +1,12 @@ +import { expect, describe, it } from "vitest"; +import { {{symbolName}} } from "./{{symbolPathBasename}}"; + +describe("{{symbolName}}", () => { + it("should do something", () => { + @{{symbolName}}({}) + class Test { + } + + expect(typeof {{symbolName}}).toBe("function") + }); +}); diff --git a/packages/cli-plugin-vitest/templates/generate/decorator.endpoint.spec.hbs b/packages/cli-plugin-vitest/templates/generate/decorator.endpoint.spec.hbs new file mode 100644 index 000000000..fa00c7db3 --- /dev/null +++ b/packages/cli-plugin-vitest/templates/generate/decorator.endpoint.spec.hbs @@ -0,0 +1,16 @@ +import { expect, describe, it } from "vitest"; +import { Store } from "@tsed/core"; +import { {{symbolName}} } from "./{{symbolPathBasename}}"; + +describe("{{symbolName}}", () => { + it("should store options", () => { + class Test { + @{{symbolName}}({options: "options"}) + method() param: string){} + } + + const store = Store.fromMethod(Test, "method"); + + expect(store.get({{symbolName}})).toEqual({options: "options"}); + }); +}); diff --git a/packages/cli-plugin-vitest/templates/generate/decorator.method.spec.hbs b/packages/cli-plugin-vitest/templates/generate/decorator.method.spec.hbs new file mode 100644 index 000000000..c92062193 --- /dev/null +++ b/packages/cli-plugin-vitest/templates/generate/decorator.method.spec.hbs @@ -0,0 +1,14 @@ +import { expect, describe, it } from "vitest"; +import { {{symbolName}} } from "./{{symbolPathBasename}}"; + +describe("{{symbolName}}", () => { + it("should do something", () => { + class Test { + @{{symbolName}}({}) + method(){} + } + + expect(typeof {{symbolName}}).toBe("function") + expect(typeof {{symbolName}}()).toBe("function") + }); +}); diff --git a/packages/cli-plugin-vitest/templates/generate/decorator.param.spec.hbs b/packages/cli-plugin-vitest/templates/generate/decorator.param.spec.hbs new file mode 100644 index 000000000..05b86fb04 --- /dev/null +++ b/packages/cli-plugin-vitest/templates/generate/decorator.param.spec.hbs @@ -0,0 +1,15 @@ +import { expect, describe, it } from "vitest"; +import { Store } from "@tsed/core"; +import { {{symbolName}} } from "./{{symbolPathBasename}}"; + +describe("{{symbolName}}", () => { + it("should store options", () => { + class Test { + method(@{{symbolName}}({options: "options"}) param: string){} + } + + const store = Store.from(Test, "method", 0) + + expect(store.get({{symbolName}})).toEqual({options: "options"}); + }); +}); diff --git a/packages/cli-plugin-vitest/templates/generate/decorator.parameter.spec.hbs b/packages/cli-plugin-vitest/templates/generate/decorator.parameter.spec.hbs new file mode 100644 index 000000000..70dff120b --- /dev/null +++ b/packages/cli-plugin-vitest/templates/generate/decorator.parameter.spec.hbs @@ -0,0 +1,13 @@ +import { expect, describe, it } from "vitest"; +import { {{symbolName}} } from "./{{symbolPathBasename}}"; + +describe("{{symbolName}}", () => { + it("should do something", () => { + class Test { + method(@{{symbolName}}({}) param: string){} + } + + expect(typeof {{symbolName}}).toBe("function") + expect(typeof {{symbolName}}()).toBe("function") + }); +}); diff --git a/packages/cli-plugin-vitest/templates/generate/decorator.prop.spec.hbs b/packages/cli-plugin-vitest/templates/generate/decorator.prop.spec.hbs new file mode 100644 index 000000000..71def6a63 --- /dev/null +++ b/packages/cli-plugin-vitest/templates/generate/decorator.prop.spec.hbs @@ -0,0 +1,16 @@ +import { expect, describe, it } from "vitest"; +import { Store } from "@tsed/core"; +import { {{symbolName}} } from "./{{symbolPathBasename}}"; + +describe("{{symbolName}}", () => { + it("should store options", () => { + class Test { + @{{symbolName}}({options: "options"}) + property: string; + } + + const store = Store.from(Test, "property"); + + expect(store.get({{symbolName}})).toEqual({options: "options"}); + }); +}); diff --git a/packages/cli-plugin-vitest/templates/generate/decorator.property.spec.hbs b/packages/cli-plugin-vitest/templates/generate/decorator.property.spec.hbs new file mode 100644 index 000000000..a5feeef6b --- /dev/null +++ b/packages/cli-plugin-vitest/templates/generate/decorator.property.spec.hbs @@ -0,0 +1,14 @@ +import { expect, describe, it } from "vitest"; +import { {{symbolName}} } from "./{{symbolPathBasename}}"; + +describe("{{symbolName}}", () => { + it("should do something", () => { + class Test { + @{{symbolName}}({}) + property: string; + } + + expect(typeof {{symbolName}}).toBe("function") + expect(typeof {{symbolName}}()).toBe("function") + }); +}); diff --git a/packages/cli-plugin-vitest/templates/generate/generic.integration.hbs b/packages/cli-plugin-vitest/templates/generate/generic.integration.hbs new file mode 100644 index 000000000..731697c62 --- /dev/null +++ b/packages/cli-plugin-vitest/templates/generate/generic.integration.hbs @@ -0,0 +1,21 @@ +import { expect, describe, it, afterAll, beforeAll } from "vitest"; +import { PlatformTest } from "@tsed/common"; +import SuperTest from "supertest"; +import { {{symbolName}} } from "./{{symbolPathBasename}}"; +import { Server } from "{{relativeSrcPath}}/Server"; + +describe("{{symbolName}}", () => { + beforeAll(PlatformTest.bootstrap(Server, { + mount: { + "/": [{{symbolName}}] + } + })); + afterAll(PlatformTest.reset); + + it("should call GET {{route}}", async () => { + const request = SuperTest(PlatformTest.callback()); + const response = await request.get("{{route}}").expect(200); + + expect(response.text).toEqual("hello"); + }); +}); diff --git a/packages/cli-plugin-vitest/templates/generate/generic.spec.hbs b/packages/cli-plugin-vitest/templates/generate/generic.spec.hbs new file mode 100644 index 000000000..830b5ad6d --- /dev/null +++ b/packages/cli-plugin-vitest/templates/generate/generic.spec.hbs @@ -0,0 +1,15 @@ +import { expect, describe, it, beforeEach, afterEach } from "vitest"; +import { PlatformTest } from "@tsed/common"; +import { {{symbolName}} } from "./{{symbolPathBasename}}"; + +describe("{{symbolName}}", () => { + beforeEach(PlatformTest.create); + afterEach(PlatformTest.reset); + + it("should do something", () => { + const instance = PlatformTest.get<{{symbolName}}>({{symbolName}}); + // const instance = PlatformTest.invoke<{{symbolName}}>({{symbolName}}); // get fresh instance + + expect(instance).toBeInstanceOf({{symbolName}}); + }); +}); diff --git a/packages/cli-plugin-vitest/templates/generate/server.integration.hbs b/packages/cli-plugin-vitest/templates/generate/server.integration.hbs new file mode 100644 index 000000000..4aa7fc5dc --- /dev/null +++ b/packages/cli-plugin-vitest/templates/generate/server.integration.hbs @@ -0,0 +1,21 @@ +import { expect, describe, it, beforeAll, afterAll } from "vitest"; +import { PlatformTest } from "@tsed/common"; +import SuperTest from "supertest"; +import { {{symbolName}} } from "./{{symbolPathBasename}}"; + +describe("{{symbolName}}", () => { + beforeAll(PlatformTest.bootstrap({{symbolName}})); + afterAll(PlatformTest.reset); + + it("should call GET {{route}}", async () => { + const request = SuperTest(PlatformTest.callback()); + const response = await request.get("{{route}}").expect(404); + + expect(response.body).toEqual({ + errors: [], + message: 'Resource "/rest" not found', + name: "NOT_FOUND", + status: 404, + }); + }); +}); diff --git a/packages/cli-plugin-vitest/templates/init/vitest.config.mts.hbs b/packages/cli-plugin-vitest/templates/init/vitest.config.mts.hbs new file mode 100644 index 000000000..ee1ef340e --- /dev/null +++ b/packages/cli-plugin-vitest/templates/init/vitest.config.mts.hbs @@ -0,0 +1,16 @@ +import swc from "unplugin-swc"; +import {defineConfig} from "vitest/config"; + +export default defineConfig({ + test: { + globals: true, + root: "./" + }, + plugins: [ + // This is required to build the test files with SWC + swc.vite({ + // Explicitly set the module type to avoid inheriting this value from a `.swcrc` config file + module: {type: "es6"} + }) + ] +}); diff --git a/packages/cli-plugin-vitest/test/integrations/generate/generate.controller.integration.spec.ts b/packages/cli-plugin-vitest/test/integrations/generate/generate.controller.integration.spec.ts new file mode 100644 index 000000000..9e7165adc --- /dev/null +++ b/packages/cli-plugin-vitest/test/integrations/generate/generate.controller.integration.spec.ts @@ -0,0 +1,75 @@ +import {GenerateCmd, TEMPLATE_DIR} from "@tsed/cli"; +import {CliService, ProjectPackageJson} from "@tsed/cli-core"; +import {CliPlatformTest, FakeCliFs} from "@tsed/cli-testing"; +import "../../../src"; + +describe("Generate Controller", () => { + beforeEach(() => + CliPlatformTest.bootstrap({ + templateDir: TEMPLATE_DIR, + commands: [GenerateCmd] + }) + ); + afterEach(() => CliPlatformTest.reset()); + + it("should generate the template with the right options (simple path)", async () => { + CliPlatformTest.setPackageJson({ + name: "", + version: "1.0.0", + description: "", + scripts: {}, + dependencies: {}, + devDependencies: {} + }); + + await CliPlatformTest.exec("generate", { + rootDir: "./project-data", + type: "controller", + name: "Test", + route: "/tests" + }); + + expect(FakeCliFs.getKeys()).toEqual([ + "project-name/src/controllers", + "project-name/src/controllers/TestController.integration.spec.ts", + "project-name/src/controllers/TestController.spec.ts", + "project-name/src/controllers/TestController.ts" + ]); + + const result = FakeCliFs.entries.get("project-name/src/controllers/TestController.integration.spec.ts"); + expect(result).toContain('import { PlatformTest } from "@tsed/common";'); + expect(result).toContain('import SuperTest from "supertest";'); + expect(result).toContain('import { Server } from "../Server";'); + expect(result).toContain('import { TestController } from "./TestController";'); + }); + it("should generate the template with the right options (complex path)", async () => { + CliPlatformTest.setPackageJson({ + name: "", + version: "1.0.0", + description: "", + scripts: {}, + dependencies: {}, + devDependencies: {} + }); + + await CliPlatformTest.exec("generate", { + rootDir: "./project-data", + type: "controller", + name: "users/User", + route: "/users" + }); + + expect(FakeCliFs.getKeys()).toEqual([ + "project-name/src/controllers/users", + "project-name/src/controllers/users/UserController.integration.spec.ts", + "project-name/src/controllers/users/UserController.spec.ts", + "project-name/src/controllers/users/UserController.ts" + ]); + + const result = FakeCliFs.entries.get("project-name/src/controllers/users/UserController.integration.spec.ts"); + expect(result).toContain('import { PlatformTest } from "@tsed/common";'); + expect(result).toContain('import SuperTest from "supertest";'); + expect(result).toContain('import { Server } from "../../Server";'); + expect(result).toContain('import { UserController } from "./UserController";'); + }); +}); diff --git a/packages/cli-plugin-vitest/tsconfig.esm.json b/packages/cli-plugin-vitest/tsconfig.esm.json new file mode 100644 index 000000000..a500944d9 --- /dev/null +++ b/packages/cli-plugin-vitest/tsconfig.esm.json @@ -0,0 +1,39 @@ +{ + "extends": "@tsed/typescript/tsconfig.node.json", + "compilerOptions": { + "baseUrl": ".", + "module": "ES2020", + "rootDir": "src", + "outDir": "./lib/esm", + "declaration": true, + "declarationDir": "./lib/types", + "composite": true, + "noEmit": false + }, + "include": [ + "src", + "src/**/*.json" + ], + "exclude": [ + "node_modules", + "test", + "lib", + "benchmark", + "coverage", + "spec", + "**/*.benchmark.ts", + "**/*.spec.ts", + "keys", + "jest.config.js", + "**/__mock__/**", + "webpack.config.js" + ], + "references": [ + { + "path": "../cli" + }, + { + "path": "../cli-core" + } + ] +} diff --git a/packages/cli-plugin-vitest/tsconfig.json b/packages/cli-plugin-vitest/tsconfig.json new file mode 100644 index 000000000..8f91fe8dc --- /dev/null +++ b/packages/cli-plugin-vitest/tsconfig.json @@ -0,0 +1,39 @@ +{ + "extends": "@tsed/typescript/tsconfig.node.json", + "compilerOptions": { + "baseUrl": ".", + "module": "commonjs", + "rootDir": "src", + "outDir": "./lib/cjs", + "declaration": true, + "declarationDir": "./lib/types", + "composite": true, + "noEmit": false + }, + "include": [ + "src", + "src/**/*.json" + ], + "exclude": [ + "node_modules", + "test", + "lib", + "benchmark", + "coverage", + "spec", + "**/*.benchmark.ts", + "**/*.spec.ts", + "keys", + "jest.config.js", + "**/__mock__/**", + "webpack.config.js" + ], + "references": [ + { + "path": "../cli" + }, + { + "path": "../cli-core" + } + ] +} diff --git a/packages/cli/src/commands/init/config/FeaturesPrompt.ts b/packages/cli/src/commands/init/config/FeaturesPrompt.ts index 0f1ce95ff..a42c11a89 100644 --- a/packages/cli/src/commands/init/config/FeaturesPrompt.ts +++ b/packages/cli/src/commands/init/config/FeaturesPrompt.ts @@ -45,6 +45,7 @@ export enum FeatureType { // TESTING TESTING = "testing", JEST = "jest", + VITEST = "vitest", MOCHA = "mocha", LINTER = "linter", ESLINT = "eslint", @@ -226,6 +227,12 @@ export const FeaturesMap: Record = { typeorm: "latest" } }, + [FeatureType.VITEST]: { + name: "Vitest", + devDependencies: { + "@tsed/cli-plugin-vitest": "{{cliVersion}}" + } + }, [FeatureType.JEST]: { name: "Jest", devDependencies: { @@ -251,37 +258,6 @@ export const FeaturesMap: Record = { [FeatureType.LINT_STAGED]: { name: "Lint on commit" }, - // [FeatureType.BABEL]: { - // name: "Babel", - // devDependencies: { - // // "@babel/cli": "latest", - // // "@babel/core": "latest", - // // "@babel/node": "latest", - // // "@babel/plugin-proposal-class-properties": "latest", - // // "@babel/plugin-proposal-decorators": "latest", - // // "@babel/preset-env": "latest", - // // "@babel/preset-typescript": "latest", - // // "babel-plugin-transform-typescript-metadata": "latest", - // // "babel-watch": "latest" - // } - // }, - // [FeatureType.WEBPACK]: { - // name: "Webpack", - // devDependencies: { - // // "@babel/cli": "latest", - // // "@babel/core": "latest", - // // "@babel/node": "latest", - // // "@babel/plugin-proposal-class-properties": "latest", - // // "@babel/plugin-proposal-decorators": "latest", - // // "@babel/preset-env": "latest", - // // "@babel/preset-typescript": "latest", - // // "babel-plugin-transform-typescript-metadata": "latest", - // // "babel-watch": "latest", - // // "babel-loader": "latest", - // // webpack: "latest", - // // "webpack-cli": "latest" - // } - // }, node: { name: "Node.js", checked: true @@ -352,7 +328,6 @@ export const FeaturesPrompt = (availableRuntimes: string[], availablePackageMana FeatureType.OIDC, FeatureType.TESTING, FeatureType.LINTER, - // FeatureType.BUNDLER, FeatureType.COMMANDS ] }, @@ -397,7 +372,7 @@ export const FeaturesPrompt = (availableRuntimes: string[], availablePackageMana type: "list", name: "featuresTesting", when: hasFeature(FeatureType.TESTING), - choices: [FeatureType.JEST, FeatureType.MOCHA] + choices: [FeatureType.VITEST, FeatureType.JEST, FeatureType.MOCHA] }, { message: "Choose linter tools framework", diff --git a/packages/cli/src/commands/init/prompts/getFeaturesPrompt.spec.ts b/packages/cli/src/commands/init/prompts/getFeaturesPrompt.spec.ts index dd2ec13f8..a2daca8d6 100644 --- a/packages/cli/src/commands/init/prompts/getFeaturesPrompt.spec.ts +++ b/packages/cli/src/commands/init/prompts/getFeaturesPrompt.spec.ts @@ -255,6 +255,13 @@ describe("getFeaturesPrompt", () => { }, Object { "choices": Array [ + Object { + "devDependencies": Object { + "@tsed/cli-plugin-vitest": "{{cliVersion}}", + }, + "name": "Vitest", + "value": "vitest", + }, Object { "devDependencies": Object { "@tsed/cli-plugin-jest": "{{cliVersion}}", diff --git a/tsconfig.json b/tsconfig.json index 348f35a89..f81154c53 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,6 +21,9 @@ { "path": "./packages/cli-plugin-jest" }, + { + "path": "./packages/cli-plugin-vitest" + }, { "path": "./packages/cli-plugin-mocha" }, diff --git a/yarn.lock b/yarn.lock index 53369b7b8..fa5dceacf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3239,7 +3239,7 @@ __metadata: languageName: node linkType: hard -"@tsed/cli-core@npm:5.0.3, @tsed/cli-core@workspace:packages/cli-core": +"@tsed/cli-core@npm:5.0.3, @tsed/cli-core@workspace:*, @tsed/cli-core@workspace:packages/cli-core": version: 0.0.0-use.local resolution: "@tsed/cli-core@workspace:packages/cli-core" dependencies: @@ -3513,6 +3513,22 @@ __metadata: languageName: unknown linkType: soft +"@tsed/cli-plugin-vitest@workspace:packages/cli-plugin-vitest": + version: 0.0.0-use.local + resolution: "@tsed/cli-plugin-vitest@workspace:packages/cli-plugin-vitest" + dependencies: + "@tsed/cli": "workspace:*" + "@tsed/cli-core": "workspace:*" + "@tsed/eslint": "workspace:*" + "@tsed/jest-config": "workspace:*" + "@tsed/typescript": "workspace:*" + cross-env: "npm:7.0.3" + eslint: "npm:8.22.0" + jest: "npm:29.5.0" + tslib: "npm:2.3.1" + languageName: unknown + linkType: soft + "@tsed/cli-root@workspace:.": version: 0.0.0-use.local resolution: "@tsed/cli-root@workspace:." @@ -3601,7 +3617,7 @@ __metadata: languageName: unknown linkType: soft -"@tsed/cli@npm:5.0.3, @tsed/cli@workspace:packages/cli": +"@tsed/cli@npm:5.0.3, @tsed/cli@workspace:*, @tsed/cli@workspace:packages/cli": version: 0.0.0-use.local resolution: "@tsed/cli@workspace:packages/cli" dependencies: @@ -3669,7 +3685,7 @@ __metadata: languageName: node linkType: hard -"@tsed/eslint@npm:5.0.3, @tsed/eslint@workspace:tools/eslint": +"@tsed/eslint@npm:5.0.3, @tsed/eslint@workspace:*, @tsed/eslint@workspace:tools/eslint": version: 0.0.0-use.local resolution: "@tsed/eslint@workspace:tools/eslint" dependencies: @@ -3679,7 +3695,7 @@ __metadata: languageName: unknown linkType: soft -"@tsed/jest-config@npm:5.0.3, @tsed/jest-config@workspace:tools/jest": +"@tsed/jest-config@npm:5.0.3, @tsed/jest-config@workspace:*, @tsed/jest-config@workspace:tools/jest": version: 0.0.0-use.local resolution: "@tsed/jest-config@workspace:tools/jest" dependencies: @@ -3799,7 +3815,7 @@ __metadata: languageName: node linkType: hard -"@tsed/typescript@npm:5.0.3, @tsed/typescript@workspace:tools/typescript": +"@tsed/typescript@npm:5.0.3, @tsed/typescript@workspace:*, @tsed/typescript@workspace:tools/typescript": version: 0.0.0-use.local resolution: "@tsed/typescript@workspace:tools/typescript" dependencies: