Skip to content

Commit

Permalink
test: more
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 16, 2019
1 parent 5be3086 commit 0fbac11
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
4 changes: 2 additions & 2 deletions test/__snapshots__/loader.test.js.snap
Expand Up @@ -147,11 +147,11 @@ Array [
.class {
color: red;
background: url(/webpack/public/path/de52feff0a80fb98abe3.png);
background: url(/webpack/public/path/img.png);
}
.class-duplicate-url {
background: url(/webpack/public/path/de52feff0a80fb98abe3.png);
background: url(/webpack/public/path/img.png);
}
:root {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/source-map/basic.scss
@@ -1,4 +1,4 @@
@import "./nested/nested";
@import "./nested/nested.scss";

$font-stack: Helvetica, sans-serif;
$primary-color: #333;
Expand Down
67 changes: 36 additions & 31 deletions test/loader.test.js
Expand Up @@ -52,38 +52,43 @@ describe('loader', () => {

it('should work with "asset" module type', async () => {
const isWebpack5 = version[0] === '5';
const config = {
module: {
rules: [
{
test: /\.css$/i,
use: [
{
loader: path.resolve(__dirname, '../src'),
},
],
},
isWebpack5
? {
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i,
type: 'asset',
}
: {
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i,
loader: 'file-loader',
options: { name: '[name].[ext]' },
},
],
},
};

const compiler = getCompiler(
'./basic.js',
{},
{
module: {
rules: [
{
test: /\.css$/i,
use: [
{
loader: path.resolve(__dirname, '../src'),
},
],
},
isWebpack5
? {
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i,
type: 'asset',
}
: {
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i,
loader: 'file-loader',
options: { name: '[hash].[ext]' },
},
],
},
experiments: {
asset: true,
},
}
);
if (isWebpack5) {
config.experiments = { asset: true };
config.output = {
path: path.resolve(__dirname, 'outputs'),
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js',
publicPath: '/webpack/public/path/',
assetModuleFilename: '[name][ext]',
};
}

const compiler = getCompiler('./basic.js', {}, config);
const stats = await compile(compiler);

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

0 comments on commit 0fbac11

Please sign in to comment.