Skip to content
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

refactor(internet): rename userName method to username #3130

Merged
merged 12 commits into from
Oct 12, 2024

Conversation

suyashgulati
Copy link
Contributor

Aims to resolve #3023

As the team has decided to user username as a convention over the current userName method name.
This PR refactors the code to use username instead.

@suyashgulati suyashgulati requested a review from a team as a code owner September 22, 2024 14:31
Copy link

netlify bot commented Sep 22, 2024

Deploy Preview for fakerjs ready!

Name Link
🔨 Latest commit afe723e
🔍 Latest deploy log https://app.netlify.com/sites/fakerjs/deploys/670afc6b9ef8e000082d5fc2
😎 Deploy Preview https://deploy-preview-3130.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Sep 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.96%. Comparing base (e271d4a) to head (afe723e).
Report is 1 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff            @@
##             next    #3130    +/-   ##
========================================
  Coverage   99.96%   99.96%            
========================================
  Files        2798     2798            
  Lines      227793   227806    +13     
  Branches      955      577   -378     
========================================
+ Hits       227709   227737    +28     
+ Misses         84       69    -15     
Files with missing lines Coverage Δ
src/modules/git/index.ts 100.00% <100.00%> (ø)
src/modules/internet/index.ts 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

@xDivisionByZerox xDivisionByZerox added p: 1-normal Nothing urgent c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs m: internet Something is referring to the internet module deprecation A deprecation was made in the PR labels Sep 22, 2024
@xDivisionByZerox xDivisionByZerox added this to the v9.x milestone Sep 22, 2024
@suyashgulati
Copy link
Contributor Author

I wasn't aware the old one needs to be deprecated, I expected it to be refactor issue.
I will make changes.
thanks @matthewmayer

@suyashgulati
Copy link
Contributor Author

@matthewmayer I have made the changes and deprecated the userName
But if I am using testing both new and deprecated code I am not able to pass the preflight locally.

Screenshot 2024-09-23 at 2 41 39 AM

Its showing cannot use deprecated code.
Can you suggest what do to in that case?

@xDivisionByZerox
Copy link
Member

The error messages are correct as eslint is warning you about the usage of deprecated code. In this specific case, it is obviously ok, since you just maked this method as deprecated. We have this rule to make sure that we are no longer using the deprecated method in any of the live source code.

For the test files you can use a comment to disable the check on the next line. An example would currently be in the image module test where avatarLegacy was deprecated:

it('should return a random avatar url from cloudflare-ipfs', () => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const avatarUrl = faker.image.avatarLegacy();
expect(avatarUrl).toBeTypeOf('string');
expect(avatarUrl).toMatch(
/^https:\/\/cloudflare-ipfs\.com\/ipfs\/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye\/avatar\/\d{1,4}\.jpg$/
);
});

@suyashgulati
Copy link
Contributor Author

Issue: Unit Tests are failing at checking the deprecated tag on new username method
RCA: I found out we are creating a new ephemeral files to execute examples from the js doc in test/scripts/apidocs/verify-jsdoc-tags.spec.ts being written here

As userName and username have same name but different case the execution file for username is not getting created reason being MacOS and windows have case insensitive file systems.
Because of that when running examples for username it picks up examples of userName instead and shows the deprecated console.warn.
Reference: nodejs/help#2116

Please suggest a way around this.

@matthewmayer
Copy link
Contributor

Great detective work!

@ST-DDT
Copy link
Member

ST-DDT commented Sep 23, 2024

You can use the following as a workaround:

function resolvePathToMethodFile(

function resolvePathToMethodFile(
  moduleName: string,
  methodName: string,
  signature: number
): string {
  const dir = resolveDirToModule(moduleName);

  // TODO @ST-DDT 2024-09-23: Remove this in v10
  if (methodName === 'userName') {
    methodName = 'userName2';
  }

  return resolve(dir, `${methodName}_${signature}.ts`);
}

src/modules/internet/index.ts Outdated Show resolved Hide resolved
src/modules/internet/index.ts Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/modules/internet/index.ts Outdated Show resolved Hide resolved
@matthewmayer
Copy link
Contributor

I noticed on
https://deploy-preview-3130.fakerjs.dev/api/

both username and userName link to https://deploy-preview-3130.fakerjs.dev/api/internet.html#username (as the hash fragments are lowercased)

@xDivisionByZerox
Copy link
Member

I noticed on deploy-preview-3130.fakerjs.dev/api

both username and userName link to deploy-preview-3130.fakerjs.dev/api/internet.html#username (as the hash fragments are lowercased)

For me it two different ones:

Am I missing something?

@matthewmayer
Copy link
Contributor

The links from the https://deploy-preview-3130.fakerjs.dev/api/ page both go to the same place.

@ST-DDT
Copy link
Member

ST-DDT commented Sep 25, 2024

The links from the https://deploy-preview-3130.fakerjs.dev/api/ page both go to the same place.

I pushed a fix that should solve that issue.

ST-DDT
ST-DDT previously approved these changes Sep 25, 2024
@ST-DDT ST-DDT requested review from matthewmayer and a team September 25, 2024 20:04
matthewmayer
matthewmayer previously approved these changes Sep 27, 2024
Shinigami92
Shinigami92 previously approved these changes Sep 27, 2024
import-brain
import-brain previously approved these changes Sep 27, 2024
@ST-DDT
Copy link
Member

ST-DDT commented Sep 27, 2024

Dear @suyashgulati,

Thank you for your patience and contributions so far. We wanted to provide you with a brief update.

We are pleased to inform you that we have addressed all the known bugs in version 9.0. We will now take a short break and resume work around October 7, 2024, to begin merging new features for v9.1, including yours.

In the meantime, we hope you have a great time, and we sincerely appreciate your ongoing support and contributions.

Best regards,
your FakerJS Team

@ST-DDT ST-DDT changed the title refactor(internet): Renaming userName method to username refactor(internet): rename userName method to username Oct 12, 2024
@ST-DDT ST-DDT enabled auto-merge (squash) October 12, 2024 22:48
@ST-DDT ST-DDT merged commit 34cf364 into faker-js:next Oct 12, 2024
25 checks passed
@ST-DDT
Copy link
Member

ST-DDT commented Oct 12, 2024

Thanks for your contribution.
This change will be included in the next faker release v9.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs deprecation A deprecation was made in the PR m: internet Something is referring to the internet module p: 1-normal Nothing urgent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename userName to username
6 participants