Skip to content

Commit

Permalink
Port the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Jan 31, 2025
1 parent 189264e commit 9e51377
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 95 deletions.
34 changes: 0 additions & 34 deletions test/fast_transformer_test.coffee

This file was deleted.

43 changes: 43 additions & 0 deletions test/fast_transformer_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {FastTransformer} from "@cedx/php-minifier";
import {doesNotReject, ok} from "node:assert/strict";
import {after, describe, it} from "node:test";

/**
* Tests the features of the {@link FastTransformer} class.
*/
describe("FastTransformer", () => {
describe("close()", () => {
it("should not reject, even if called several times", async () => {
const transformer = new FastTransformer;
await doesNotReject(transformer.listen());
await doesNotReject(transformer.close());
await doesNotReject(transformer.close());
});
});

describe("listen()", () => {
it("should not reject, even if called several times", async () => {
const transformer = new FastTransformer;
await doesNotReject(transformer.listen());
await doesNotReject(transformer.listen());
await doesNotReject(transformer.close());
});
});

describe("transform()", () => {
const map = new Map([
["should remove the inline comments", "<?= 'Hello World!' ?>"],
["should remove the multi-line comments", "namespace dummy; class Dummy"],
["should remove the single-line comments", "$className = get_class($this); return $className;"],
["should remove the whitespace", "__construct() { $this->property"]
]);

const transformer = new FastTransformer;
after(() => transformer.close());

for (const [key, value] of map) it(key, async () => {
const output = await transformer.transform("res/sample.php");
ok(output.includes(value));
});
});
});
35 changes: 0 additions & 35 deletions test/gulp_plugin_test.coffee

This file was deleted.

42 changes: 42 additions & 0 deletions test/gulp_plugin_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable no-underscore-dangle */
import {GulpPlugin} from "@cedx/php-minifier";
import {doesNotReject, ifError, ok} from "node:assert/strict";
import {resolve} from "node:path";
import {after, describe, it} from "node:test";
import File from "vinyl";

/**
* Tests the features of the {@link GulpPlugin} class.
*/
describe("GulpPlugin", () => {
describe("_transform()", () => {
const map = new Map([
["should remove the inline comments", "<?= 'Hello World!' ?>"],
["should remove the multi-line comments", "namespace dummy; class Dummy"],
["should remove the single-line comments", "$className = get_class($this); return $className;"],
["should remove the whitespace", "__construct() { $this->property"]
]);

describe("fast", () => {
const file = new File({path: resolve("res/sample.php")});
const plugin = new GulpPlugin({mode: "fast", silent: true});
after(() => plugin.emit("end"));

for (const [key, value] of map) it(key, () => doesNotReject(plugin._transform(file, "utf8", (error, /** @type {File} */ chunk) => {
ifError(error);
ok(chunk.contents?.toString().includes(value)); // eslint-disable-line @typescript-eslint/no-base-to-string
})));
});

describe("safe", () => {
const file = new File({path: resolve("res/sample.php")});
const plugin = new GulpPlugin({mode: "safe", silent: true});
after(() => plugin.emit("end"));

for (const [key, value] of map) it(key, () => doesNotReject(plugin._transform(file, "utf8", (error, /** @type {File} */ chunk) => {
ifError(error);
ok(chunk.contents?.toString().includes(value)); // eslint-disable-line @typescript-eslint/no-base-to-string
})));
});
});
});
26 changes: 0 additions & 26 deletions test/safe_transformer_test.coffee

This file was deleted.

33 changes: 33 additions & 0 deletions test/safe_transformer_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {SafeTransformer} from "@cedx/php-minifier";
import {doesNotReject, ok} from "node:assert/strict";
import {after, describe, it} from "node:test";

/**
* Tests the features of the {@link SafeTransformer} class.
*/
describe("SafeTransformer", () => {
describe("close()", () => {
it("should not reject, even if called several times", async () => {
const transformer = new SafeTransformer;
await doesNotReject(transformer.close());
await doesNotReject(transformer.close());
});
});

describe("transform()", () => {
const map = new Map([
["should remove the inline comments", "<?= 'Hello World!' ?>"],
["should remove the multi-line comments", "namespace dummy; class Dummy"],
["should remove the single-line comments", "$className = get_class($this); return $className;"],
["should remove the whitespace", "__construct() { $this->property"]
]);

const transformer = new SafeTransformer;
after(() => transformer.close());

for (const [key, value] of map) it(key, async () => {
const output = await transformer.transform("res/sample.php");
ok(output.includes(value));
});
});
});

0 comments on commit 9e51377

Please sign in to comment.