Skip to content

Commit e48bbfa

Browse files
committed
test: add test for 3.3 type imports
1 parent 56e8db7 commit e48bbfa

8 files changed

+61
-4
lines changed

Diff for: example/webpack.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const webpack = require('webpack')
33
const VueLoaderPlugin = require('../dist/plugin').default
44
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
55

6-
console.log(webpack.version)
7-
86
module.exports = (env = {}) => {
97
const isProd = env.prod
108
const isSSR = env.ssr
@@ -83,7 +81,9 @@ module.exports = (env = {}) => {
8381
test: /\.ts$/,
8482
use: [
8583
{
86-
loader: 'ts-loader',
84+
loader: process.env.WEBPACK4
85+
? require.resolve('ts-loader')
86+
: require.resolve('ts-loader-v9'),
8787
options: {
8888
transpileOnly: true,
8989
appendTsSuffixTo: [/\.vue$/],

Diff for: test/fixtures/entry.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ if (typeof window !== 'undefined') {
99

1010
const app = createApp(Component)
1111
const container = window.document.createElement('div')
12+
container.id = 'app'
1213
window.instance = app.mount(container)
14+
window.document.body.appendChild(container)
1315
}
1416

1517
export default Component

Diff for: test/fixtures/imported-types-aliased.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface Props {
2+
id?: number
3+
}

Diff for: test/fixtures/imported-types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface Props {
2+
msg: string
3+
}

Diff for: test/fixtures/imported-types.vue

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
import type { Props } from './imported-types'
3+
import type { Props as P } from 'foo'
4+
5+
const props = defineProps<Props & P>()
6+
</script>
7+
8+
<template>
9+
{{ Object.keys(props) }}
10+
</template>

Diff for: test/fixtures/tsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"paths": {
4+
"foo": ["./imported-types-aliased.ts"]
5+
}
6+
},
7+
"include": ["."]
8+
}

Diff for: test/script.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,21 @@ test('should handle custom resource query', async () => {
1919

2020
expect(exports.default.data().msg).toBe('Hello from Component A!')
2121
})
22+
23+
test('should support importing external types', async () => {
24+
const { exports, window } = await mockBundleAndRun({
25+
entry: 'imported-types.vue',
26+
})
27+
expect(exports.default).toMatchObject({
28+
props: {
29+
msg: {
30+
type: window.String,
31+
required: true,
32+
},
33+
id: {
34+
type: window.Number,
35+
required: false,
36+
},
37+
},
38+
})
39+
})

Diff for: test/utils.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const baseConfig: webpack.Configuration = {
1717
filename: 'test.build.js',
1818
publicPath: '',
1919
},
20+
resolve: {
21+
extensions: ['.js', '.ts'],
22+
},
2023
resolveLoader: {
2124
alias: {
2225
'vue-loader': require.resolve('../dist'),
@@ -28,6 +31,16 @@ const baseConfig: webpack.Configuration = {
2831
test: /\.vue$/,
2932
loader: 'vue-loader',
3033
},
34+
{
35+
test: /\.ts$/,
36+
loader: process.env.WEBPACK4
37+
? require.resolve('ts-loader')
38+
: require.resolve('ts-loader-v9'),
39+
options: {
40+
transpileOnly: true,
41+
appendTsSuffixTo: [/\.vue$/],
42+
},
43+
},
3144
{
3245
test: /\.css$/,
3346
use: ['style-loader', 'css-loader'],
@@ -129,7 +142,7 @@ export async function mockBundleAndRun(
129142
const { code, stats } = await bundle(options, wontThrowError)
130143

131144
const dom = new JSDOM(
132-
`<!DOCTYPE html><html><head></head><body><div id="#app"></div></body></html>`,
145+
`<!DOCTYPE html><html><head></head><body></body></html>`,
133146
{
134147
runScripts: 'outside-only',
135148
virtualConsole: new VirtualConsole(),

0 commit comments

Comments
 (0)