Skip to content

Commit

Permalink
fix: replace remaining process.env reference
Browse files Browse the repository at this point in the history
OKTA-465286
<<<Jenkins Check-In of Tested SHA: e163b1a for eng_productivity_ci_bot_okta@okta.com>>>
Artifact: okta-react
Files changed count: 7
PR Link: "#203"
  • Loading branch information
oleksandrpravosudko-okta authored and eng-prod-CI-bot-okta committed Jan 28, 2022
1 parent 4442e6e commit 31469df
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [#199](https://github.com/okta/okta-react/pull/199) Fixes okta-auth-js peer dependency error
- [#200](https://github.com/okta/okta-react/pull/200) Fixes: Typescript types when using `react-router-dom` v6 with `okta-react`
- [#201](https://github.com/okta/okta-react/pull/201) Removes `process.env` reference from the bundles

# 6.4.1

Expand Down
5 changes: 0 additions & 5 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ const path = require('path');
const dotenv = require('dotenv');
const fs = require('fs');

// Read information from package.json and expose as environment variables
const PACKAGE = require('./package.json');
process.env.PACKAGE_NAME = PACKAGE.name;
process.env.PACKAGE_VERSION = PACKAGE.version;

// Read environment variables from "testenv". Override environment vars if they are already set.
const TESTENV = path.resolve(__dirname, 'testenv');
if (fs.existsSync(TESTENV)) {
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module.exports = {
],
globals: {
AUTH_JS: { minSupportedVersion: '5.3.1' },
PACKAGE_NAME: 'okta-react-test',
PACKAGE_VERSION: '3.14.15',
SKIP_VERSION_CHECK: '1',
'ts-jest': {
diagnostics: {
warnOnly: true
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "yarn lint && yarn test:unit && yarn test:e2e",
"test:e2e": "yarn workspace @okta/okta-react-test-harness test",
"test:e2e:samples": "yarn workspace @okta/test.e2e-samples test",
"test:unit": "SKIP_VERSION_CHECK=1 jest",
"test:unit": "jest",
"bundle": "rollup -c",
"dev": "yarn bundle --watch",
"generate": "yarn workspace @okta/generator generate",
Expand Down
5 changes: 3 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ const commonPlugins = [
useTsconfigDeclarationDir: true
}),
replace({
'process.env.PACKAGE_NAME': JSON.stringify(process.env.PACKAGE_NAME),
'process.env.PACKAGE_VERSION': JSON.stringify(process.env.PACKAGE_VERSION),
'PACKAGE_NAME': JSON.stringify(pkg.name),
'PACKAGE_VERSION': JSON.stringify(pkg.version),
'SKIP_VERSION_CHECK': '0',
'AUTH_JS': JSON.stringify({
minSupportedVersion: '5.3.1'
})
Expand Down
9 changes: 7 additions & 2 deletions src/Security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ declare const AUTH_JS: {
minSupportedVersion: string;
}

declare const PACKAGE_NAME: string;
declare const PACKAGE_VERSION: string;
declare const SKIP_VERSION_CHECK: string;

const Security: React.FC<{
oktaAuth: OktaAuth,
restoreOriginalUri: RestoreOriginalUriFunction,
Expand Down Expand Up @@ -53,7 +57,7 @@ const Security: React.FC<{

// Add okta-react userAgent
if (oktaAuth._oktaUserAgent) {
oktaAuth._oktaUserAgent.addEnvironment(`${process.env.PACKAGE_NAME}/${process.env.PACKAGE_VERSION}`);
oktaAuth._oktaUserAgent.addEnvironment(`${PACKAGE_NAME}/${PACKAGE_VERSION}`);
} else {
console.warn('_oktaUserAgent is not available on auth SDK instance. Please use okta-auth-js@^5.3.1 .');
}
Expand Down Expand Up @@ -88,7 +92,8 @@ const Security: React.FC<{
}
else {
// use SKIP_VERSION_CHECK flag to control version check in tests
const isAuthJsSupported = process.env.SKIP_VERSION_CHECK === '1' ||
// OKTA-465157: remove SKIP_VERSION_CHECK
const isAuthJsSupported = SKIP_VERSION_CHECK === '1' ||
compareVersions(oktaAuth._oktaUserAgent.getVersion(), AUTH_JS.minSupportedVersion, '>=');
if (!isAuthJsSupported) {
const err = new AuthSdkError(`
Expand Down
9 changes: 6 additions & 3 deletions test/jest/security.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ describe('<Security />', () => {
restoreOriginalUri
};
mount(<Security {...mockProps} />);
expect(addEnvironmentSpy).toBeCalledWith(`${process.env.PACKAGE_NAME}/${process.env.PACKAGE_VERSION}`);
// package name and version defined in jest.config.js
expect(addEnvironmentSpy).toBeCalledWith(`okta-react-test/3.14.15`);
});

it('logs a warning in case _oktaUserAgent is not available on auth SDK instance', () => {
Expand All @@ -77,7 +78,8 @@ describe('<Security />', () => {

// turn off SKIP_VERSION_CHECK to test the functionality
beforeEach(() => {
process.env.SKIP_VERSION_CHECK = '0';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
SKIP_VERSION_CHECK = '0';

originalConsole = global.console;
global.console = {
Expand All @@ -86,7 +88,8 @@ describe('<Security />', () => {
};
});
afterEach(() => {
process.env.SKIP_VERSION_CHECK = '1';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
SKIP_VERSION_CHECK = '1';
global.console = originalConsole;
});
it('throws runtime error when passed in authJS version is too low', () => {
Expand Down

0 comments on commit 31469df

Please sign in to comment.