Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update update-notifier to 7.0.0 #1544

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions __tests__/lib/http/proxy-agent.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { HttpsProxyAgent } from 'https-proxy-agent';
import { SocksProxyAgent } from 'socks-proxy-agent';

import { createProxyAgent } from '../../../src/lib/http/proxy-agent';

// Reference for testing with env variables within a test: https://github.com/vuejs/vue-test-utils/issues/193

describe( 'validate CreateProxyAgent', () => {
let env;

beforeAll( () => {
env = { ...process.env };
} );

beforeEach( () => {
// Clear all applicable environment variables before running test so each test starts "clean"
// using beforeEach instead of afterEach in case the client running tests has env variables set before the first test is run
Expand All @@ -19,6 +27,10 @@ describe( 'validate CreateProxyAgent', () => {
}
} );

afterAll( () => {
process.env = { ...env };
} );
Comment on lines +30 to +32
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is unnecessary, but I prefer restoring things to their original state.


// Tests checking for null results
it.each( [
{
Expand Down Expand Up @@ -90,11 +102,7 @@ describe( 'validate CreateProxyAgent', () => {
urlToHit: 'https://wpAPI.org/api',
},
] )( 'should return null with %o', async ( { envVars, urlToHit } ) => {
setEnvironmentVariabeles( envVars );
// We have to dynamically import the module so we can set environment variables above
// All tests must be async to support this dynamic import, otherwise the modified env variables are not picked up
const createProxyAgent = ( await import( '../../../src/lib/http/proxy-agent' ) )
.createProxyAgent;
Comment on lines -93 to -97
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It magically works :-) I found no code in createProxyAgent to cache the old environment variables. And, as far as I understand, multiple await import (= require()) will load the module only once anyway.

setEnvironmentVariables( envVars );
const agent = createProxyAgent( urlToHit );
expect( agent ).toBeNull();
} );
Expand Down Expand Up @@ -167,17 +175,15 @@ describe( 'validate CreateProxyAgent', () => {
expectedClass: HttpsProxyAgent,
},
] )( 'should return proxy with %o', async ( { envVars, urlToHit, expectedClass } ) => {
setEnvironmentVariabeles( envVars );
const createProxyAgent = ( await import( '../../../src/lib/http/proxy-agent' ) )
.createProxyAgent;
setEnvironmentVariables( envVars );
const agent = createProxyAgent( urlToHit );
expect( agent ).not.toBeNull();
expect( agent ).toBeInstanceOf( expectedClass );
} );

// Helper function to set environment variables based on passed in object
// envVars of the form: [ { VAR: 'VALUE' }, { VAR1: 'VALUE1' }, ... ]
function setEnvironmentVariabeles( envVars ) {
function setEnvironmentVariables( envVars ) {
for ( const index in envVars ) {
for ( const key in envVars[ index ] ) {
process.env[ key ] = envVars[ index ][ key ];
Expand Down
4 changes: 3 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ module.exports = {
[
'@babel/preset-env',
{
loose: true,
exclude: [ '@babel/plugin-proposal-dynamic-import' ],
targets: {
node: '16', // Keep this in sync with package.json engines.node
node: '18', // Keep this in sync with package.json engines.node
},
},
],
Expand Down
Loading