Skip to content

Conversation

@gibson042
Copy link

Description

In ECMAScript template literals, ` and \ and $ are special and therefore need escaping in generation of source text like new TypedDocumentString(`…`), while still preserving literal ${…} as appropriate for fragment references.

Related #10480

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Existing tests seem to pass, although yarn test ends with an error for me even before application of these changes:

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: [vitest-pool]: Worker forks emitted error.
 ❯ EventEmitter.<anonymous> node_modules/vitest/dist/chunks/cli-api.BxbUFDR6.js:6866:22
 ❯ EventEmitter.emit node:events:519:28
 ❯ ChildProcess.emitUnexpectedExit node_modules/vitest/dist/chunks/cli-api.BxbUFDR6.js:6513:22
 ❯ ChildProcess.emit node:events:519:28
 ❯ Process.ChildProcess._handle.onexit node:internal/child_process:293:12

Caused by: Error: Worker exited unexpectedly
 ❯ ChildProcess.emitUnexpectedExit node_modules/vitest/dist/chunks/cli-api.BxbUFDR6.js:6512:33
 ❯ ChildProcess.emit node:events:519:28
 ❯ Process.ChildProcess._handle.onexit node:internal/child_process:293:12

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯


 Test Files  48 passed (49)
      Tests  759 passed | 4 skipped (764)
     Errors  1 error
   Start at  17:13:14
   Duration  31.49s (transform 13.16s, setup 334ms, collect 55.99s, tests 23.56s, environment 12ms, prepare 829ms)

error during close Error: [vitest-pool-runner]: Timeout waiting for worker to respond
    at Timeout.<anonymous> (file:///host/graphql-code-generator/node_modules/vitest/dist/chunks/cli-api.BxbUFDR6.js:6525:58)
    at listOnTimeout (node:internal/timers:588:17)
    at process.processTimers (node:internal/timers:523:7)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I'm unfamiliar with your test framework and would appreciate suggestions/guidance on how to cover the specific scenario of #10480.

Test Environment:

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@changeset-bot
Copy link

changeset-bot bot commented Nov 6, 2025

⚠️ No Changeset found

Latest commit: 4dcd10e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

}

if (this.config.documentMode === DocumentMode.string) {
const escapedLiteralContents = asTemplateLiteral(doc).slice(1, -1);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to further extend this for honoring optimizeDocumentNode (but doing so introduces whitespace changes that break tests):

Suggested change
const escapedLiteralContents = asTemplateLiteral(doc).slice(1, -1);
const optimizedDoc = this.config.optimizeDocumentNode
? print(optimizeDocumentNode(gqlTag([doc])))
: doc;
const escapedLiteralContents = asTemplateLiteral(optimizedDoc).slice(1, -1);

return `new TypedDocumentString(\`${escapedLiteralContents}\`)`;
}

const escapedLiteralContentsPrefix = asTemplateLiteral(docLiteralContents).slice(1, -1);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to further extend this for honoring optimizeDocumentNode (but doing so introduces whitespace changes that break tests):

Suggested change
const escapedLiteralContentsPrefix = asTemplateLiteral(docLiteralContents).slice(1, -1);
const optimizedDocPrefix = this.config.optimizeDocumentNode
? print(optimizeDocumentNode(gqlTag([docLiteralContents])))
: docLiteralContents;
const escapedLiteralContentsPrefix = asTemplateLiteral(optimizedDocPrefix).slice(1, -1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant