process.env can't find terminal environmental variables when running IOS/Android - react-native

Variables defined in .env file are not showing up in process.env (in babel.config.js as well as in index.tsx)
.env:
ENV_VAR1=testabc
ENV_VAR2=testdef
babel.config:
console.log(process.env);
module.exports = {
....
Terminal:
user#Users-MacBook-Pro react_frontend % yarn start --reset-cache
warning: Obfuscation SKIPPED [Not a *bundle* command]
▒▒▓▓▓▓▒▒
▒▓▓▓▒▒░░▒▒▓▓▓▒
▒▓▓▓▓░░░▒▒▒▒░░░▓▓▓▓▒
▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓
▓▓░░░░░▒▓▓▓▓▓▓▒░░░░░▓▓
▓▓░░▓▓▒░░░▒▒░░░▒▓▒░░▓▓
▓▓░░▓▓▓▓▓▒▒▒▒▓▓▓▓▒░░▓▓
▓▓░░▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░▓▓
▓▓▒░░▒▒▓▓▓▓▓▓▓▓▒░░░▒▓▓
▒▓▓▓▒░░░▒▓▓▒░░░▒▓▓▓▒
▒▓▓▓▒░░░░▒▓▓▓▒
▒▒▓▓▓▓▒▒
warning: the transform cache was reset.
Welcome to Metro v0.72.3
Fast - Scalable - Integrated
To reload the app press "r"
To open developer menu press "d"
user#Users-MacBook-Pro react_frontend % source .env && echo $ENV_VAR1 && npx react-native run-android
testabc
info Starting JS server...
info Installing the app...
Metro terminal:
...
transform[stdout]: {
transform[stdout]: MANPATH: '/opt/homebrew/share/man::',
transform[stdout]: rvm_bin_path: '/Users/xxxxxx/.rvm/bin',
transform[stdout]: VIRTUALENVWRAPPER_SCRIPT: '/opt/homebrew/bin/virtualenvwrapper.sh',
transform[stdout]: VIRTUALENVWRAPPER_PROJECT_FILENAME: '.project',
transform[stdout]: TERM_PROGRAM: 'Apple_Terminal',
transform[stdout]: GEM_HOME: '/Users/xxxxxx/.rvm/gems/ruby-3.0.0',
transform[stdout]: ANDROID_HOME: '/Users/xxxxx/Library/Android/sdk',
transform[stdout]: SHELL: '/bin/zsh',
transform[stdout]: TERM: 'xterm-256color',
transform[stdout]: IRBRC: '/Users/xxxxxxx/.rvm/rubies/ruby-3.0.0/.irbrc',
transform[stdout]: HOMEBREW_REPOSITORY: '/opt/homebrew',
transform[stdout]: TMPDIR: '/var/folders/nq/_9bt81g17cj0036184j_gxrw0000gn/T/',
transform[stdout]: TERM_PROGRAM_VERSION: '447',
transform[stdout]: MY_RUBY_HOME: '/Users/xxxx/.rvm/rubies/ruby-3.0.0',
transform[stdout]: TERM_SESSION_ID: 'xxxxxx',
transform[stdout]: JENV_FORCEJAVAHOME: 'true',
transform[stdout]: USER: 'xxxxx',
transform[stdout]: rvm_path: '/Users/xxxxxx/.rvm',
transform[stdout]: SSH_AUTH_SOCK: '/xxxxxx',
transform[stdout]: PODS_ROOT: '/xxxxx/node_modules/react-native/scripts/../../../ios/Pods',
transform[stdout]: WORKON_HOME: '/Users/xxxxx/.virtualenvs',
transform[stdout]: rvm_prefix: '/Users/xxxxxx',
transform[stdout]: VIRTUALENVWRAPPER_PYTHON: '/opt/homebrew/bin/python3.10',
transform[stdout]: PATH: 'xxxxxxx',
transform[stdout]: VIRTUALENVWRAPPER_HOOK_DIR: '/Users/xxxxxx/.virtualenvs',
transform[stdout]: __CFBundleIdentifier: 'com.apple.Terminal',
transform[stdout]: JENV_LOADED: '1',
transform[stdout]: PWD: '/Users/xxxx/Desktop/xxxx/xxxx/xxxxx',
transform[stdout]: JAVA_HOME: '/Users/xxxxx/.jenv/versions/11.0.17',
transform[stdout]: XPC_FLAGS: '0x0',
transform[stdout]: VIRTUALENVWRAPPER_VIRTUALENV: '/opt/homebrew/bin/virtualenv',
transform[stdout]: RCT_METRO_PORT: '8081',
transform[stdout]: JENV_FORCEJDKHOME: 'true',
transform[stdout]: XPC_SERVICE_NAME: 'xxxxx',
transform[stdout]: rvm_version: '1.29.12 (latest)',
transform[stdout]: JDK_HOME: '/Users/xxxxx/.jenv/versions/11.0.17',
transform[stdout]: SHLVL: '2',
transform[stdout]: HOME: '/Users/xxxxxx',
transform[stdout]: HOMEBREW_PREFIX: '/opt/homebrew',
transform[stdout]: LOGNAME: 'xxxxxxx',
transform[stdout]: JENV_SHELL: 'zsh',
transform[stdout]: LC_CTYPE: 'UTF-8',
transform[stdout]: GEM_PATH: '/Users/xxxxxx/.rvm/gems/ruby-3.0.0:/Users/xxxxxxx/.rvm/gems/ruby-3.0.0#global',
transform[stdout]: NODE_BINARY: '/opt/homebrew/Cellar/node/19.4.0_1/bin/node',
transform[stdout]: VIRTUALENVWRAPPER_WORKON_CD: '1',
transform[stdout]: INFOPATH: '/opt/homebrew/share/info:',
transform[stdout]: HOMEBREW_CELLAR: '/opt/homebrew/Cellar',
transform[stdout]: RUBY_VERSION: 'ruby-3.0.0',
transform[stdout]: OLDPWD: '/Users/xxxx',
transform[stdout]: _: '/opt/homebrew/Cellar/node/19.4.0_1/bin/node',
transform[stdout]: __CF_USER_TEXT_ENCODING: 'xxxxxx',
transform[stdout]: FORCE_COLOR: '1',
transform[stdout]: BABEL_ENV: 'xxxxxx'
transform[stdout]: }

fix:
yarn add dotenv --dev
babel.config file:
require('dotenv').config();
console.log(process.env);
module.exports = {
....
answer: https://stackoverflow.com/a/61442921/9611924

Related

Testcafe runs on average 2-3 times slower when using SSL

After installing and using a self-signed SSL certificate by following the official guide here and running our test suites it was discovered that the tests take about 3 times as long. I would expect there to maybe be some sort of delay but that's a lot.
Any ideas on why this is the case?
With SSL: 45 passed (6m 56s)
Without SSL: 45 passed (2m 55s)
.testcaferc.js File
let filtered_tests = [
// Located in editor_page_tests.js
'user_is_able_to_add_a_section_column_row_and_element_to_editor',
'pop_up_element_displays_during_page_preview',
'clicking_button_shows_hides_elements',
'user_is_able_to_save_when_adding_a_video',
'user_is_able_to_save_when_leaving_video_embed_blank',
// Located in courses_page_tests.js
'user_can_preview_existing_course',
'optin_user_can_navigate_through_course',
'manually_added_user_can_navigate_through_course',
// Located in funnels_page_tests.js
'user_can_navigate_through_funnel',
// Located in developer_portal_page_tests.js
'user_can_navigate_to_developer_portal_page',
// Located in members_page_tests.js
'user_can_navigate_to_team_members_page',
// Located in teams_dashboard_pages_tests.js
'user_can_navigate_to_team_dashboard_page',
// Located in workspaces_page_tests.js
'user_can_navigate_to_team_workspaces_page'
]
let isolated_tests = [
// Located in sites_overview_page_tests.js
'user_can_make_site_public',
'user_can_edit_site_name',
'user_can_make_site_password_protected',
'user_can_make_site_private',
'user_can_edit_site_domain',
'changing_site_domain_updates_funnel_urls',
// Located in account_details_page_tests.js
'user_can_edit_account_name',
// Located in account_details_page_tests.js
'user_can_edit_account_password',
// Located in general_page_tests.js
'user_can_edit_workspace_details'
]
let full_filter = filtered_tests.concat(isolated_tests)
let build_filter = () => {
// Purpose: To set the suite that we want to run. (Sanity, Smoke, Regression)
var filter = {}
if(process.env.SCOPE) {
filter = {
testGrep: `^(?!.*(${filtered_tests.join('|')})).*$`,
testMeta: {
scope: process.env.SCOPE
}
}
} else {
filter = {
testGrep: `^(?!.*(${full_filter.join('|')})).*$`
}
}
return filter
}
let determine_concurrency = () => {
// Purpose: To set concurrency dependant on the scope that is passed
let concurrency = 5
if (process.env.SCOPE == 'isolated') {
concurrency = 1
}
return concurrency
}
module.exports = {
assertionTimeout: 5000,
browsers: [
"chrome:headless --window-size=1920,1159 --allow-insecure-localhost"
],
concurrency: determine_concurrency(),
cache: true,
clientScripts: "scripts/hide_notifications.js",
filter: build_filter(),
hostname: "localhost",
pageLoadTimeout: 30000,
quarantineMode: {
successThreshold: 1,
attemptLimit: 3
},
reporter: [
{
name: "spec",
output: "artifacts/reports/spec_results"
},
{
name: "xunit",
output: "artifacts/reports/xunit_results.xml"
}
],
screenshots: {
path: "artifacts/screenshots",
pathPattern: "${TEST}_${DATE}_${TIME}.png",
takeOnFails: true,
thumbnails: false
},
selectorTimeout: 5000,
skipJsErrors: true,
skipUncaughtErrors: true,
src: "tests/**",
ssl: {
pfx: "ssl/testingdomain.pfx",
rejectUnauthorized: true
},
videoEncodingOptions: {
aspect: "16:9",
framerate: 30
},
videoOptions: {
failedOnly: true,
pathPattern: "${TEST}_${DATE}_${TIME}.mp4",
singleFile: false
},
videoPath: "artifacts/recordings"
}

How to define messages with react-i18next

I'd like to ask a question about whether react-i18next provides us a way to define messages as react-intl
I wanna define all my messages first then using i18next-scanner to extract to json file.
Thanks in advance for your help in this matter.
After a while of researching. I'd give my way to someone wanna define messages in such a messages.js. BTW, I'm using i18nxt-scanner to extract the messages to JSON file.
i18next-scanner.config.js
module.exports = {
input: [
'src/app/**/*.{js,jsx}',
// Use ! to filter out files or directories
'!app/**/*.spec.{js,jsx}',
'!app/i18n/**',
'!**/node_modules/**',
],
output: './',
options: {
debug: true,
removeUnusedKeys: true,
func: {
list: ['getTranslationId'],
extensions: ['.js', '.tsx'],
},
lngs: ['en', 'ko'],
ns: ['translation'],
defaultLng: 'en',
defaultNs: 'translation',
defaultValue: '',
resource: {
loadPath: 'src/locales/{{lng}}/{{ns}}.json',
savePath: 'src/locales/{{lng}}/{{ns}}.json',
jsonIndent: 2,
lineEnding: '\n',
},
nsSeparator: false, // namespace separator
keySeparator: false, // key separator
interpolation: {
prefix: '{{',
suffix: '}}',
},
},
};
messages.js
import { getTranslationId } from 'locales/utils';
const messages = {
title: getTranslationId('Homepage_title', {
defaultValue: 'hello, {{name}}',
}),
count: getTranslationId('Homepage_count', {
defaultValue: '{{count}} time',
count: 0, // for plurals
}),
};
export default messages;
locales/utils.js
export const getTranslationId = id => {
if (!id || !id.includes('_'))
throw new Error('ID pattern should be "BLOCK_ElEMENT"');
return id;
};
Extracting command
yarn run i18next-scanner
Hope this helps! :D

Cannot read property 'AllowOverride' of null for Boolean field

I have response above like
i need to frame that
const masterSettingResponse = {
masterSMS: {
allowOverRide: setting.MasterSMS.AllowUserOverride,
smsEnabled: setting.MasterSMS.SMSEnabled,
smsUrl: setting.MasterSMS.SMSURL,
accessToken: setting.MasterSMS.AccesToken,
smsLogUrl: setting.MasterSMS.SMSLogUrl,
clientId: setting.MasterSMS.ClientId,
},
masterEmail: {
allowOverRide: setting.MasterEmail.AllowOverride,
emailEnabled: setting.MasterEmail.EmailEnabled,
emailLogUrl: setting.MasterEmail.EmailLogUrl,
accessToken: setting.MasterEmail.AccessToken,
emailUrl: setting.MasterEmail.EmailUrl,
clientId: setting.MasterEmail.ClientId,
},
masterGeneralSetting: {
isActive: setting.MasterGeneralSetting.IsActive,
portalSessionTimeout: setting.MasterGeneralSetting.PortalSessionTimeout,
appSessionTimeout: setting.MasterGeneralSetting.AppSessionTimeout,
},
};
return masterSettingResponse;
While coming to MasterEmail I am getting an 'AllowOverride' Null Exception.
But, it is boolean property. If the data is not available I need to show 'masterEmail' as null. How do I overcome the Exception?
You are trying to access a property from a null object. Add a check for this to solve your problem.
const masterSettingResponse = {
masterSMS: {
allowOverRide: (setting.MasterSMS ? setting.MasterSMS.AllowUserOverride : null),
smsEnabled: (setting.MasterSMS ? setting.MasterSMS.SMSEnabled : null),
smsUrl: (setting.MasterSMS ? setting.MasterSMS.SMSURL : null),
accessToken: (setting.MasterSMS ? setting.MasterSMS.AccesToken : null),
smsLogUrl: (setting.MasterSMS ? setting.MasterSMS.SMSLogUrl : null),
clientId: (setting.MasterSMS ? setting.MasterSMS.ClientId : null),
},
masterEmail: {
allowOverRide: (setting.MasterEmail ? setting.MasterEmail.AllowOverride : null),
emailEnabled: (setting.MasterEmail ? setting.MasterEmail.EmailEnabled : null),
emailLogUrl: (setting.MasterEmail ? setting.MasterEmail.EmailLogUrl : null),
accessToken: (setting.MasterEmail ? setting.MasterEmail.AccessToken : null),
emailUrl: (setting.MasterEmail ? setting.MasterEmail.EmailUrl : null),
clientId: (setting.MasterEmail ? setting.MasterEmail.ClientId : null),
},
masterGeneralSetting: {
isActive: (setting.MasterGeneralSetting ? setting.MasterGeneralSetting.IsActive : null),
portalSessionTimeout: (setting.MasterGeneralSetting ? setting.MasterGeneralSetting.PortalSessionTimeout : null),
appSessionTimeout: (setting.MasterGeneralSetting ? setting.MasterGeneralSetting.AppSessionTimeout : null),
},
};

vue-cli linting throwing camelcase warning when the rule is disabled

I'm building an app with vue-cli, using airbnb rules to lint.
Despite me adding a rule to my .eslintrc.js config file, and the rule appying on other files, this particular variable in my Welcome.vue file keeps throwing a warning when linting.
The warning:
warning: Identifier 'tables_count' is not in camel case (camelcase) at src\components\Welcome.vue:49:33:
47 | enableAll: function enableAll() {
48 | const tables_count = this.tables.length;
49 | for (let i = 0; i < tables_count; i += 1) {
| ^
50 | this.tables[i].enabled = true;
51 | }
52 | },
The full .eslintrc.js file:
module.exports = {
root: true,
env: {
node: true,
},
extends: [
'plugin:vue/essential',
'#vue/airbnb',
],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
indent: ['error', 4],
camelcase: ['warn', { properties: 'never' }],
},
parserOptions: {
parser: 'babel-eslint',
},
};
The strucure of my app is as follows:
App.vue
Welcome.vue
Game.vue
Both App.vue and Game.vue have variables with an under score and the linting is not throwing warnings for them.
App.vue: this.show_welcome = true;
Game.vue: this.current_answer = '';
What have I done wrong to make one particular Vue file offend the linter so much?!
This is either when I run npm run serve or npm run lint
NOTE: I thought I'd worked it out, but still no...
Currently I only have unit tests for welcome.vue, which has it's own lint file, but I've added the rule in there and I'm still getting the warnings:
tests/unit/eslintrc.js
module.exports = {
env: {
jest: true,
},
rules: {
camelcase: ['warn', { properties: 'never' }],
},
};
For a typescript project:
.eslintrc.js
{
rules: {
'#typescript-eslint/camelcase': 'off'
}
}
If you don't want eslint to check for variable casing then just turn it off with camelcase: 'off' in your .eslintrc.js.

Include npm dependency in karma

How can I include a dependency in package.json (not a devDependency) in karma?
I can include the file in node_modules/<dependency>, but I was looking for something more generic, including the main file.
I did not find any other better way to include them in karma.conf.js than
module.exports = function(config) {
var cfg = {
frameworks: ["jasmine", "commonjs"]
, files: [
{pattern: "node_modules/" + deps + "/*.js", included: true, watched: false}
, ...
]
...
};
cfg.preprocessors["node_modules/" + deps + "/**/*.js"] = ["commonjs"];
config.set(cfg);
};