Skip to content

Commit 45ecf68

Browse files
committed
test: add snap test for sync vitePlugins() usage
1 parent c7002cd commit 45ecf68

6 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!doctype html>
2+
<html>
3+
<body>
4+
<script type="module">
5+
console.log('hello');
6+
</script>
7+
</body>
8+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function mySyncPlugin() {
2+
return {
3+
name: 'my-sync-plugin',
4+
transformIndexHtml(html: string) {
5+
return html.replace('</body>', '<!-- sync-plugin-injected --></body>');
6+
},
7+
};
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "vite-plugins-sync-test",
3+
"private": true
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
> # Test that plugins loaded via sync vitePlugins() are applied during build
2+
> vp build
3+
> cat dist/index.html | grep 'sync-plugin-injected'
4+
<!-- sync-plugin-injected --></body>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"commands": [
3+
"# Test that plugins loaded via sync vitePlugins() are applied during build",
4+
{
5+
"command": "vp build",
6+
"ignoreOutput": true
7+
},
8+
"cat dist/index.html | grep 'sync-plugin-injected'"
9+
]
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig, vitePlugins } from 'vite-plus';
2+
import mySyncPlugin from './my-plugin';
3+
4+
export default defineConfig({
5+
plugins: vitePlugins(() => [mySyncPlugin()]),
6+
});

0 commit comments

Comments
 (0)