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

Fix: Use local venue data for development instead of prod data #3810

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion website/src/utils/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
return qs.parse(window.location.search);
}

function isLocalhost() {
return window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';

Check warning on line 12 in website/src/utils/debug.ts

View check run for this annotation

Codecov / codecov/patch

website/src/utils/debug.ts#L11-L12

Added lines #L11 - L12 were not covered by tests
}

Comment on lines +11 to +14
Copy link
Member

Choose a reason for hiding this comment

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

Would it be make sense to use NUSMODS_ENV instead?

// Snippet from src/types/global.d.ts

/**
 * NUSMods deployment environment.
 *
 * **Note:** although these environments may share the same name as
 * `NODE_ENV` and other envs, there are subtle differences. Definitions:
 *
 * - `production`: a production deployment of NUSMods, i.e. a deployment meant to
 *   be used by the general public.
 * - `staging`: a deployment of NUSMods's main development branch, which is
 *   not meant to be used by the general public but which may be promoted to
 *   production at any point.
 * - `preview`: a deployment of work-in-progress branches, e.g. PR deploy
 *   previews.
 * - `test`: we are in a test environment, e.g. a jest test run.
 * - `development`: all other situations.
 */
declare const NUSMODS_ENV: 'development' | 'production' | 'staging' | 'preview' | 'test';

// Force the 'new version available' refresh prompt to appear
export function forceRefreshPrompt() {
return getParams().refresh === '1';
Expand Down Expand Up @@ -40,6 +44,11 @@
return getParams().edit === '1';
}

// prodVenue query parameter allows the user to use production data instead of local data
// By default, on localhost, local data will be used
export function preferRepoVenues() {
return getParams().localVenue === '1';
// Don't use repo data in jest tests
if (process.env.JEST_WORKER_ID !== undefined) return false;
Copy link
Member

Choose a reason for hiding this comment

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

Using NUSMODS_ENV would allow checking for NUSMODS_ENV === 'test' as well.


return isLocalhost() && getParams().prodVenue !== '1';

Check warning on line 53 in website/src/utils/debug.ts

View check run for this annotation

Codecov / codecov/patch

website/src/utils/debug.ts#L53

Added line #L53 was not covered by tests
}