Skip to content

Commit

Permalink
test: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jul 26, 2024
1 parent 3878f9e commit b09f1a3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 96 deletions.
3 changes: 1 addition & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ module.exports = (api) => {
[
"@babel/preset-env",
{
exclude:
process.env.NODE_ENV === "test" ? [] : ["proposal-dynamic-import"],
exclude: ["proposal-dynamic-import"],
targets: {
node: "18.12.0",
},
Expand Down
76 changes: 0 additions & 76 deletions globalSetup.js

This file was deleted.

12 changes: 0 additions & 12 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,5 @@

module.exports = {
testEnvironment: "node",
moduleNameMapper: {
"^imagemin$": "<rootDir>/test/bundled/imagemin/index.js",
"^imagemin-svgo$": "<rootDir>/test/bundled/imagemin-svgo/index.js",
"^node:buffer$": "<rootDir>/test/helpers/built-in-modules/buffer.js",
"^node:fs$": "<rootDir>/test/helpers/built-in-modules/fs.js",
"^node:util$": "<rootDir>/test/helpers/built-in-modules/util.js",
"^node:path$": "<rootDir>/test/helpers/built-in-modules/path.js",
"^node:stream$": "<rootDir>/test/helpers/built-in-modules/stream.js",
"^node:url$": "<rootDir>/test/helpers/built-in-modules/url.js",
"^node:process$": "<rootDir>/test/helpers/built-in-modules/url.js",
},
collectCoverageFrom: ["src/**/*.{js,mjs,jsx}"],
globalSetup: "<rootDir>/globalSetup.js",
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"fix:js": "npm run lint:js -- --fix",
"fix:prettier": "npm run lint:prettier -- --write",
"fix": "npm-run-all -l fix:js fix:prettier",
"test:only": "cross-env NODE_ENV=test jest --runInBand",
"test:only": "cross-env NODE_ENV=test node --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand",
"test:watch": "npm run test:only -- --watch",
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
"pretest": "npm run lint",
Expand Down
7 changes: 4 additions & 3 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import fs from "fs";
import path from "path";

import imagemin from "imagemin";
import imageminGifsicle from "imagemin-gifsicle";
import imageminMozjpeg from "imagemin-mozjpeg";
import imageminPngquant from "imagemin-pngquant";
import imageminSvgo from "imagemin-svgo";
import pify from "pify";
import tempy from "tempy";
import webpack from "webpack";
Expand Down Expand Up @@ -244,7 +242,7 @@ function runWebpack(maybeOptions, getCompiler = false) {
return pify(webpack)(configs.length === 1 ? configs[0] : configs);
}

function isOptimized(originalPath, compilation) {
async function isOptimized(originalPath, compilation) {
const { assets } = compilation;
let name = originalPath;
let realName = originalPath;
Expand All @@ -263,6 +261,9 @@ function isOptimized(originalPath, compilation) {
const pathToOriginal = path.join(fixturesPath, realName);
const pathToEmitted = path.join(outputPath, name);

const imagemin = (await import("imagemin")).default;
const imageminSvgo = (await import("imagemin-svgo")).default;

return Promise.resolve()
.then(() => pify(fs.readFile)(pathToOriginal))
.then((data) =>
Expand Down
10 changes: 8 additions & 2 deletions test/worker.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import fs from "fs";
import path from "path";

import imagemin from "imagemin";
import imageminMozjpeg from "imagemin-mozjpeg";
import imageminWebp from "imagemin-webp";
import imageminSvgo from "imagemin-svgo";
import pify from "pify";
import sharp from "sharp";
import { ifit, needSquooshTest } from "./helpers";
Expand All @@ -22,7 +20,15 @@ function isPromise(obj) {
);
}

let imagemin;
let imageminSvgo;

describe("minify", () => {
beforeAll(async () => {
imagemin = (await import("imagemin")).default;
imageminSvgo = (await import("imagemin-svgo")).default;
});

it("minify should be is function", () =>
expect(worker).toBeInstanceOf(Function));

Expand Down

0 comments on commit b09f1a3

Please sign in to comment.