Skip to content

Commit 6b486a9

Browse files
committed
test: fix some type checking errors and warnings
1 parent cc3d39c commit 6b486a9

File tree

7 files changed

+27
-30
lines changed

7 files changed

+27
-30
lines changed

test/advanced.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test('support chaining with other loaders', async () => {
88
const { componentModule } = await mockBundleAndRun({
99
entry: 'basic.vue',
1010
modify: (config) => {
11-
config!.module!.rules[0] = {
11+
config.module!.rules![0] = {
1212
test: /\.vue$/,
1313
use: ['@freddy38510/vue-loader', require.resolve('./mock-loaders/js')],
1414
}
@@ -22,7 +22,7 @@ test.skip('inherit queries on files', async () => {
2222
const { componentModule } = await mockBundleAndRun({
2323
entry: 'basic.vue?change',
2424
modify: (config) => {
25-
config!.module!.rules[0] = {
25+
config.module!.rules![0] = {
2626
test: /\.vue$/,
2727
use: [
2828
'@freddy38510/vue-loader',

test/edgeCases.spec.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ test('vue rule with include', async () => {
3131
const result = await mockBundleAndRun({
3232
entry: 'basic.vue',
3333
modify: (config: any) => {
34-
const i = config.module.rules.findIndex((r) =>
35-
r.test.toString().includes('vue')
34+
const i = (config.module.rules as webpack.RuleSetRule[]).findIndex((r) =>
35+
r.test?.toString().includes('vue')
3636
)
3737
config.module.rules[i] = {
3838
test: /\.vue$/,
@@ -74,10 +74,10 @@ test('normalize multiple use + options', async () => {
7474
await bundle({
7575
entry: 'basic.vue',
7676
modify: (config: any) => {
77-
const i = config.module.rules.findIndex((r) =>
78-
r.test.toString().includes('vue')
77+
const i = (config.module.rules as webpack.RuleSetRule[]).findIndex((r) =>
78+
r.test?.toString().includes('vue')
7979
)
80-
config!.module!.rules[i] = {
80+
config.module.rules[i] = {
8181
test: /\.vue$/,
8282
use: [
8383
{
@@ -91,11 +91,11 @@ test('normalize multiple use + options', async () => {
9191
})
9292

9393
test('should not duplicate css modules value imports', async () => {
94-
const { window, exports } = await mockBundleAndRun({
94+
const { window, _exports } = await mockBundleAndRun({
9595
entry: './test/fixtures/duplicate-cssm.js',
9696
modify: (config: any) => {
97-
const i = config.module.rules.findIndex((r) =>
98-
r.test.toString().includes('css')
97+
const i = (config.module.rules as webpack.RuleSetRule[]).findIndex((r) =>
98+
r.test?.toString().includes('css')
9999
)
100100
config.module.rules[i] = {
101101
test: /\.css$/,
@@ -117,8 +117,8 @@ test('should not duplicate css modules value imports', async () => {
117117
const style = normalizeNewline(styles[1]!.textContent!)
118118
// value should be injected
119119
expect(style).toMatch('color: red;')
120-
// exports is set as the locals imported from values.css
121-
expect(exports.color).toBe('red')
120+
// _exports is set as the locals imported from values.css
121+
expect(_exports.color).toBe('red')
122122
})
123123

124124
// #1213
@@ -146,8 +146,8 @@ test('usage with null-loader', async () => {
146146
await mockBundleAndRun({
147147
entry: 'basic.vue',
148148
modify: (config: any) => {
149-
const i = config.module.rules.findIndex((r) =>
150-
r.test.toString().includes('css')
149+
const i = (config.module.rules as webpack.RuleSetRule[]).findIndex((r) =>
150+
r.test?.toString().includes('css')
151151
)
152152
config.module.rules[i] = {
153153
test: /\.css$/,

test/fixtures/entry.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { createApp } from 'vue'
22

33
import Component from '~target'
4-
import * as exports from '~target'
4+
import * as _exports from '~target'
55

66
if (typeof window !== 'undefined') {
77
window.componentModule = Component
8-
window.exports = exports
8+
window.exports = _exports
99

1010
const app = createApp(Component)
1111
const container = window.document.createElement('div')

test/fixtures/i18n-entry.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createApp } from 'vue'
22
import { createI18n } from 'vue-i18n'
33

44
import Component from './i18n.vue'
5-
import * as exports from './i18n.vue'
5+
import * as _exports from './i18n.vue'
66

77
const i18n = createI18n({
88
locale: 'de',
@@ -12,7 +12,7 @@ const i18n = createI18n({
1212

1313
if (typeof window !== 'undefined') {
1414
window.componentModule = Component
15-
window.exports = exports
15+
window.exports = _exports
1616

1717
const app = createApp(Component).use(i18n)
1818

test/fixtures/postcss.vue

-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ h1
77
color: red
88
font-size: 14px
99
</style>
10-
<script>
11-
export default {}
12-
</script>

test/script.spec.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import { mockBundleAndRun } from './utils'
22

33
test('named exports', async () => {
4-
const { exports } = await mockBundleAndRun({
4+
const { _exports } = await mockBundleAndRun({
55
entry: 'named-exports.vue',
66
})
7-
expect(exports.default.name).toBe('named-exports')
8-
expect(exports.foo()).toBe(1)
7+
expect(_exports.default.name).toBe('named-exports')
8+
expect(_exports.foo()).toBe(1)
99
})
1010

1111
test('experimental <script setup>', async () => {
1212
await mockBundleAndRun({ entry: 'ScriptSetup.vue' })
1313
})
1414

1515
test('should handle custom resource query', async () => {
16-
const { exports } = await mockBundleAndRun({
16+
const { _exports } = await mockBundleAndRun({
1717
entry: 'custom-query.vue',
1818
})
1919

20-
expect(exports.default.data().msg).toBe('Hello from Component A!')
20+
expect(_exports.default.data().msg).toBe('Hello from Component A!')
2121
})
2222

2323
test('should support importing external types', async () => {
24-
const { exports, window } = await mockBundleAndRun({
24+
const { _exports, window } = await mockBundleAndRun({
2525
entry: 'imported-types.vue',
2626
})
27-
expect(exports.default).toMatchObject({
27+
expect(_exports.default).toMatchObject({
2828
props: {
2929
msg: {
3030
type: window.String,

test/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ export async function mockBundleAndRun(
156156
}
157157

158158
const { window } = dom
159-
const { componentModule, exports, instance } = window
159+
const { componentModule, exports: _exports, instance } = window
160160

161161
return {
162162
window,
163163

164164
componentModule,
165-
exports,
165+
_exports,
166166
instance,
167167

168168
code,

0 commit comments

Comments
 (0)