Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 19 additions & 55 deletions packages/core/__tests__/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,9 @@ describe("Package: core", async () => {
output: filesJS.fileJSOut,
};

try {
return await minify(settings);
} catch (err: unknown) {
if (err instanceof Error) {
return expect(err.toString()).toEqual(
"Error: compressor should be a function, maybe you forgot to install the compressor"
);
}
}
await expect(minify(settings)).rejects.toThrow(
"compressor should be a function, maybe you forgot to install the compressor"
);
});
});

Expand All @@ -58,15 +52,9 @@ describe("Package: core", async () => {
output: filesJS.fileJSOut,
};

try {
return await minify(settings);
} catch (err: unknown) {
if (err instanceof Error) {
return expect(err.toString()).toEqual(
"Error: compressor is mandatory."
);
}
}
await expect(minify(settings)).rejects.toThrow(
"compressor is mandatory."
Comment thread
srod marked this conversation as resolved.
Resolved
);
});

test("should throw an error if no input", async () => {
Expand All @@ -75,15 +63,9 @@ describe("Package: core", async () => {
output: filesJS.fileJSOut,
};

try {
return await minify(settings);
} catch (err: unknown) {
if (err instanceof Error) {
return expect(err.toString()).toEqual(
"Error: input is mandatory."
);
}
}
await expect(minify(settings)).rejects.toThrow(
"input is mandatory."
);
});

test("should throw an error if no output", async () => {
Expand All @@ -92,36 +74,24 @@ describe("Package: core", async () => {
input: filesJS.oneFileWithWildcards,
};

try {
return await minify(settings);
} catch (err: unknown) {
if (err instanceof Error) {
return expect(err.toString()).toEqual(
"Error: output is mandatory."
);
}
}
await expect(minify(settings)).rejects.toThrow(
"output is mandatory."
);
});
});

describe("Mandatory", () => {
test("should show throw on type option", async () => {
test("should require a compressor even when type is set", async () => {
const settings: Settings = {
// @ts-expect-error testing invalid input: "uglifyjs" is not a valid FileType ("js" | "css")
type: "uglifyjs",
input: filesJS.oneFileWithWildcards,
output: filesJS.fileJSOut,
};

try {
return await minify(settings);
} catch (err: unknown) {
if (err instanceof Error) {
return expect(err.toString()).toEqual(
"Error: compressor is mandatory."
);
}
}
await expect(minify(settings)).rejects.toThrow(
"compressor is mandatory."
);
});
});

Expand Down Expand Up @@ -167,15 +137,9 @@ describe("Package: core", async () => {
"<html lang='en'><body><div>content</div></body></html>",
};

try {
return await minify(settings);
} catch (err: unknown) {
if (err instanceof Error) {
return expect(err.toString()).toEqual(
"Error: compressor should be a function, maybe you forgot to install the compressor"
);
}
}
await expect(minify(settings)).rejects.toThrow(
"compressor should be a function, maybe you forgot to install the compressor"
);
});
});

Expand Down
8 changes: 3 additions & 5 deletions packages/cssnano/__tests__/cssnano.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ describe("Package: cssnano", async () => {
output: filesCSS.fileCSSOut,
};

try {
return await minify(settings);
} catch (err) {
return expect(err).not.toBeNull();
}
await expect(minify(settings)).rejects.toThrow(
"cssnano minification failed"
);
});
});
14 changes: 4 additions & 10 deletions packages/esbuild/__tests__/esbuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ describe("Package: esbuild", async () => {
type: "js",
};

try {
return await minify(settings);
} catch (err) {
return expect(err).not.toBeNull();
}
await expect(minify(settings)).rejects.toThrow("Transform failed");
});
});

Expand Down Expand Up @@ -100,10 +96,8 @@ describe("Package: esbuild", async () => {
output: filesJS.fileJSOut,
};

try {
return await minify(settings);
} catch (err) {
return expect(err).toBeInstanceOf(Error);
}
await expect(minify(settings)).rejects.toThrow(
"You must specify a type: js or css"
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ describe("Package: google-closure-compiler", async () => {
output: filesJS.fileJSOut,
};

try {
return await minify(settings);
} catch (err) {
return expect(err).not.toBeNull();
}
await expect(minify(settings)).rejects.toThrow("exited with code");
});

test("should compress with boolean options", async (): Promise<void> => {
Expand Down
6 changes: 1 addition & 5 deletions packages/lightningcss/__tests__/lightningcss.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ describe("Package: lightningcss", async () => {
output: filesCSS.fileCSSOut,
};

try {
return await minify(settings);
} catch (err) {
return expect(err).not.toBeNull();
}
await expect(minify(settings)).rejects.toThrow(SyntaxError);
});

test("should throw an error for array content", async () => {
Expand Down
6 changes: 1 addition & 5 deletions packages/swc/__tests__/swc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ describe("Package: swc", async () => {
output: filesJS.fileJSOut,
};

try {
return await minify(settings);
} catch (err) {
return expect(err).not.toBeNull();
}
await expect(minify(settings)).rejects.toThrow();
});
});
6 changes: 1 addition & 5 deletions packages/terser/__tests__/terser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ describe("Package: terser", async () => {
},
};

try {
return await minify(settings);
} catch (err) {
return expect(err).not.toBeNull();
}
await expect(minify(settings)).rejects.toThrow();
});
});
6 changes: 1 addition & 5 deletions packages/uglify-js/__tests__/uglify-js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ describe("Package: uglify-js", async () => {
output: filesJS.fileJSOut,
};

try {
return await minify(settings);
} catch (err) {
return expect(err).not.toBeNull();
}
await expect(minify(settings)).rejects.toThrow();
});
});
Loading