-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { describe, it, expect } from "bun:test"; | ||
import { prerenderPluginTransformation } from "prerender-macro"; | ||
|
||
export const toInline = (s: string) => s.replace(/\s*\n\s*/g, ""); | ||
export const normalizeQuotes = (s: string) => toInline(s).replaceAll("'", '"'); | ||
|
||
describe("Brisa", () => { | ||
describe("plugin", () => { | ||
it('should not transform if there is not an import attribute with type "prerender"', () => { | ||
const input = ` | ||
import StaticComponent from "@/components/static"; | ||
import DynamicComponent from "@/components/dynamic"; | ||
export default function Test() { | ||
return ( | ||
<div> | ||
<StaticComponent /> | ||
<DynamicComponent /> | ||
</div> | ||
); | ||
} | ||
`; | ||
const output = normalizeQuotes(prerenderPluginTransformation(input)); | ||
const expected = normalizeQuotes(input); | ||
|
||
expect(output).toBe(expected); | ||
}); | ||
it("should transform a static component without props", () => { | ||
const input = ` | ||
import StaticComponent from "@/components/static" with { type: "prerender" }; | ||
import DynamicComponent from "@/components/dynamic"; | ||
export default function Test() { | ||
return ( | ||
<div> | ||
<StaticComponent /> | ||
<DynamicComponent /> | ||
</div> | ||
); | ||
} | ||
`; | ||
const output = normalizeQuotes(prerenderPluginTransformation(input)); | ||
const expected = normalizeQuotes(` | ||
import { prerender as __prerender_macro } from "prerender-macro/prerender" with { "type": "macro" }; | ||
import StaticComponent from "@/components/static" with { type: "prerender" }; | ||
import DynamicComponent from "@/components/dynamic"; | ||
export default function Test() { | ||
return ( | ||
<div> | ||
{__prerender_macro({ componentPath: "@/components/static", componentModuleName: "default", componentProps: {} })} | ||
<DynamicComponent /> | ||
</div> | ||
); | ||
} | ||
`); | ||
|
||
expect(output).toBe(expected); | ||
Check failure on line 58 in tests/brisa/plugin.test.tsx
|
||
}); | ||
}); | ||
}); |