diff --git a/packages/vite/src/node/__tests__/scan.spec.ts b/packages/vite/src/node/__tests__/scan.spec.ts
new file mode 100644
index 00000000000000..d99a6fb501ad28
--- /dev/null
+++ b/packages/vite/src/node/__tests__/scan.spec.ts
@@ -0,0 +1,70 @@
+import { scriptRE, commentRE } from '../optimizer/scan'
+describe('optimizer-scan:script-test', () => {
+ const scriptContent = `import { defineComponent } from 'vue'
+ import ScriptDevelopPane from './ScriptDevelopPane.vue';
+ export default defineComponent({
+ components: {
+ ScriptDevelopPane
+ }
+ })`
+
+ test('component return value test', () => {
+ scriptRE.lastIndex = 0
+ const [, tsOpenTag, , tsContent] = scriptRE.exec(
+ ``
+ )
+ expect(tsOpenTag).toEqual('`
+ )
+ expect(openTag).toEqual(' -->
+ `.replace(commentRE, '')
+ )
+ expect(ret).toEqual(null)
+ })
+
+ test('components with script keyword test', () => {
+ scriptRE.lastIndex = 0
+ let ret = scriptRE.exec(``)
+ expect(ret).toBe(null)
+
+ scriptRE.lastIndex = 0
+ ret = scriptRE.exec(
+ ``
+ )
+ expect(ret).toBe(null)
+
+ scriptRE.lastIndex = 0
+ ret = scriptRE.exec(
+ ` content `
+ )
+ expect(ret).toBe(null)
+ })
+
+ test('ordinary script tag test', () => {
+ scriptRE.lastIndex = 0
+ const [, tag, , content] = scriptRE.exec(
+ ``
+ )
+ expect(tag).toEqual('`
+ )
+ expect(tag1).toEqual('