Skip to content

Commit

Permalink
Merge pull request #56 from fabscale/fn/test-waiter
Browse files Browse the repository at this point in the history
feat: Add test waiters to ensure everything is settled
  • Loading branch information
mydea authored Aug 3, 2021
2 parents 34f5a7d + ba013c3 commit 75c21f7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/ember-l10n/addon/services/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
import fetch from 'fetch';
import { detectLocale } from '@ember-gettext/ember-l10n/utils/detect-locale';
import { PluralFactory } from '@ember-gettext/ember-l10n/utils/plural-factory';
import { buildWaiter } from '@ember/test-waiters';

const waiter = buildWaiter('ember-l10n:l10n');

// We cache locales - this is useful to avoid re-fetching the locale files e.g. in acceptance tests
const LOCALE_CACHE = {};
Expand Down Expand Up @@ -172,10 +175,13 @@ export default class L10nService extends Service {
Boolean(localePath)
);

let token = waiter.beginAsync();

try {
localeData = await this._fetch(localePath);
} catch (error) {
console.error(`ember-l10n: Error trying to fetch locale ${locale}`);
waiter.endAsync(token);
throw error;
}

Expand All @@ -187,6 +193,8 @@ export default class L10nService extends Service {
this.pluralFactory = new PluralFactory(locale);

LOCALE_CACHE[locale] = l10nTranslations;

waiter.endAsync(token);
}

async _fetch(localePath) {
Expand Down
1 change: 1 addition & 0 deletions packages/ember-l10n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"test:ember-compatibility": "ember try:each"
},
"dependencies": {
"@ember/test-waiters": "^2.4.5",
"@glimmer/component": "^1.0.4",
"@glimmer/tracking": "^1.0.4",
"broccoli-funnel": "^3.0.8",
Expand Down
13 changes: 12 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,17 @@
ember-cli-version-checker "^5.1.2"
semver "^7.3.2"

"@ember/test-waiters@^2.4.5":
version "2.4.5"
resolved "https://registry.yarnpkg.com/@ember/test-waiters/-/test-waiters-2.4.5.tgz#6e8e34d1bc46a9b0cc22cb11cc5936046e926031"
integrity sha512-833JvHtHdEfBfKXgvmw+6oziFOpVfD4NQrc04Ztj59A11K9FPNfZ3P8YydL7LFTtdd7UfJ/cYCLAm+OwUxbotQ==
dependencies:
calculate-cache-key-for-tree "^2.0.0"
ember-cli-babel "^7.26.6"
ember-cli-typescript "^4.1.0"
ember-cli-version-checker "^5.1.2"
semver "^7.3.5"

"@embroider/[email protected]", "@embroider/core@^0.33.0":
version "0.33.0"
resolved "https://registry.yarnpkg.com/@embroider/core/-/core-0.33.0.tgz#0fb1752d6e34ea45368e65c42e13220a57ffae76"
Expand Down Expand Up @@ -11413,7 +11424,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e"
integrity sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==

[email protected], semver@^7.1.3, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4:
[email protected], semver@^7.1.3, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
version "7.3.5"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
Expand Down

0 comments on commit 75c21f7

Please sign in to comment.