Skip to content

Commit 0939767

Browse files
yyx990803freddy38510
authored andcommitted
test: fix edgeCase test case
1 parent 477912c commit 0939767

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

test/edgeCases.spec.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from 'path'
2-
import webpack = require('webpack')
2+
import webpack from 'webpack'
33
import { mfs, bundle, mockBundleAndRun, normalizeNewline } from './utils'
44

55
// @ts-ignore
@@ -30,8 +30,11 @@ function assertComponent({
3030
test('vue rule with include', async () => {
3131
const result = await mockBundleAndRun({
3232
entry: 'basic.vue',
33-
modify: (config) => {
34-
config!.module!.rules[0] = {
33+
modify: (config: any) => {
34+
const i = config.module.rules.findIndex((r) =>
35+
r.test.toString().includes('vue')
36+
)
37+
config.module.rules[i] = {
3538
test: /\.vue$/,
3639
include: /fixtures/,
3740
loader: '@freddy38510/vue-loader',
@@ -70,8 +73,11 @@ test('test-less oneOf rules', async () => {
7073
test('normalize multiple use + options', async () => {
7174
await bundle({
7275
entry: 'basic.vue',
73-
modify: (config) => {
74-
config!.module!.rules[0] = {
76+
modify: (config: any) => {
77+
const i = config.module.rules.findIndex((r) =>
78+
r.test.toString().includes('vue')
79+
)
80+
config!.module!.rules[i] = {
7581
test: /\.vue$/,
7682
use: [
7783
{
@@ -88,7 +94,10 @@ test('should not duplicate css modules value imports', async () => {
8894
const { window, exports } = await mockBundleAndRun({
8995
entry: './test/fixtures/duplicate-cssm.js',
9096
modify: (config: any) => {
91-
config!.module!.rules[1] = {
97+
const i = config.module.rules.findIndex((r) =>
98+
r.test.toString().includes('css')
99+
)
100+
config.module.rules[i] = {
92101
test: /\.css$/,
93102
use: [
94103
'style-loader',
@@ -136,8 +145,11 @@ test('html-webpack-plugin', async () => {
136145
test('usage with null-loader', async () => {
137146
await mockBundleAndRun({
138147
entry: 'basic.vue',
139-
modify: (config) => {
140-
config!.module!.rules[1] = {
148+
modify: (config: any) => {
149+
const i = config.module.rules.findIndex((r) =>
150+
r.test.toString().includes('css')
151+
)
152+
config.module.rules[i] = {
141153
test: /\.css$/,
142154
use: ['null-loader'],
143155
}

test/utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const baseConfig: webpack.Configuration = {
3131
test: /\.vue$/,
3232
loader: '@freddy38510/vue-loader',
3333
},
34+
{
35+
test: /\.css$/,
36+
use: ['style-loader', 'css-loader'],
37+
},
3438
{
3539
test: /\.ts$/,
3640
loader: process.env.WEBPACK4
@@ -41,10 +45,6 @@ const baseConfig: webpack.Configuration = {
4145
appendTsSuffixTo: [/\.vue$/],
4246
},
4347
},
44-
{
45-
test: /\.css$/,
46-
use: ['style-loader', 'css-loader'],
47-
},
4848
],
4949
},
5050
plugins: [

0 commit comments

Comments
 (0)