Skip to content

Commit d22ac5f

Browse files
committed
test(javascript): type runtime comment pattern fixtures
1 parent 9a1f2c6 commit d22ac5f

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎test/unitCases/jsMinify.unittest.js‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ describe("jsMinify", () => {
141141
const actual = await jsMinify(
142142
input,
143143
INPUT_MAP,
144-
{ printer, format: { comments: "first|last" } },
145-
{ condition: "@license" }
144+
// Terser accepts string patterns at runtime, but its types exclude them.
145+
{ printer, format: { comments: /** @type {EXPECTED_ANY} */ ("first|last") } },
146+
{ condition: /** @type {EXPECTED_ANY} */ ("@license") }
146147
);
147148
const expected = await jsMinify(
148149
input,
@@ -155,15 +156,17 @@ describe("jsMinify", () => {
155156
});
156157

157158
it(`should defer invalid comment patterns until a comment is tested (printer: ${printer})`, async () => {
158-
const options = { printer, format: { comments: "[" } };
159+
// Exercise a malformed runtime pattern outside the published type union.
160+
const invalidPattern = /** @type {EXPECTED_ANY} */ ("[");
161+
const options = { printer, format: { comments: invalidPattern } };
159162
const input = { "plain.js": "run();" };
160-
expect(await jsMinify(input, undefined, options, { condition: "[" })).toEqual(
163+
expect(await jsMinify(input, undefined, options, { condition: invalidPattern })).toEqual(
161164
await jsMinify(input, undefined, { printer, format: { comments: false } }, false)
162165
);
163166
const commented = { "commented.js": "/* comment */ run();" };
164167
await expect(jsMinify(commented, undefined, options, false)).rejects.toThrow(SyntaxError);
165168
await expect(
166-
jsMinify(commented, undefined, { printer }, { condition: "[" })
169+
jsMinify(commented, undefined, { printer }, { condition: invalidPattern })
167170
).rejects.toThrow(SyntaxError);
168171
});
169172
}

0 commit comments

Comments
 (0)