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

Generator creates a project with a singe-locale #325

Merged
merged 27 commits into from
Jan 25, 2022

Conversation

adamraya
Copy link
Collaborator

@adamraya adamraya commented Jan 18, 2022

GUS: https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07EE00000TshIdYAJ/view

Description

The PWA Kit now supports multiple locales, but we want the generator to create a simplified project configured to use only a single locale. Users will be able to add multiple locales supported by PWA KIt by following the provided documentation.

This PR updates the generator script create-mobify-app.js to generate a project with the en-US locale and the RefArch siteId .

Since we'll work only with one locale, the URL configuration locale type for the generated project it's set to 'none' in the pwa-kit.config.js file. This removes the locale shortcode from the URL.

A lot of tests have been updated since they were using the hardcoded locale en-GB and thus all these tests were failing on a generated project using the single locale en-US.
These tests now use the locale defined as defaultLocale in package.json and follow the configuration set in the URL configuration locale type on the pwa-kit.config.js file to determine if the locale shortcode should be included in the URL pathname.

Note: I decided to copy the content of the en-GB translations to the en-US translation since we need the strings for the default language to render the app.
Once we have the real en-US translation, we'll need to update the content of the en-US file.

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • Updated generator to create a project with the single locale en-US and the locale type URL configuration set to none.
  • Fixed a lot of tests with the hardcoded locale en-GB.

How to Test-Drive This PR

  • Checkout this branch generator-single-site-singe-locale.
  • Run npm ci.
  • Generate a project locally by running the create-mobify-app.js script:
GENERATOR_PRESET=test-project node packages/pwa-kit-create-app/scripts/create-mobify-app-dev.js --outputDir /tmp/project

Verify

  1. Start the generated project npm start.
  2. Navigate through the app verifying that locale en-US is used, the data is from theRefArch siteId and the locale shortcode is not being displayed in the URL.
  3. Confirm the l10n settings in the generated project package.json look like this:
"l10n": {
    "supportedCurrencies": [
      "USD"
    ],
    "defaultCurrency": "USD",
    "supportedLocales": [
      {
        "id": "en-US",
        "preferredCurrency": "USD"
      }
    ],
    "defaultLocale": "en-US"
  }
  1. Also confirm the URL configuration for the locale type in the pwa-kit.config.js file looks like this:
{
  "url": {
    "locale": "none"
  }
}

Run tests

  • All tests pass for the PWA: npm run test --prefix packages/pwa
  • The same tests pass for the generated project: npm run test

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@adamraya adamraya requested a review from a team as a code owner January 18, 2022 00:48
@adamraya adamraya added the ready for review PR is ready to be reviewed label Jan 18, 2022
@vcua-mobify
Copy link
Contributor

It looks like some of the CI tests are failing because they are hard coded to expect /en-GB as part of the url. We'll need to update the tests to be locale agnostic

@adamraya
Copy link
Collaborator Author

It looks like some of the CI tests are failing because they are hard coded to expect /en-GB as part of the url. We'll need to update the tests to be locale agnostic

Yeah, I saw that. I'll work on updating those tests tomorrow.

@adamraya adamraya added wip Work in process and removed ready for review PR is ready to be reviewed labels Jan 18, 2022
@vmarta
Copy link
Contributor

vmarta commented Jan 19, 2022

@adamraya It looks like you're still working on this PR. Pls let me know when it's ready for review, thanks.

@adamraya adamraya added ready for review PR is ready to be reviewed and removed wip Work in process labels Jan 20, 2022
@adamraya
Copy link
Collaborator Author

@adamraya It looks like you're still working on this PR. Pls let me know when it's ready for review, thanks.

Yeah, sorry, we had a bunch of tests with the locale hardcoded that started to fail.

The tests are passing now. The PR is ready for review @vmarta.

@adamraya adamraya changed the title Generator creates a project with a single-site and a singe-locale Generator creates a project with a singe-locale Jan 20, 2022
// Otherwise, our code would fall back to default and incorrectly pass the tests
const supportedLocale = supportedLocales[1]

const supportedLocale = supportedLocales[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 hmm, this test file assumes that it's working with a multi-locale setup.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that we have updated the tests such that they would pass for both the pwa and the generated pwa project. But since the two have deviated from each other (one is a multi-locale site, while the other one is now a single locale), the tests can be more tricky to write and may not be clear to new developers.

How about we consider not running the tests for the generated project?

- runtests:
cwd: /tmp/project

Copy link
Collaborator Author

@adamraya adamraya Jan 21, 2022

Choose a reason for hiding this comment

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

The generated project is our final most crucial product shipped to customers.
I think it is vital for us to run tests on the code that we hand to customers to make sure that the code they use as starting point works as expected.

The final transient dependencies installed in a generated project can be different from the set of dependencies installed in the PWA, they end up being different projects, thus in my opinion we still need to run tests on both.

You're right that writing tests that work for a single-locale and multi-locale setup can be harder to write.

Let me see what I can do on that particular test file to cover both single-locale and multi-locale scenarios in a simpler way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I restored the original functionality on these tests and added a conditional with values for the specific single locale scenario.

Comment on lines 301 to 319
const pkgSingleLocaleData = {
l10n: {
supportedCurrencies: ['USD'],
defaultCurrency: 'USD',
supportedLocales: [
{
id: 'en-US',
preferredCurrency: 'USD'
}
],
defaultLocale: 'en-US'
}
}

const PWAKitConfigSingleLocaleData = {
url: {
locale: 'none'
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How about extracting these config-related objects into files in the folder 'packages/pwa-kit-create-app/assets/'? The ticket asks about creating files in that asset folder. It may be better to group all the files together in the same location.

Copy link
Collaborator Author

@adamraya adamraya Jan 21, 2022

Choose a reason for hiding this comment

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

Good call! I didn't know that we added an /assets folder to the generator and I missed that implementation detail.

Done, now the configuration objects are in files inside the assets folder.

@sejal-salesforce
Copy link
Contributor

@adamraya The steps to testdrive PR confused me, so I want to confirm the behavior here. The default project = when no preset is given to npx pwa-kit-create-app. Is that right?

@adamraya
Copy link
Collaborator Author

adamraya commented Jan 21, 2022

https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07EE00000TshIdYAJ/view

@sejal-salesforce Yes, with these changes, running the generator using npx pwa-kit-create-app will generate a project with a single locale.

However, the ticket doesn't refer to presets at all.
If we want to generate a project with a different locale configuration based on presets, that will be out of scope for this ticket and we'll need to address that work in a new ticket.

We can not test the changes using npx pwa-kit-create-app until we release the changes to NPM. The equivalent command to run the generator locally from the root of the monorepo is:

GENERATOR_PRESET=test-project node packages/pwa-kit-create-app/scripts/create-mobify-app-dev.js --outputDir /tmp/project

The command uses the test-project preset just to automate filling the generator questions with the default answers.

This PR doesn't change the questions/answers or the presets.

Copy link
Contributor

@vmarta vmarta left a comment

Choose a reason for hiding this comment

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

Thanks for the latest changes. They look good. I also tested generating a project locally and running it. It's good too.

@adamraya adamraya merged commit a3834ea into develop Jan 25, 2022
@vcua-mobify vcua-mobify mentioned this pull request Jan 26, 2022
12 tasks
@adamraya adamraya deleted the generator-single-site-singe-locale branch January 29, 2022 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants