Skip to content

Commit e6c1c31

Browse files
committed
Mocking env for snapshot tests.
1 parent 18ccb81 commit e6c1c31

File tree

2 files changed

+9
-142
lines changed

2 files changed

+9
-142
lines changed

packages/pwa-buildpack/lib/Utilities/__tests__/__snapshots__/serve.spec.js.snap

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -50,143 +50,8 @@ Array [
5050
"before": [Function],
5151
"bindLocal": true,
5252
"env": Object {
53-
"Apple_PubSub_Socket_Render": "/private/tmp/com.apple.launchd.20K8lIfFAM/Render",
54-
"COLORFGBG": "7;0",
55-
"COLORTERM": "truecolor",
56-
"COMMAND_MODE": "unix2003",
57-
"DISPLAY": "/private/tmp/com.apple.launchd.Oy4oakq6H2/org.macosforge.xquartz:0",
5853
"ENABLE_EXPRESS_SERVER_COMPRESSION": "false",
59-
"HOME": "/Users/annavara",
60-
"INIT_CWD": "/Users/annavara/Documents/node_projects/pwa-studio",
61-
"ITERM_PROFILE": "Default",
62-
"ITERM_SESSION_ID": "w0t0p0:53C2BF61-4D60-493D-8DE5-80EECFBA9F71",
63-
"JEST_WORKER_ID": "1",
64-
"LANG": "en_US.UTF-8",
65-
"LOGNAME": "annavara",
66-
"NODE": "/usr/local/bin/node",
67-
"NODE_ENV": "test",
68-
"ONLY_SUBSCRIBE_UNHANDLED_REJECTIONS_ONCE": "1",
69-
"PATH": "/var/folders/r5/3gw4fmrd51l_vztt4khkw0gh0000gn/T/yarn--1612380327605-0.8606273544197223:/Users/annavara/Documents/node_projects/pwa-studio/node_modules/.bin:/Users/annavara/.config/yarn/link/node_modules/.bin:/Users/annavara/Documents/node_projects/pwa-studio/node_modules/.bin:/usr/local/libexec/lib/node_modules/npm/bin/node-gyp-bin:/usr/local/lib/node_modules/npm/bin/node-gyp-bin:/usr/local/bin/node_modules/npm/bin/node-gyp-bin:/usr/local/opt/[email protected]/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/annavara/.composer/vendor/bin",
7054
"PORT": "1234",
71-
"PWD": "/Users/annavara/Documents/node_projects/pwa-studio",
72-
"SECURITYSESSIONID": "186aa",
73-
"SHELL": "/bin/bash",
74-
"SHLVL": "2",
75-
"SSH_AUTH_SOCK": "/private/tmp/com.apple.launchd.g4gZYLGM7H/Listeners",
76-
"TERM": "xterm-256color",
77-
"TERM_PROGRAM": "iTerm.app",
78-
"TERM_PROGRAM_VERSION": "3.2.9",
79-
"TERM_SESSION_ID": "w0t0p0:53C2BF61-4D60-493D-8DE5-80EECFBA9F71",
80-
"TMPDIR": "/var/folders/r5/3gw4fmrd51l_vztt4khkw0gh0000gn/T/",
81-
"USER": "annavara",
82-
"XPC_FLAGS": "0x0",
83-
"XPC_SERVICE_NAME": "0",
84-
"YARN_WRAP_OUTPUT": "false",
85-
"_": "/Users/annavara/Documents/node_projects/pwa-studio/node_modules/.bin/jest",
86-
"__CF_USER_TEXT_ENCODING": "0x1F5:0x0:0x0",
87-
"npm_config_argv": "{\\"remain\\":[],\\"cooked\\":[\\"run\\",\\"test\\"],\\"original\\":[\\"test\\",\\"-u\\",\\"--watch\\",\\"--no-coverage\\",\\"packages/pwa-buildpack/lib/Utilities/__tests__/serve.spec.js\\"]}",
88-
"npm_config_bin_links": "true",
89-
"npm_config_ignore_optional": "",
90-
"npm_config_ignore_scripts": "",
91-
"npm_config_init_license": "MIT",
92-
"npm_config_init_version": "1.0.0",
93-
"npm_config_registry": "https://registry.yarnpkg.com",
94-
"npm_config_save_prefix": "~",
95-
"npm_config_strict_ssl": "true",
96-
"npm_config_user_agent": "yarn/1.16.0 npm/? node/v14.15.3 darwin x64",
97-
"npm_config_version_commit_hooks": "true",
98-
"npm_config_version_git_message": "v%s",
99-
"npm_config_version_git_sign": "",
100-
"npm_config_version_git_tag": "true",
101-
"npm_config_version_tag_prefix": "v",
102-
"npm_execpath": "/usr/local/lib/node_modules/yarn/bin/yarn.js",
103-
"npm_lifecycle_event": "test",
104-
"npm_lifecycle_script": "jest",
105-
"npm_node_execpath": "/usr/local/bin/node",
106-
"npm_package_author_name": "Magento Commerce",
107-
"npm_package_bugs_url": "https://github.com/magento/pwa-studio/issues",
108-
"npm_package_bundlesize_0_maxSize": "250 kB",
109-
"npm_package_bundlesize_0_path": "./packages/venia-concept/dist/{client,vendors,sw}?(.)*.js",
110-
"npm_package_bundlesize_1_maxSize": "250 kB",
111-
"npm_package_bundlesize_1_path": "./packages/venia-concept/dist/RootCmp_*.js",
112-
"npm_package_bundlesize_2_maxSize": "100 kB",
113-
"npm_package_bundlesize_2_path": "./packages/venia-concept/dist/+([0-9]).*.js",
114-
"npm_package_description": "Magento PWA Studio is a collection of tools that lets developers build complex Progressive Web Applications on top of Magento 2 stores.",
115-
"npm_package_devDependencies__magento_eslint_config": "~1.5.0",
116-
"npm_package_devDependencies__types_jest": "~25.2.1",
117-
"npm_package_devDependencies_caller_id": "~0.1.0",
118-
"npm_package_devDependencies_chalk": "~2.4.2",
119-
"npm_package_devDependencies_chokidar": "~2.1.2",
120-
"npm_package_devDependencies_coveralls": "~3.0.3",
121-
"npm_package_devDependencies_danger": "^7.1.4",
122-
"npm_package_devDependencies_eslint": "~5.14.1",
123-
"npm_package_devDependencies_eslint_config_prettier": "~6.0.0",
124-
"npm_package_devDependencies_eslint_plugin_babel": "~5.3.0",
125-
"npm_package_devDependencies_eslint_plugin_graphql": "~3.0.3",
126-
"npm_package_devDependencies_eslint_plugin_jsx_a11y": "~6.2.1",
127-
"npm_package_devDependencies_eslint_plugin_node": "~8.0.1",
128-
"npm_package_devDependencies_eslint_plugin_package_json": "~0.1.4",
129-
"npm_package_devDependencies_eslint_plugin_react": "~7.21.5",
130-
"npm_package_devDependencies_eslint_plugin_react_hooks": "~2.0.1",
131-
"npm_package_devDependencies_execa": "~1.0.0",
132-
"npm_package_devDependencies_figures": "~2.0.0",
133-
"npm_package_devDependencies_first_run": "~2.0.0",
134-
"npm_package_devDependencies_identity_obj_proxy": "~3.0.0",
135-
"npm_package_devDependencies_jest": "~26.0.1",
136-
"npm_package_devDependencies_jest_fetch_mock": "~2.1.1",
137-
"npm_package_devDependencies_jest_junit": "~10.0.0",
138-
"npm_package_devDependencies_jest_transform_graphql": "~2.1.0",
139-
"npm_package_devDependencies_lodash_debounce": "~4.0.8",
140-
"npm_package_devDependencies_prettier": "~1.16.4",
141-
"npm_package_devDependencies_rimraf": "~2.6.3",
142-
"npm_package_engines_node": ">=10.x",
143-
"npm_package_engines_yarn": ">=1.12.0",
144-
"npm_package_homepage": "https://github.com/magento/pwa-studio",
145-
"npm_package_license": "SEE LICENSE IN LICENSE.txt",
146-
"npm_package_name": "@magento/pwa-studio",
147-
"npm_package_optionalDependencies_bundlesize": "~0.17.1",
148-
"npm_package_optionalDependencies_sharp": "~0.23.3",
149-
"npm_package_private": "true",
150-
"npm_package_readmeFilename": "README.md",
151-
"npm_package_resolutions____graphql_cli_graphql_playground_middleware_express": "~1.7.18",
152-
"npm_package_resolutions____graphql_cli_npm_run": "~5.0.0",
153-
"npm_package_resolutions_graphql": "~14.3.1",
154-
"npm_package_resolutions_https_proxy_agent": "~2.2.3",
155-
"npm_package_scripts_build": "yarn venia run build",
156-
"npm_package_scripts_build_dev": "yarn venia run build:dev",
157-
"npm_package_scripts_clean_all": "yarn workspaces run -s clean && rimraf ./node_modules",
158-
"npm_package_scripts_clean_dist": "yarn workspaces run clean",
159-
"npm_package_scripts_coveralls": "cat ./coverage/lcov.info | coveralls",
160-
"npm_package_scripts_danger": "danger-ci",
161-
"npm_package_scripts_lint": "eslint '@(packages|scripts)/**/{*.js,package.json}' --ignore-pattern node_modules --ignore-pattern storybook-dist",
162-
"npm_package_scripts_postbuild": "rimraf \\"./packages/*/dist/{,**/}__*__\\"",
163-
"npm_package_scripts_preinstall": "node -e 'process.env.CI||process.exit(1)' || npx npm-is yarn",
164-
"npm_package_scripts_prepare": "node scripts/monorepo-introduction.js",
165-
"npm_package_scripts_prettier": "prettier --loglevel warn --write '@(packages|scripts)/**/*.@(css|graphql|js)' '*.js'",
166-
"npm_package_scripts_prettier_check": "prettier --list-different '@(packages|scripts)/**/*.@(css|graphql|js)' '*.js'",
167-
"npm_package_scripts_stage_venia": "yarn venia start",
168-
"npm_package_scripts_stats_venia": "yarn venia run build:analyze && yarn venia run stats",
169-
"npm_package_scripts_storybook_venia": "yarn workspace @magento/venia-ui run storybook",
170-
"npm_package_scripts_test": "jest",
171-
"npm_package_scripts_test_ci": "jest --no-cache --max-workers=3 --json --outputFile=test-results.json",
172-
"npm_package_scripts_test_debug": "node --inspect-brk node_modules/.bin/jest --no-cache --no-coverage --runInBand --testTimeout 86400",
173-
"npm_package_scripts_test_dev": "jest --watch",
174-
"npm_package_scripts_validate_queries": "yarn venia run validate-queries",
175-
"npm_package_scripts_venia": "yarn workspace @magento/venia-concept",
176-
"npm_package_scripts_watch_all": "node scripts/watch-all.js",
177-
"npm_package_scripts_watch_venia": "yarn venia run watch",
178-
"npm_package_version": "8.0.0",
179-
"npm_package_workspaces_0": "packages/babel-preset-peregrine",
180-
"npm_package_workspaces_1": "packages/create-pwa",
181-
"npm_package_workspaces_10": "packages/venia-ui",
182-
"npm_package_workspaces_2": "packages/extensions/*",
183-
"npm_package_workspaces_3": "packages/graphql-cli-validate-magento-pwa-queries",
184-
"npm_package_workspaces_4": "packages/pagebuilder",
185-
"npm_package_workspaces_5": "packages/peregrine",
186-
"npm_package_workspaces_6": "packages/pwa-buildpack",
187-
"npm_package_workspaces_7": "packages/upward-js",
188-
"npm_package_workspaces_8": "packages/upward-spec",
189-
"npm_package_workspaces_9": "packages/venia-concept",
19055
},
19156
"logUrl": true,
19257
"port": "1234",

packages/pwa-buildpack/lib/Utilities/__tests__/serve.spec.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ beforeAll(() => {
9393
});
9494

9595
beforeEach(() => {
96-
process.env.ENABLE_EXPRESS_SERVER_COMPRESSION = 'false';
97-
process.env.PORT = 1234;
96+
process.env = {
97+
ENABLE_EXPRESS_SERVER_COMPRESSION: 'false',
98+
PORT: '1234'
99+
};
98100

99101
logs = {
100102
info: [],
@@ -188,7 +190,7 @@ test('should throw error if unable to load env', async () => {
188190
});
189191

190192
test('should use env.PORT if provided', async () => {
191-
process.env.PORT = 7899;
193+
process.env.PORT = '7899';
192194

193195
await serve('pwa-buildpack');
194196

@@ -197,7 +199,7 @@ test('should use env.PORT if provided', async () => {
197199
});
198200

199201
test('should use staging server port if env.PORT is not defined', async () => {
200-
process.env.PORT = null;
202+
process.env.PORT = 'null';
201203
getStagingServerConfig.mockReturnValueOnce({
202204
port: '5678'
203205
});
@@ -209,7 +211,7 @@ test('should use staging server port if env.PORT is not defined', async () => {
209211
});
210212

211213
test('should use port 0 if both env.PORT and staging config port are falsy', async () => {
212-
process.env.PORT = null;
214+
process.env.PORT = 'null';
213215
getStagingServerConfig.mockReturnValueOnce({
214216
port: null
215217
});
@@ -221,7 +223,7 @@ test('should use port 0 if both env.PORT and staging config port are falsy', asy
221223
});
222224

223225
test('should use configureHost config if custom origin is enabled', async () => {
224-
process.env.PORT = 7899;
226+
process.env.PORT = '7899';
225227
getCustomOriginConfig.mockReturnValueOnce({
226228
enabled: true
227229
});
@@ -241,7 +243,7 @@ test('should use configureHost config if custom origin is enabled', async () =>
241243
});
242244

243245
test('should log error if configureHost throws error', async () => {
244-
process.env.PORT = 7899;
246+
process.env.PORT = '7899';
245247
getCustomOriginConfig.mockReturnValueOnce({
246248
enabled: true
247249
});

0 commit comments

Comments
 (0)