-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix: Add objectParser for ObjectTypeAnnotation (e.g. PARSE_SERVER_AUTH_PROVIDERS) #9912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mattia1208
wants to merge
6
commits into
parse-community:alpha
Choose a base branch
from
E38-Software:fix/auth-env-bug
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+159
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
996205b
fix: Add objectParser action for ParseServerOptions in Definitions.js
Giacomo117 81b88f1
Merge branch 'parse-community:alpha' into fix/auth-env-bug
mattia1208 d794856
Merge branch 'alpha' of https://github.com/E38-Software/parse-server …
Giacomo117 c72fff6
Merge branch 'fix/auth-env-bug' of https://github.com/E38-Software/pa…
Giacomo117 69875a2
test: Add unit tests for mapperFor function in buildConfigDefinitions
Giacomo117 8224a93
feat: Export mapperFor function for testing purposes
Giacomo117 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| const t = require('@babel/types'); | ||
| const { mapperFor } = require('../resources/buildConfigDefinitions'); | ||
|
|
||
| describe('buildConfigDefinitions', () => { | ||
| describe('mapperFor', () => { | ||
| it('should return objectParser for ObjectTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'ObjectTypeAnnotation', | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('objectParser'); | ||
| }); | ||
|
|
||
| it('should return objectParser for AnyTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'AnyTypeAnnotation', | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('objectParser'); | ||
| }); | ||
|
|
||
| it('should return arrayParser for ArrayTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'ArrayTypeAnnotation', | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('arrayParser'); | ||
| }); | ||
|
|
||
| it('should return booleanParser for BooleanTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'BooleanTypeAnnotation', | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('booleanParser'); | ||
| }); | ||
|
|
||
| it('should return numberParser call expression for NumberTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'NumberTypeAnnotation', | ||
| name: 'testNumber', | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isCallExpression(result)).toBe(true); | ||
| expect(result.callee.property.name).toBe('numberParser'); | ||
| expect(result.arguments[0].value).toBe('testNumber'); | ||
| }); | ||
|
|
||
| it('should return moduleOrObjectParser for Adapter GenericTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'GenericTypeAnnotation', | ||
| typeAnnotation: { | ||
| id: { | ||
| name: 'Adapter', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('moduleOrObjectParser'); | ||
| }); | ||
|
|
||
| it('should return numberOrBooleanParser for NumberOrBoolean GenericTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'GenericTypeAnnotation', | ||
| typeAnnotation: { | ||
| id: { | ||
| name: 'NumberOrBoolean', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('numberOrBooleanParser'); | ||
| }); | ||
|
|
||
| it('should return numberOrStringParser call expression for NumberOrString GenericTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'GenericTypeAnnotation', | ||
| name: 'testString', | ||
| typeAnnotation: { | ||
| id: { | ||
| name: 'NumberOrString', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isCallExpression(result)).toBe(true); | ||
| expect(result.callee.property.name).toBe('numberOrStringParser'); | ||
| expect(result.arguments[0].value).toBe('testString'); | ||
| }); | ||
|
|
||
| it('should return arrayParser for StringOrStringArray GenericTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'GenericTypeAnnotation', | ||
| typeAnnotation: { | ||
| id: { | ||
| name: 'StringOrStringArray', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('arrayParser'); | ||
| }); | ||
|
|
||
| it('should return objectParser for unknown GenericTypeAnnotation', () => { | ||
| const mockElement = { | ||
| type: 'GenericTypeAnnotation', | ||
| typeAnnotation: { | ||
| id: { | ||
| name: 'UnknownType', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const result = mapperFor(mockElement, t); | ||
|
|
||
| expect(t.isMemberExpression(result)).toBe(true); | ||
| expect(result.object.name).toBe('parsers'); | ||
| expect(result.property.name).toBe('objectParser'); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Verify that tests handle file system side effects.
Exporting
mapperForenables testing, which is good. However, when this module is required (e.g., by tests), it will execute the babel transformation at lines 378-385, which writes toDefinitions.jsanddocs.js. Ensure that your test setup either:🏁 Script executed:
Length of output: 471
🏁 Script executed:
Length of output: 2399
🏁 Script executed:
Length of output: 168
🏁 Script executed:
Length of output: 167
🏁 Script executed:
Length of output: 372
🏁 Script executed:
Length of output: 30
🏁 Script executed:
Length of output: 1499
Refactor to prevent file system writes during test import.
The side effect concern is confirmed: the transformation at lines 378-385 executes unconditionally on import, writing to versioned files
src/Options/Definitions.jsandsrc/Options/docs.jsevery time tests run.Use one of these approaches:
if (require.main === module)guard around the transformation, so it only runs when executed directlyNODE_ENV === 'test'check to skip transformation during testingfs.writeFileSyncin test setupmapperForwithout running the build🤖 Prompt for AI Agents