Skip to content

Commit

Permalink
test: add test for 3.3 type imports
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 19, 2023
1 parent 56e8db7 commit e48bbfa
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 4 deletions.
6 changes: 3 additions & 3 deletions example/webpack.config.js
Expand Up @@ -3,8 +3,6 @@ const webpack = require('webpack')
const VueLoaderPlugin = require('../dist/plugin').default
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

console.log(webpack.version)

module.exports = (env = {}) => {
const isProd = env.prod
const isSSR = env.ssr
Expand Down Expand Up @@ -83,7 +81,9 @@ module.exports = (env = {}) => {
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
loader: process.env.WEBPACK4
? require.resolve('ts-loader')
: require.resolve('ts-loader-v9'),
options: {
transpileOnly: true,
appendTsSuffixTo: [/\.vue$/],
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/entry.js
Expand Up @@ -9,7 +9,9 @@ if (typeof window !== 'undefined') {

const app = createApp(Component)
const container = window.document.createElement('div')
container.id = 'app'
window.instance = app.mount(container)
window.document.body.appendChild(container)
}

export default Component
3 changes: 3 additions & 0 deletions test/fixtures/imported-types-aliased.ts
@@ -0,0 +1,3 @@
export interface Props {
id?: number
}
3 changes: 3 additions & 0 deletions test/fixtures/imported-types.ts
@@ -0,0 +1,3 @@
export interface Props {
msg: string
}
10 changes: 10 additions & 0 deletions test/fixtures/imported-types.vue
@@ -0,0 +1,10 @@
<script setup lang="ts">
import type { Props } from './imported-types'
import type { Props as P } from 'foo'
const props = defineProps<Props & P>()
</script>

<template>
{{ Object.keys(props) }}
</template>
8 changes: 8 additions & 0 deletions test/fixtures/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"paths": {
"foo": ["./imported-types-aliased.ts"]
}
},
"include": ["."]
}
18 changes: 18 additions & 0 deletions test/script.spec.ts
Expand Up @@ -19,3 +19,21 @@ test('should handle custom resource query', async () => {

expect(exports.default.data().msg).toBe('Hello from Component A!')
})

test('should support importing external types', async () => {
const { exports, window } = await mockBundleAndRun({
entry: 'imported-types.vue',
})
expect(exports.default).toMatchObject({
props: {
msg: {
type: window.String,
required: true,
},
id: {
type: window.Number,
required: false,
},
},
})
})
15 changes: 14 additions & 1 deletion test/utils.ts
Expand Up @@ -17,6 +17,9 @@ const baseConfig: webpack.Configuration = {
filename: 'test.build.js',
publicPath: '',
},
resolve: {
extensions: ['.js', '.ts'],
},
resolveLoader: {
alias: {
'vue-loader': require.resolve('../dist'),
Expand All @@ -28,6 +31,16 @@ const baseConfig: webpack.Configuration = {
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.ts$/,
loader: process.env.WEBPACK4
? require.resolve('ts-loader')
: require.resolve('ts-loader-v9'),
options: {
transpileOnly: true,
appendTsSuffixTo: [/\.vue$/],
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
Expand Down Expand Up @@ -129,7 +142,7 @@ export async function mockBundleAndRun(
const { code, stats } = await bundle(options, wontThrowError)

const dom = new JSDOM(
`<!DOCTYPE html><html><head></head><body><div id="#app"></div></body></html>`,
`<!DOCTYPE html><html><head></head><body></body></html>`,
{
runScripts: 'outside-only',
virtualConsole: new VirtualConsole(),
Expand Down

0 comments on commit e48bbfa

Please sign in to comment.