Skip to content

Commit

Permalink
feat(vite-ssr-plugin): add @Vite decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Apr 22, 2023
1 parent 6f4106b commit 582ff60
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/third-parties/vite-ssr-plugin/src/decorators/vite.spec.ts
@@ -0,0 +1,31 @@
import {Controller} from "@tsed/common";
import {Store} from "@tsed/core";

import {Vite} from "./vite";

@Controller("/")
class ControllerTest {
@Vite()
post() {
return;
}

@Vite("nice-view")
postWithView() {
return;
}
}

describe("ViteDecorator", () => {
it("should return attached View with *.vite with empty path", async () => {
const metadata = Store.fromMethod(ControllerTest, "post").get("view");

expect(metadata.path).toEqual("*.vite");
});

it("should return attached View with {path}.vite", async () => {
const metadata = Store.fromMethod(ControllerTest, "postWithView").get("view");

expect(metadata.path).toEqual("nice-view.vite");
});
});
5 changes: 5 additions & 0 deletions packages/third-parties/vite-ssr-plugin/src/decorators/vite.ts
@@ -0,0 +1,5 @@
import {View} from "@tsed/schema";

export function Vite(path?: string) {
return View(`${path || "*"}.vite`);
}
1 change: 1 addition & 0 deletions packages/third-parties/vite-ssr-plugin/src/index.ts
Expand Up @@ -3,6 +3,7 @@
*/

export * from "./ViteModule";
export * from "./decorators/vite";
export * from "./interfaces/ViteConfig";
export * from "./interfaces/ViteRenderContext";
export * from "./interfaces/interfaces";
Expand Down

0 comments on commit 582ff60

Please sign in to comment.