Skip to content

Commit 9e51377

Browse files
author
Cédric Belin
committed
Port the tests
1 parent 189264e commit 9e51377

6 files changed

+118
-95
lines changed

test/fast_transformer_test.coffee

Lines changed: 0 additions & 34 deletions
This file was deleted.

test/fast_transformer_test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {FastTransformer} from "@cedx/php-minifier";
2+
import {doesNotReject, ok} from "node:assert/strict";
3+
import {after, describe, it} from "node:test";
4+
5+
/**
6+
* Tests the features of the {@link FastTransformer} class.
7+
*/
8+
describe("FastTransformer", () => {
9+
describe("close()", () => {
10+
it("should not reject, even if called several times", async () => {
11+
const transformer = new FastTransformer;
12+
await doesNotReject(transformer.listen());
13+
await doesNotReject(transformer.close());
14+
await doesNotReject(transformer.close());
15+
});
16+
});
17+
18+
describe("listen()", () => {
19+
it("should not reject, even if called several times", async () => {
20+
const transformer = new FastTransformer;
21+
await doesNotReject(transformer.listen());
22+
await doesNotReject(transformer.listen());
23+
await doesNotReject(transformer.close());
24+
});
25+
});
26+
27+
describe("transform()", () => {
28+
const map = new Map([
29+
["should remove the inline comments", "<?= 'Hello World!' ?>"],
30+
["should remove the multi-line comments", "namespace dummy; class Dummy"],
31+
["should remove the single-line comments", "$className = get_class($this); return $className;"],
32+
["should remove the whitespace", "__construct() { $this->property"]
33+
]);
34+
35+
const transformer = new FastTransformer;
36+
after(() => transformer.close());
37+
38+
for (const [key, value] of map) it(key, async () => {
39+
const output = await transformer.transform("res/sample.php");
40+
ok(output.includes(value));
41+
});
42+
});
43+
});

test/gulp_plugin_test.coffee

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/gulp_plugin_test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable no-underscore-dangle */
2+
import {GulpPlugin} from "@cedx/php-minifier";
3+
import {doesNotReject, ifError, ok} from "node:assert/strict";
4+
import {resolve} from "node:path";
5+
import {after, describe, it} from "node:test";
6+
import File from "vinyl";
7+
8+
/**
9+
* Tests the features of the {@link GulpPlugin} class.
10+
*/
11+
describe("GulpPlugin", () => {
12+
describe("_transform()", () => {
13+
const map = new Map([
14+
["should remove the inline comments", "<?= 'Hello World!' ?>"],
15+
["should remove the multi-line comments", "namespace dummy; class Dummy"],
16+
["should remove the single-line comments", "$className = get_class($this); return $className;"],
17+
["should remove the whitespace", "__construct() { $this->property"]
18+
]);
19+
20+
describe("fast", () => {
21+
const file = new File({path: resolve("res/sample.php")});
22+
const plugin = new GulpPlugin({mode: "fast", silent: true});
23+
after(() => plugin.emit("end"));
24+
25+
for (const [key, value] of map) it(key, () => doesNotReject(plugin._transform(file, "utf8", (error, /** @type {File} */ chunk) => {
26+
ifError(error);
27+
ok(chunk.contents?.toString().includes(value)); // eslint-disable-line @typescript-eslint/no-base-to-string
28+
})));
29+
});
30+
31+
describe("safe", () => {
32+
const file = new File({path: resolve("res/sample.php")});
33+
const plugin = new GulpPlugin({mode: "safe", silent: true});
34+
after(() => plugin.emit("end"));
35+
36+
for (const [key, value] of map) it(key, () => doesNotReject(plugin._transform(file, "utf8", (error, /** @type {File} */ chunk) => {
37+
ifError(error);
38+
ok(chunk.contents?.toString().includes(value)); // eslint-disable-line @typescript-eslint/no-base-to-string
39+
})));
40+
});
41+
});
42+
});

test/safe_transformer_test.coffee

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/safe_transformer_test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {SafeTransformer} from "@cedx/php-minifier";
2+
import {doesNotReject, ok} from "node:assert/strict";
3+
import {after, describe, it} from "node:test";
4+
5+
/**
6+
* Tests the features of the {@link SafeTransformer} class.
7+
*/
8+
describe("SafeTransformer", () => {
9+
describe("close()", () => {
10+
it("should not reject, even if called several times", async () => {
11+
const transformer = new SafeTransformer;
12+
await doesNotReject(transformer.close());
13+
await doesNotReject(transformer.close());
14+
});
15+
});
16+
17+
describe("transform()", () => {
18+
const map = new Map([
19+
["should remove the inline comments", "<?= 'Hello World!' ?>"],
20+
["should remove the multi-line comments", "namespace dummy; class Dummy"],
21+
["should remove the single-line comments", "$className = get_class($this); return $className;"],
22+
["should remove the whitespace", "__construct() { $this->property"]
23+
]);
24+
25+
const transformer = new SafeTransformer;
26+
after(() => transformer.close());
27+
28+
for (const [key, value] of map) it(key, async () => {
29+
const output = await transformer.transform("res/sample.php");
30+
ok(output.includes(value));
31+
});
32+
});
33+
});

0 commit comments

Comments
 (0)