Skip to content

Commit

Permalink
Bugfix: jpeg extension
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuaz committed Apr 22, 2021
1 parent 8e0602f commit ec12580
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from "path"
import type { Options, MimeType, LoaderContext, ImageOptions, CacheOptions } from "./types"
const version = "3"

enum MIMES {
jpg = "image/jpeg",
jpeg = "image/jpeg",
Expand Down Expand Up @@ -52,6 +53,7 @@ function parseOptions(loaderContext: LoaderContext, options: Options): ParsedOpt
ext = path.extname(loaderContext.resourcePath).replace(/\./, "")
switch (ext) {
case "jpg":
case "jpeg":
case "png":
case "webp":
case "avif":
Expand Down
17 changes: 0 additions & 17 deletions test/cache/build/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`disable 1`] = `
Object {
"default": Object {
"images": Array [
Object {
"height": 100,
"path": "foobar/d65e7eabf402c163ee9e87493c5b07af-100.jpg",
"width": 100,
},
],
"src": "foobar/d65e7eabf402c163ee9e87493c5b07af-100.jpg",
"srcSet": "foobar/d65e7eabf402c163ee9e87493c5b07af-100.jpg",
"toString": [Function],
},
}
`;

exports[`jpg to webp 1`] = `
Object {
"default": Object {
Expand Down
5 changes: 0 additions & 5 deletions test/cache/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ test("with size defined in webpack.config.js", () => {
expect(multi).toMatchSnapshot()
})

test("disable", () => {
const multi = require("../cat-1000.jpg?disable")
expect(multi).toMatchSnapshot()
})

test("output should be relative to context", () => {
const multi = require("../cat-1000.jpg?name=[path][hash]-[width]x[height].[ext]&context=./")
expect(multi).toMatchSnapshot()
Expand Down
Binary file added test/cat-1000copy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/sharp/build/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ Object {
}
`;

exports[`jpeg extension 1`] = `
Object {
"default": Object {
"height": 395,
"images": Array [
Object {
"height": 395,
"path": "foobar/f32ecdef2ffef2786a6499ee57bfe2d1-439.jpeg",
"width": 439,
},
],
"src": "foobar/f32ecdef2ffef2786a6499ee57bfe2d1-439.jpeg",
"srcSet": "foobar/f32ecdef2ffef2786a6499ee57bfe2d1-439.jpeg 439w",
"toString": [Function],
"width": 439,
},
}
`;

exports[`jpg to webp 1`] = `
Object {
"default": Object {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions test/sharp/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
test("jpeg extension", () => {
const output = require("../cat-1000copy.jpeg?size=439")
expect(output).toMatchSnapshot()
})

test("png to avif", () => {
const output = require("../cat-transparent.png?format=avif&size=777")
expect(output).toMatchSnapshot()
Expand Down
6 changes: 3 additions & 3 deletions test/sharp/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require("path");
const path = require("path")

module.exports = {
mode: "development",
Expand All @@ -18,7 +18,7 @@ module.exports = {
},
},
{
test: /\.(png|jpg)$/,
test: /\.(png|jpe?g)$/,
loader: require.resolve("../../lib/index"),
options: {
sizes: [500, 750, 1000],
Expand All @@ -34,4 +34,4 @@ module.exports = {
filename: "test.js",
},
target: "node",
};
}

0 comments on commit ec12580

Please sign in to comment.