fix(client-generator-ts): type browser null singleton exports#29408
fix(client-generator-ts): type browser null singleton exports#29408raashish1601 wants to merge 2 commits intoprisma:mainfrom
Conversation
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughExports for the null singletons ( Changes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/client-generator-ts/tests/generator.test.ts (1)
89-144:⚠️ Potential issue | 🟡 MinorEnsure
generator.stop()always runs withtry/finally.In Line 143 and Line 161, cleanup is on the success path only. If an assertion or file read fails,
generator.stop()is skipped.Suggested hardening
test('minimal', async () => { const generator = await getGenerator({ schemaPath: path.join(__dirname, 'schema.prisma'), printDownloadProgress: false, skipDownload: true, registry, }) - - const manifest = omit(generator.manifest!, ['version']) + try { + const manifest = omit(generator.manifest!, ['version']) - if (manifest.requiresEngineVersion?.length !== 40) { - throw new Error(`Generator manifest should have "requiresEngineVersion" with length 40`) - } - manifest.requiresEngineVersion = 'ENGINE_VERSION_TEST' + if (manifest.requiresEngineVersion?.length !== 40) { + throw new Error(`Generator manifest should have "requiresEngineVersion" with length 40`) + } + manifest.requiresEngineVersion = 'ENGINE_VERSION_TEST' - // ... assertions ... + // ... assertions ... - await generator.generate() - const clientDir = path.join(__dirname, 'generated') - expect(fs.existsSync(clientDir)).toBe(true) - expect(fs.existsSync(path.join(clientDir, 'client.ts'))).toBe(true) - - generator.stop() + await generator.generate() + const clientDir = path.join(__dirname, 'generated') + expect(fs.existsSync(clientDir)).toBe(true) + expect(fs.existsSync(path.join(clientDir, 'client.ts'))).toBe(true) + } finally { + generator.stop() + } }) test('emits portable typed null singleton exports in the browser namespace', async () => { const generator = await getGenerator({ schemaPath: path.join(__dirname, 'schema.prisma'), printDownloadProgress: false, skipDownload: true, registry, }) - - await generator.generate() - const clientDir = path.join(__dirname, 'generated') - const browserNamespace = fs.readFileSync(path.join(clientDir, 'internal', 'prismaNamespaceBrowser.ts'), 'utf8') - expect(browserNamespace).toContain('export const DbNull: typeof runtime.DbNull = runtime.DbNull') - expect(browserNamespace).toContain('export const JsonNull: typeof runtime.JsonNull = runtime.JsonNull') - expect(browserNamespace).toContain('export const AnyNull: typeof runtime.AnyNull = runtime.AnyNull') - - generator.stop() + try { + await generator.generate() + const clientDir = path.join(__dirname, 'generated') + const browserNamespace = fs.readFileSync(path.join(clientDir, 'internal', 'prismaNamespaceBrowser.ts'), 'utf8') + expect(browserNamespace).toContain('export const DbNull: typeof runtime.DbNull = runtime.DbNull') + expect(browserNamespace).toContain('export const JsonNull: typeof runtime.JsonNull = runtime.JsonNull') + expect(browserNamespace).toContain('export const AnyNull: typeof runtime.AnyNull = runtime.AnyNull') + } finally { + generator.stop() + } })Also applies to: 146-162
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/client-generator-ts/tests/generator.test.ts` around lines 89 - 144, The test should ensure generator.stop() is always called by wrapping generator usage in a try/finally: locate the test function named "test('minimal')" (and the other similar test around the second block) where getGenerator(...) is awaited and generator.generate() is called, move generator.stop() into a finally block so it runs even if assertions or file operations fail; keep generator variable in scope (declared before try) and call generator.stop() in the finally to guarantee cleanup.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/client-generator-ts/tests/generator.test.ts`:
- Around line 89-144: The test should ensure generator.stop() is always called
by wrapping generator usage in a try/finally: locate the test function named
"test('minimal')" (and the other similar test around the second block) where
getGenerator(...) is awaited and generator.generate() is called, move
generator.stop() into a finally block so it runs even if assertions or file
operations fail; keep generator variable in scope (declared before try) and call
generator.stop() in the finally to guarantee cleanup.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: a8bea333-e61f-4028-bee9-ff0d4582f03f
📒 Files selected for processing (2)
packages/client-generator-ts/src/TSClient/NullTypes.tspackages/client-generator-ts/tests/generator.test.ts
|
I would like to see a reproduction of the issue this is meant to fix. Ideally this reproduction would be turned into a test, we could make it an E2E test in |
Summary
typeof runtime.*annotations to the generated browser-sideDbNull,JsonNull, andAnyNullsingleton exportsinternal/prismaNamespaceBrowser.tstext directlyTesting
pnpm.cmd install --frozen-lockfilepnpm.cmd --filter @prisma/client-generator-ts... buildpnpm.cmd --filter @prisma/client-generator-ts exec vitest run tests/generator.test.ts -t "emits portable typed null singleton exports in the browser namespace"pnpm.cmd exec eslint packages/client-generator-ts/src/TSClient/NullTypes.ts packages/client-generator-ts/tests/generator.test.tsgit diff --check HEAD~1..HEADFixes #28581
Summary by CodeRabbit
Refactor
Tests