Skip to content

Commit 0fbac11

Browse files
test: more
1 parent 5be3086 commit 0fbac11

File tree

3 files changed

+39
-34
lines changed

3 files changed

+39
-34
lines changed

test/__snapshots__/loader.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ Array [
147147
148148
.class {
149149
color: red;
150-
background: url(/webpack/public/path/de52feff0a80fb98abe3.png);
150+
background: url(/webpack/public/path/img.png);
151151
}
152152
153153
.class-duplicate-url {
154-
background: url(/webpack/public/path/de52feff0a80fb98abe3.png);
154+
background: url(/webpack/public/path/img.png);
155155
}
156156
157157
:root {

test/fixtures/source-map/basic.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "./nested/nested";
1+
@import "./nested/nested.scss";
22

33
$font-stack: Helvetica, sans-serif;
44
$primary-color: #333;

test/loader.test.js

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,38 +52,43 @@ describe('loader', () => {
5252

5353
it('should work with "asset" module type', async () => {
5454
const isWebpack5 = version[0] === '5';
55+
const config = {
56+
module: {
57+
rules: [
58+
{
59+
test: /\.css$/i,
60+
use: [
61+
{
62+
loader: path.resolve(__dirname, '../src'),
63+
},
64+
],
65+
},
66+
isWebpack5
67+
? {
68+
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i,
69+
type: 'asset',
70+
}
71+
: {
72+
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i,
73+
loader: 'file-loader',
74+
options: { name: '[name].[ext]' },
75+
},
76+
],
77+
},
78+
};
5579

56-
const compiler = getCompiler(
57-
'./basic.js',
58-
{},
59-
{
60-
module: {
61-
rules: [
62-
{
63-
test: /\.css$/i,
64-
use: [
65-
{
66-
loader: path.resolve(__dirname, '../src'),
67-
},
68-
],
69-
},
70-
isWebpack5
71-
? {
72-
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i,
73-
type: 'asset',
74-
}
75-
: {
76-
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i,
77-
loader: 'file-loader',
78-
options: { name: '[hash].[ext]' },
79-
},
80-
],
81-
},
82-
experiments: {
83-
asset: true,
84-
},
85-
}
86-
);
80+
if (isWebpack5) {
81+
config.experiments = { asset: true };
82+
config.output = {
83+
path: path.resolve(__dirname, 'outputs'),
84+
filename: '[name].bundle.js',
85+
chunkFilename: '[name].chunk.js',
86+
publicPath: '/webpack/public/path/',
87+
assetModuleFilename: '[name][ext]',
88+
};
89+
}
90+
91+
const compiler = getCompiler('./basic.js', {}, config);
8792
const stats = await compile(compiler);
8893

8994
expect(getModuleSource('./basic.css', stats)).toMatchSnapshot('module');

0 commit comments

Comments
 (0)