node icon indicating copy to clipboard operation
node copied to clipboard

test-snapshot-typescript should work with typescript 6

Open kapouer opened this issue 6 months ago • 10 comments

Version

24.15.0

Platform

Linux lal 7.0.7+deb14-amd64 #1 SMP PREEMPT_DYNAMIC Debian 7.0.7-1 (2026-05-15) x86_64 GNU/Linux

Subsystem

test

What steps will reproduce the bug?

Replace test/fixtures/snapshot/typescript.js by typescript 6 bundle.

How often does it reproduce? Is there a required condition?

As a distributor, we avoid bundled software when not strictly necessary. test/fixtures/snapshot/typescript.js is such a thing. Instead, I use a copy of the node-typescript debian package files, setup before the tests.

What is the expected behavior? Why is that the expected behavior?

No test error.

What do you see instead?

105s AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 105s + actual - expected 105s
105s + '"use strict";\n' + 105s + 'class VirtualPoint {\n' + 105s + ' x;\n' + 105s + ' y;\n' + 105s + ' constructor(x, y) {\n' + 105s - 'var VirtualPoint = /** @class */ (function () {\n' + 105s - ' function VirtualPoint(x, y) {\n' + 105s ' this.x = x;\n' + 105s ' this.y = y;\n' + 105s ' }\n' + 105s + '}\n' + 105s + 'const newVPoint = new VirtualPoint(13, 56);\n' 105s - ' return VirtualPoint;\n' + 105s - '}());\n' + 105s - 'var newVPoint = new VirtualPoint(13, 56);\n'

Additional information

Something like this could help

--- a/test/fixtures/snapshot/typescript-main.js
+++ b/test/fixtures/snapshot/typescript-main.js
@@ -20,7 +20,10 @@
     source,
     {
       compilerOptions: {
-        module: ts.ModuleKind.CommonJS
+        module: ts.ModuleKind.CommonJS,
+        strict: false,
+        alwaysStrict: false,
+        target: 'es5'
       }
     });

kapouer avatar May 19 '26 10:05 kapouer

This is a test fixture and essentially it only serves as ”a huge blob of sophisticated enough real-world JavaScript for testing”. The fact that it’s an outdated copy of a popular library instead of randomly generated gibberish can be seen as mostly a coincidence. It is not used by the Node.js binary. Is there a reason why the downstream distribution is bundling a test fixture at all?

joyeecheung avatar May 20 '26 00:05 joyeecheung

Le mer. 20 mai 2026, 02:30, Joyee Cheung @.***> a écrit :

joyeecheung left a comment (nodejs/node#63427) https://github.com/nodejs/node/issues/63427#issuecomment-4493382937

This is a test fixture and essentially it only serves as a”a huge blob of sophisticated enough real-world JavaScript for testing”. Is there a reason why the downstream distribution is bundling a test fixture at all?

Yes because we run most unit tests

— Reply to this email directly, view it on GitHub https://github.com/nodejs/node/issues/63427#issuecomment-4493382937, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABACTRMF2UA5TR2IIMTHE343T4DZAVCNFSM6AAAAACZEEEKUOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DIOJTGM4DEOJTG4 . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

kapouer avatar May 20 '26 06:05 kapouer

I think if the diff is small (like the one in the OP) and it works with the bundle in the upstream, feel free to send in a PR to make it work with both bundles. If it becomes a significant churn, it may be better to either disable those tests or avoid bundling it. As said it's only a coincidence that the fixture happens to be an outdated version of a popular library, it should technically be treated as no more special than a randomly generated blob of JavaScript.

joyeecheung avatar May 20 '26 18:05 joyeecheung

Although according to the OP:

Replace test/fixtures/snapshot/typescript.js by typescript 6 bundle.

I think down the line, this is just going to be problematic. The test fixture is pinned at 4.7.4 and there's no plan to update it - introducing a maintenance burden of keeping it up to date is not worth it when all we need is no more than "a giant blob of JavaScript". If the idea is that this is meant to "keep working with actual version of TypeScript" I think maybe we should either delete the test so that people don't even attempt to take it as real TypeScript, or at least replace it with some much less serious blob of JavaScript so that there's no one who would take it any more seriously than "a random blob of JavaScript".

joyeecheung avatar May 20 '26 20:05 joyeecheung

In that case, if the goal is to just run "a big blob of js", could it be possible to generate it ?

kapouer avatar May 20 '26 20:05 kapouer

I think yes, though it's a bit difficult to think of a way to generate "a big blob of JavaScript that exercises many JavaScript features and also use a bit of Node.js builtins" other than "pulling some popular library from npm", which was what we did ;) Idea is welcome though!

joyeecheung avatar May 20 '26 20:05 joyeecheung

@joyeecheung — I verified the OP's diff both ways: with the pinned options, the 4.7.4 bundle still emits the current golden file byte-for-byte, and a TypeScript 6.0.3 bundle emits the same output — including when actually embedded in a snapshot build and run against ts-example.ts.

On the "down the line" concern: typescript@7 ships the native compiler and no lib/typescript.js at all, so 6.x is the last JS bundle a distributor could swap in — the version-chasing ends there.

I can send the OP's diff as a PR, unless you'd rather delete or replace the fixture as you suggested.

soreavis avatar Jul 16 '26 09:07 soreavis

TBH I think the best course of action is do nothing. The version is meaningless since we only want "a blob of JS", and it doesn't really need to stay up to date for that purpose. In retrospect I probably should've named it "this-is-not-typescript-dont-mind-its-version.js" to prevent the lost souls from taking it this seriously...

joyeecheung avatar Jul 16 '26 11:07 joyeecheung

This issue has been marked as stale due to 90 days of inactivity. It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

github-actions[bot] avatar Oct 15 '26 01:10 github-actions[bot]

This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days). If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

github-actions[bot] avatar Nov 15 '26 01:11 github-actions[bot]