-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
79 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
`<script lang="ts">${scriptContent}</script>` | ||
) | ||
expect(tsOpenTag).toEqual('<script lang="ts">') | ||
expect(tsContent).toEqual(scriptContent) | ||
|
||
scriptRE.lastIndex = 0 | ||
const [, openTag, , content] = scriptRE.exec( | ||
`<script>${scriptContent}</script>` | ||
) | ||
expect(openTag).toEqual('<script>') | ||
expect(content).toEqual(scriptContent) | ||
}) | ||
|
||
test('include comments test', () => { | ||
scriptRE.lastIndex = 0 | ||
const ret = scriptRE.exec( | ||
`<template> | ||
<!-- <script >var test = null</script> --> | ||
</template>`.replace(commentRE, '') | ||
) | ||
expect(ret).toEqual(null) | ||
}) | ||
|
||
test('components with script keyword test', () => { | ||
scriptRE.lastIndex = 0 | ||
let ret = scriptRE.exec(`<template><script-develop-pane/></template>`) | ||
expect(ret).toBe(null) | ||
|
||
scriptRE.lastIndex = 0 | ||
ret = scriptRE.exec( | ||
`<template><script-develop-pane></script-develop-pane></template>` | ||
) | ||
expect(ret).toBe(null) | ||
|
||
scriptRE.lastIndex = 0 | ||
ret = scriptRE.exec( | ||
`<template><script-develop-pane > content </script-develop-pane></template>` | ||
) | ||
expect(ret).toBe(null) | ||
}) | ||
|
||
test('ordinary script tag test', () => { | ||
scriptRE.lastIndex = 0 | ||
const [, tag, , content] = scriptRE.exec( | ||
`<script >var test = null</script>` | ||
) | ||
expect(tag).toEqual('<script >') | ||
expect(content).toEqual('var test = null') | ||
|
||
scriptRE.lastIndex = 0 | ||
const [, tag1, , content1] = scriptRE.exec( | ||
`<script>var test = null</script>` | ||
) | ||
expect(tag1).toEqual('<script>') | ||
expect(content1).toEqual('var test = null') | ||
}) | ||
}) |
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