Skip to content

Commit 05e4acb

Browse files
authored
fix: bumping version of frontend-build to latest (#122)
* fix: bumping version of frontend-build to latest Also opportunistically removing a strange script tag loading ‘index.js’ in the example app, which doesn’t work. * fix: linting because of @edx/eslint-config The linting needs to happen because @edx/frontend-build was updated to use the new @edx/eslint-config. * fix: updating tests because of new jest version Updating to the latest @edx/frontend-build has brought with it some updated versions of jest, which caused some of our tests to break. This fixes them. * fix: pegging version of frontend-build. * fix: further linting errors after rebase
1 parent db03e2b commit 05e4acb

25 files changed

+9699
-7266
lines changed

example/index.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import 'babel-polyfill'; // eslint-disable-line import/no-extraneous-dependencie
22

33
import React from 'react';
44
import ReactDOM from 'react-dom';
5-
import { AppProvider, AuthenticatedPageRoute, ErrorPage, PageRoute } from '@edx/frontend-platform/react';
5+
import {
6+
AppProvider,
7+
AuthenticatedPageRoute,
8+
ErrorPage,
9+
PageRoute,
10+
} from '@edx/frontend-platform/react';
611
import { APP_INIT_ERROR, APP_READY, initialize } from '@edx/frontend-platform';
712
import { subscribe } from '@edx/frontend-platform/pubSub';
813

@@ -17,9 +22,7 @@ subscribe(APP_READY, () => {
1722
<PageRoute
1823
exact
1924
path="/error_example"
20-
component={() =>
21-
<ErrorPage message="Test error message" />
22-
}
25+
component={() => <ErrorPage message="Test error message" />}
2326
/>
2427
<AuthenticatedPageRoute exact path="/authenticated" component={AuthenticatedPage} />
2528
</AppProvider>,

package-lock.json

Lines changed: 9566 additions & 7195 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"devDependencies": {
3434
"@commitlint/cli": "8.2.0",
3535
"@commitlint/config-angular": "8.2.0",
36-
"@edx/frontend-build": "2.0.6",
36+
"@edx/frontend-build": "5.3.2",
3737
"@edx/paragon": "7.1.5",
3838
"axios-mock-adapter": "1.17.0",
3939
"babel-polyfill": "6.26.0",

public/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
</head>
88
<body>
99
<div id="root"></div>
10-
<script src="./index.js"></script>
1110
</body>
1211
</html>

src/analytics/SegmentAnalyticsService.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class SegmentAnalyticsService {
2525
const { analytics } = global;
2626

2727
// If the real analytics.js is already on the page return.
28-
if (analytics.initialize) return;
28+
if (analytics.initialize) {
29+
return;
30+
}
2931

3032
// If the snippet was invoked do nothing.
3133
if (analytics.invoked) {

src/auth/AxiosJwtAuthService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ class AxiosJwtAuthService {
197197
await this.fetchAuthenticatedUser();
198198

199199
if (this.getAuthenticatedUser() === null) {
200-
const isRedirectFromLoginPage = global.document.referrer &&
201-
global.document.referrer.startsWith(this.config.LOGIN_URL);
200+
const isRedirectFromLoginPage = global.document.referrer
201+
&& global.document.referrer.startsWith(this.config.LOGIN_URL);
202202

203203
if (isRedirectFromLoginPage) {
204204
const redirectLoopError = new Error('Redirect from login page. Rejecting to avoid infinite redirect loop.');

src/auth/AxiosJwtAuthService.test.jsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ Object.keys(jwtTokens).forEach((jwtTokenName) => {
7878
const mockCsrfToken = 'thetokenvalue';
7979
const mockApiEndpointPath = `${process.env.BASE_URL}/api/v1/test`;
8080

81-
window.location.assign = jest.fn();
81+
global.location = { ...global.location, assign: jest.fn() };
82+
8283
const mockCookies = new Cookies();
8384

8485
let service = null;
@@ -106,16 +107,15 @@ const setJwtTokenRefreshResponseTo = (status, jwtCookieValue) => {
106107
});
107108
};
108109

109-
110110
function expectLogout(redirectUrl = process.env.BASE_URL) {
111111
const encodedRedirectUrl = encodeURIComponent(redirectUrl);
112-
expect(window.location.assign)
112+
expect(global.location.assign)
113113
.toHaveBeenCalledWith(`${process.env.LOGOUT_URL}?redirect_url=${encodedRedirectUrl}`);
114114
}
115115

116116
function expectLogin(redirectUrl = process.env.BASE_URL) {
117117
const encodedRedirectUrl = encodeURIComponent(redirectUrl);
118-
expect(window.location.assign)
118+
expect(global.location.assign)
119119
.toHaveBeenCalledWith(`${process.env.LOGIN_URL}?next=${encodedRedirectUrl}`);
120120
}
121121

@@ -158,6 +158,8 @@ const expectRequestToHaveCsrfToken = (request) => {
158158
expect(request.headers['X-CSRFToken']).toEqual(mockCsrfToken);
159159
};
160160

161+
const { location } = global;
162+
161163
beforeEach(() => {
162164
service = new AxiosJwtAuthService(authOptions);
163165
accessTokenAxios = service.getJwtTokenService().getHttpClient();
@@ -174,7 +176,11 @@ beforeEach(() => {
174176
accessTokenAxiosMock.reset();
175177
csrfTokensAxiosMock.reset();
176178
mockCookies.get.mockReset();
177-
window.location.assign.mockReset();
179+
delete global.location;
180+
global.location = {
181+
assign: jest.fn(),
182+
origin: 'http://localhost',
183+
};
178184
mockLoggingService.logInfo.mockReset();
179185
mockLoggingService.logError.mockReset();
180186
service.getCsrfTokenService().clearCsrfTokenCache();
@@ -189,6 +195,10 @@ beforeEach(() => {
189195
accessTokenAxios.defaults.maxRetries = 0;
190196
});
191197

198+
afterEach(() => {
199+
global.location = location;
200+
});
201+
192202
describe('getAuthenticatedHttpClient', () => {
193203
beforeEach(() => {
194204
console.error = jest.fn();
@@ -512,7 +522,7 @@ describe('authenticatedHttpClient usage', () => {
512522
it(`${method.toUpperCase()}: does not redirect to login`, () => {
513523
return client[method](mockApiEndpointPath).then(() => {
514524
expectSingleCallToJwtTokenRefresh();
515-
expect(window.location.assign).not.toHaveBeenCalled();
525+
expect(global.location.assign).not.toHaveBeenCalled();
516526
});
517527
});
518528
});
@@ -732,7 +742,7 @@ describe('ensureAuthenticatedUser', () => {
732742
expect.hasAssertions();
733743
return service.ensureAuthenticatedUser().catch(() => {
734744
expectSingleCallToJwtTokenRefresh();
735-
expect(window.location.assign).not.toHaveBeenCalled();
745+
expect(global.location.assign).not.toHaveBeenCalled();
736746
expectLogFunctionToHaveBeenCalledWithMessage(
737747
mockLoggingService.logError.mock.calls[0],
738748
'[frontend-auth] Redirect from login page. Rejecting to avoid infinite redirect loop.',

src/auth/MockAuthService.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ class MockAuthService {
138138

139139
// Mock user
140140
this.authenticatedUser = this.config.authenticatedUser ? this.config.authenticatedUser : null;
141-
this.hydratedAuthenticatedUser = this.config.hydratedAuthenticatedUser ?
142-
this.config.hydratedAuthenticatedUser : {};
141+
this.hydratedAuthenticatedUser = this.config.hydratedAuthenticatedUser
142+
? this.config.hydratedAuthenticatedUser
143+
: {};
143144

144145
this.authenticatedHttpClient = axios.create();
145146
this.httpClient = axios.create();

src/auth/interface.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ export async function hydrateAuthenticatedUser() {
245245
publish(AUTHENTICATED_USER_CHANGED);
246246
}
247247

248-
249248
/**
250249
* @name AuthService
251250
* @interface

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
import { APP_CONFIG_INITIALIZED, CONFIG_CHANGED } from './constants';
28+
2829
import { publish, subscribe } from './pubSub';
2930
import { ensureDefinedConfig } from './utils';
3031

0 commit comments

Comments
 (0)