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

+7-4
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

+9,566-7,195
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
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

-1
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

+3-1
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

+2-2
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

+17-7
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

+3-2
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

-1
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

+1
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

src/constants.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/** @constant */
32
export const APP_TOPIC = 'APP';
43

@@ -65,4 +64,3 @@ export const APP_INIT_ERROR = `${APP_TOPIC}.INIT_ERROR`;
6564
export const CONFIG_TOPIC = 'CONFIG';
6665

6766
export const CONFIG_CHANGED = `${CONFIG_TOPIC}.CHANGED`;
68-

src/i18n/injectIntlWithShim.jsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import { getLoggingService } from './lib';
1010
*/
1111
const injectIntlWithShim = (WrappedComponent) => {
1212
class ShimmedIntlComponent extends React.Component {
13-
static propTypes = {
14-
intl: intlShape.isRequired,
15-
};
16-
1713
constructor(props) {
1814
super(props);
1915
this.shimmedIntl = Object.create(this.props.intl, {
@@ -39,8 +35,11 @@ const injectIntlWithShim = (WrappedComponent) => {
3935
}
4036
}
4137

38+
ShimmedIntlComponent.propTypes = {
39+
intl: intlShape.isRequired,
40+
};
41+
4242
return injectIntl(ShimmedIntlComponent);
4343
};
4444

45-
4645
export default injectIntlWithShim;

src/i18n/lib.test.js

+24-18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
import {
23
configure,
34
getPrimaryLanguageSubtag,
@@ -13,10 +14,15 @@ jest.mock('universal-cookie');
1314

1415
describe('lib', () => {
1516
describe('configure', () => {
16-
let warnSpy = null;
17+
let originalWarn = null;
1718

1819
beforeEach(() => {
19-
warnSpy = spyOn(console, 'warn');
20+
originalWarn = console.warn;
21+
console.warn = jest.fn();
22+
});
23+
24+
afterEach(() => {
25+
console.warn = originalWarn;
2026
});
2127

2228
it('should not call console.warn in production', () => {
@@ -33,7 +39,7 @@ describe('lib', () => {
3339
},
3440
});
3541

36-
expect(warnSpy).not.toHaveBeenCalled();
42+
expect(console.warn).not.toHaveBeenCalled();
3743
});
3844

3945
it('should warn about unexpected locales', () => {
@@ -61,7 +67,7 @@ describe('lib', () => {
6167
},
6268
});
6369

64-
expect(warnSpy).toHaveBeenCalledWith('Unexpected locale: uhoh');
70+
expect(console.warn).toHaveBeenCalledWith('Unexpected locale: uhoh');
6571
});
6672

6773
it('should warn about missing locales', () => {
@@ -74,20 +80,20 @@ describe('lib', () => {
7480
messages: {},
7581
});
7682

77-
expect(warnSpy).toHaveBeenCalledTimes(13);
78-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: ar');
79-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: es-419');
80-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: fr');
81-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: zh-cn');
82-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: ca');
83-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: he');
84-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: id');
85-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: ko-kr');
86-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: pl');
87-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: pt-br');
88-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: ru');
89-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: th');
90-
expect(warnSpy).toHaveBeenCalledWith('Missing locale: uk');
83+
expect(console.warn).toHaveBeenCalledTimes(13);
84+
expect(console.warn).toHaveBeenCalledWith('Missing locale: ar');
85+
expect(console.warn).toHaveBeenCalledWith('Missing locale: es-419');
86+
expect(console.warn).toHaveBeenCalledWith('Missing locale: fr');
87+
expect(console.warn).toHaveBeenCalledWith('Missing locale: zh-cn');
88+
expect(console.warn).toHaveBeenCalledWith('Missing locale: ca');
89+
expect(console.warn).toHaveBeenCalledWith('Missing locale: he');
90+
expect(console.warn).toHaveBeenCalledWith('Missing locale: id');
91+
expect(console.warn).toHaveBeenCalledWith('Missing locale: ko-kr');
92+
expect(console.warn).toHaveBeenCalledWith('Missing locale: pl');
93+
expect(console.warn).toHaveBeenCalledWith('Missing locale: pt-br');
94+
expect(console.warn).toHaveBeenCalledWith('Missing locale: ru');
95+
expect(console.warn).toHaveBeenCalledWith('Missing locale: th');
96+
expect(console.warn).toHaveBeenCalledWith('Missing locale: uk');
9197
});
9298
});
9399

src/initialize.js

+25-7
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,33 @@ import { createBrowserHistory, createMemoryHistory } from 'history';
4949
import {
5050
publish,
5151
} from './pubSub';
52+
// eslint-disable-next-line import/no-cycle
53+
import { getConfig } from './config';
5254
import {
53-
getConfig,
54-
} from './config';
55-
import { configure as configureLogging, getLoggingService, NewRelicLoggingService, logError } from './logging';
56-
import { configure as configureAnalytics, SegmentAnalyticsService, identifyAnonymousUser, identifyAuthenticatedUser } from './analytics';
57-
import { getAuthenticatedHttpClient, configure as configureAuth, ensureAuthenticatedUser, fetchAuthenticatedUser, hydrateAuthenticatedUser, getAuthenticatedUser, AxiosJwtAuthService } from './auth';
55+
configure as configureLogging, getLoggingService, NewRelicLoggingService, logError,
56+
} from './logging';
57+
import {
58+
configure as configureAnalytics, SegmentAnalyticsService, identifyAnonymousUser, identifyAuthenticatedUser,
59+
} from './analytics';
60+
import {
61+
getAuthenticatedHttpClient,
62+
configure as configureAuth,
63+
ensureAuthenticatedUser,
64+
fetchAuthenticatedUser,
65+
hydrateAuthenticatedUser,
66+
getAuthenticatedUser,
67+
AxiosJwtAuthService,
68+
} from './auth';
5869
import { configure as configureI18n } from './i18n';
59-
import { APP_PUBSUB_INITIALIZED, APP_CONFIG_INITIALIZED, APP_AUTH_INITIALIZED, APP_I18N_INITIALIZED, APP_LOGGING_INITIALIZED, APP_ANALYTICS_INITIALIZED, APP_READY, APP_INIT_ERROR } from './constants';
70+
import {
71+
APP_PUBSUB_INITIALIZED,
72+
APP_CONFIG_INITIALIZED,
73+
APP_AUTH_INITIALIZED,
74+
APP_I18N_INITIALIZED,
75+
APP_LOGGING_INITIALIZED,
76+
APP_ANALYTICS_INITIALIZED,
77+
APP_READY, APP_INIT_ERROR,
78+
} from './constants';
6079

6180
/**
6281
* A browser history or memory history object created by the [history](https://github.com/ReactTraining/history)
@@ -109,7 +128,6 @@ export async function auth(requireUser, hydrateUser) {
109128
}
110129
}
111130

112-
113131
/**
114132
* The default handler for the initialization lifecycle's `analytics` phase.
115133
*

src/initialize.test.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,21 @@ import {
1212
import { initialize } from './initialize';
1313
import { subscribe } from './pubSub';
1414

15-
import { configure as configureLogging, NewRelicLoggingService, getLoggingService, logError } from './logging';
16-
import { configure as configureAuth, getAuthenticatedHttpClient, ensureAuthenticatedUser, fetchAuthenticatedUser, hydrateAuthenticatedUser, getAuthenticatedUser, AxiosJwtAuthService } from './auth';
15+
import {
16+
configure as configureLogging,
17+
NewRelicLoggingService,
18+
getLoggingService,
19+
logError,
20+
} from './logging';
21+
import {
22+
configure as configureAuth,
23+
getAuthenticatedHttpClient,
24+
ensureAuthenticatedUser,
25+
fetchAuthenticatedUser,
26+
hydrateAuthenticatedUser,
27+
getAuthenticatedUser,
28+
AxiosJwtAuthService,
29+
} from './auth';
1730
import { configure as configureAnalytics, SegmentAnalyticsService } from './analytics';
1831
import { configure as configureI18n } from './i18n';
1932
import { getConfig } from './config';

src/logging/NewRelicLoggingService.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ function fixErrorLength(error) {
1010
const processedError = Object.create(error);
1111
processedError.message = processedError.message.substring(0, MAX_ERROR_LENGTH);
1212
return processedError;
13-
} else if (typeof error === 'string' && error.length > MAX_ERROR_LENGTH) {
13+
}
14+
if (typeof error === 'string' && error.length > MAX_ERROR_LENGTH) {
1415
return error.substring(0, MAX_ERROR_LENGTH);
1516
}
1617
return error;
@@ -58,7 +59,7 @@ export default class NewRelicLoggingService {
5859
}
5960
/* istanbul ignore else */
6061
if (window && typeof window.newrelic !== 'undefined') {
61-
window.newrelic.addPageAction('INFO', Object.assign({}, { message }, customAttributes));
62+
window.newrelic.addPageAction('INFO', { message, ...customAttributes });
6263
}
6364
}
6465

src/logging/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
export { getLoggingService, resetLoggingService, configure, logInfo, logError } from './interface';
1+
export {
2+
getLoggingService,
3+
resetLoggingService,
4+
configure,
5+
logInfo,
6+
logError,
7+
} from './interface';
28
export { default as NewRelicLoggingService } from './NewRelicLoggingService';

src/pubSub.js

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import PubSub from 'pubsub-js';
2121

22-
2322
/**
2423
*
2524
* @param {string} type

0 commit comments

Comments
 (0)