Skip to content

Commit

Permalink
test: add a test case for unusual charsets
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Dec 19, 2024
1 parent 74efd93 commit 2a5dfe6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/snapshots/transform.test.js.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ exports[`should perform transformation with source maps no filename 2`] = `
"{\\"version\\":3,\\"sources\\":[\\"<anon>\\"],\\"sourcesContent\\":[\\"\\\\n enum Foo {\\\\n Bar = 7,\\\\n Baz = 2,\\\\n }\\\\n output = Foo.Bar\\"],\\"names\\":[],\\"mappings\\":\\"AACI,IAAA,AAAK,6BAAA;;;WAAA;EAAA;AAIL\\"}"
`;

exports[`should perform transformation with source maps with uncommon chars 1`] = `
"var Foo = /*#__PURE__*/ function(Foo) {\\n Foo[Foo[\\"Bar\\"] = 7] = \\"Bar\\";\\n Foo[Foo[\\"Baz\\"] = 2] = \\"Baz\\";\\n return Foo;\\n}(Foo || {});\\noutput = 7;\\n"
`;

exports[`should perform transformation with source maps with uncommon chars 2`] = `
"{\\"version\\":3,\\"sources\\":[\\"dir%20with $unusual\\\\\\"chars?'åß∂ƒ©∆¬…\`.cts\\"],\\"names\\":[],\\"mappings\\":\\"AACI,IAAA,AAAK,6BAAA;;;WAAA;EAAA;AAKL\\"}"
`;

exports[`should perform transformation without source maps 1`] = `
"var Foo = /*#__PURE__*/ function(Foo) {\\n Foo[Foo[\\"Bar\\"] = 7] = \\"Bar\\";\\n Foo[Foo[\\"Baz\\"] = 2] = \\"Baz\\";\\n return Foo;\\n}(Foo || {});\\noutput = 7;\\n"
`;
Expand Down
20 changes: 20 additions & 0 deletions test/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ test("should perform transformation with source maps", (t) => {
assert.strictEqual(result, 7);
});

test("should perform transformation with source maps with uncommon chars", (t) => {
const tsCode = `
enum Foo {
Bar = 7,
Baz = 2,
}
output = Foo.Bar`;
const { code, map } = transformSync(tsCode, {
mode: "transform",
sourceMap: true,
filename: "dir%20with $unusual\"chars?'åß∂ƒ©∆¬…`.cts",
});

t.assert.snapshot(code);
t.assert.snapshot(map);
const result = vm.runInContext(code, vm.createContext());
assert.strictEqual(result, 7);
});

test("should perform transformation with source maps no filename", (t) => {
const tsCode = `
enum Foo {
Expand Down

0 comments on commit 2a5dfe6

Please sign in to comment.