-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
118 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}))); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); | ||
}); |