-
Notifications
You must be signed in to change notification settings - Fork 214
[E2E][Bugfix] Fix usage for Object.hasOwn #3237
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9af5caf
Fix usage for Object.hasOwn
shethj 5142a48
Fix linting
shethj 2f3c013
Handle OS specific filepaths in tests
shethj 2611018
Merge branch 'develop' into hotfix/validate-project-type-err
shethj 7771f69
Enable OTEL test
shethj c0f4de8
Merge branch 'develop' into hotfix/validate-project-type-err
shethj 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
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 @@ | ||
| /* | ||
| * Copyright (c) 2025, Salesforce, Inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| const fs = require('fs') | ||
| const path = require('path') | ||
|
|
||
| // Mock the dependencies | ||
| jest.mock('fs') | ||
|
|
||
| // Mocking the config.js file to allow testing with smaller arrays of expected artifacts | ||
| jest.mock('../config.js', () => ({ | ||
| GENERATED_PROJECTS_DIR: '../generated-projects', | ||
| EXPECTED_GENERATED_ARTIFACTS: { | ||
| 'retail-app-demo': ['package.json', 'node_modules', 'config'], | ||
| 'retail-app-ext': ['package.json', 'node_modules', 'overrides'] | ||
| } | ||
| })) | ||
| jest.mock('./utils.js', () => ({ | ||
| diffArrays: jest.fn() | ||
| })) | ||
|
|
||
| // Import the functions to test | ||
| const {diffArrays} = require('./utils.js') | ||
| const {validateGeneratedArtifacts} = require('./validate-generated-project.js') | ||
|
|
||
| describe('validateGeneratedArtifacts', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| test('resolves when all expected artifacts are present', async () => { | ||
| const project = 'retail-app-demo' | ||
| const expectedArtifacts = ['package.json', 'node_modules', 'config'] | ||
| const actualArtifacts = ['package.json', 'node_modules', 'config', 'extra-file'] | ||
|
|
||
| fs.readdirSync.mockReturnValue(actualArtifacts) | ||
| diffArrays.mockReturnValue([]) | ||
|
|
||
| const result = await validateGeneratedArtifacts(project) | ||
|
|
||
| expect(fs.readdirSync).toHaveBeenCalledWith( | ||
| // path.sep is used to handle the platform-specific path separator. (Windows uses \ and other platforms use /) | ||
| expect.stringContaining(`generated-projects${path.sep}${project}`) | ||
| ) | ||
| expect(diffArrays).toHaveBeenCalledWith(expectedArtifacts, actualArtifacts) | ||
| expect(result).toBe(`Successfully validated generated artifacts for: ${project} `) | ||
| }) | ||
|
|
||
| test('rejects when artifacts are missing', async () => { | ||
| const project = 'retail-app-demo' | ||
| const actualArtifacts = ['package.json', 'node_modules'] | ||
| const missingArtifacts = ['config'] | ||
|
|
||
| fs.readdirSync.mockReturnValue(actualArtifacts) | ||
| diffArrays.mockReturnValue(missingArtifacts) | ||
|
|
||
| await expect(validateGeneratedArtifacts(project)).rejects.toBe( | ||
| `Generated project (${project}) is missing one or more artifacts: ${missingArtifacts}` | ||
| ) | ||
| }) | ||
|
|
||
| test('rejects when project directory does not exist', async () => { | ||
| const project = 'non-existent-project' | ||
| const error = new Error('ENOENT: no such file or directory') | ||
|
|
||
| fs.readdirSync.mockImplementation(() => { | ||
| throw error | ||
| }) | ||
|
|
||
| await expect(validateGeneratedArtifacts(project)).rejects.toBe( | ||
| `Generated project (${project}) is missing one or more artifacts: ${error}` | ||
| ) | ||
| }) | ||
|
|
||
| test('handles project with no expected artifacts', async () => { | ||
| const project = 'unknown-project' | ||
| const actualArtifacts = ['some-file'] | ||
|
|
||
| fs.readdirSync.mockReturnValue(actualArtifacts) | ||
| diffArrays.mockReturnValue([]) | ||
|
|
||
| const result = await validateGeneratedArtifacts(project) | ||
|
|
||
| expect(diffArrays).toHaveBeenCalledWith([], actualArtifacts) | ||
| expect(result).toBe(`Successfully validated generated artifacts for: ${project} `) | ||
| }) | ||
| }) | ||
|
|
||
| // Since it requires files at runtime, we'll test the key validation logic | ||
| describe('validateExtensibilityConfig validation logic', () => { | ||
| test('validates Object.hasOwn usage for extensibility config', () => { | ||
| // Test the core validation logic that was fixed | ||
| const validConfig = { | ||
| ccExtensibility: { | ||
| extends: '@salesforce/retail-react-app', | ||
| overridesDir: 'overrides' | ||
| } | ||
| } | ||
|
|
||
| const invalidConfigMissingProperty = { | ||
| ccExtensibility: { | ||
| extends: '@salesforce/retail-react-app' | ||
| // missing overridesDir | ||
| } | ||
| } | ||
|
|
||
| const invalidConfigWrongExtends = { | ||
| ccExtensibility: { | ||
| extends: '@wrong/package', | ||
| overridesDir: 'overrides' | ||
| } | ||
| } | ||
|
|
||
| expect(Object.hasOwn(validConfig, 'ccExtensibility')).toBe(true) | ||
| expect(Object.hasOwn(validConfig.ccExtensibility, 'extends')).toBe(true) | ||
| expect(Object.hasOwn(validConfig.ccExtensibility, 'overridesDir')).toBe(true) | ||
|
|
||
| expect(Object.hasOwn(invalidConfigMissingProperty.ccExtensibility, 'overridesDir')).toBe( | ||
| false | ||
| ) | ||
|
|
||
| const isValidConfig = (pkg) => { | ||
| return ( | ||
| Object.hasOwn(pkg, 'ccExtensibility') && | ||
| Object.hasOwn(pkg.ccExtensibility, 'extends') && | ||
| Object.hasOwn(pkg.ccExtensibility, 'overridesDir') && | ||
| pkg.ccExtensibility.extends === '@salesforce/retail-react-app' && | ||
| pkg.ccExtensibility.overridesDir === 'overrides' | ||
| ) | ||
| } | ||
|
|
||
| expect(isValidConfig(validConfig)).toBe(true) | ||
| expect(isValidConfig(invalidConfigMissingProperty)).toBe(false) | ||
| expect(isValidConfig(invalidConfigWrongExtends)).toBe(false) | ||
| }) | ||
|
|
||
| test('validates template version matching logic', () => { | ||
| const pkg = {version: '1.0.0'} | ||
|
|
||
| const validateVersion = (pkg, templateVersion) => { | ||
| return !templateVersion || pkg.version === templateVersion | ||
| } | ||
|
|
||
| expect(validateVersion(pkg, undefined)).toBe(true) | ||
| expect(validateVersion(pkg, null)).toBe(true) | ||
| expect(validateVersion(pkg, '1.0.0')).toBe(true) | ||
| expect(validateVersion(pkg, '2.0.0')).toBe(false) | ||
| }) | ||
| }) |
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.
I see.. once we enable OTEL, then this test should pass.
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.
I set the env var in the workflow to enable OTEL so the test should pass.