Skip to content

Commit 1c0d32d

Browse files
authored
Merge pull request #2470 from Automattic/fix/url-parse-deprecation
refactor: remove deprecated `url.parse()` in favor of WHATWG URL API
2 parents 520937c + a32bed1 commit 1c0d32d

File tree

3 files changed

+6
-32
lines changed

3 files changed

+6
-32
lines changed

__tests__/lib/analytics/clients/tracks.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,16 @@
11
import nock from 'nock';
2-
import url from 'url';
32

43
import Tracks from '../../../../src/lib/analytics/clients/tracks';
54
import * as apiConfig from '../../../../src/lib/cli/apiConfig';
65

76
describe( 'lib/analytics/tracks', () => {
8-
const {
9-
protocol: endpointProtocol,
10-
host: endpointHost,
11-
path: endpointPath,
12-
} = url.parse( Tracks.ENDPOINT );
7+
const url = new URL( Tracks.ENDPOINT );
138

14-
const buildNock = () => {
15-
return nock( `${ endpointProtocol }//${ endpointHost }` ).post( endpointPath );
16-
};
9+
const buildNock = () => nock( url.origin ).post( url.pathname );
1710

1811
afterEach( nock.cleanAll );
1912

2013
describe( '.send()', () => {
21-
/**
22-
* Allow overriding of process variables per test
23-
* Adapted from https://stackoverflow.com/a/48042799
24-
*/
25-
const OLD_ENV = process.env;
26-
27-
beforeEach( () => {
28-
jest.resetModules();
29-
process.env = { ...OLD_ENV };
30-
} );
31-
32-
afterEach( () => {
33-
process.env = OLD_ENV;
34-
} );
35-
3614
it( 'should correctly construct remote request', () => {
3715
const tracksClient = new Tracks( 123, 'vip', '', {
3816
userAgent: 'vip-cli',

__tests__/lib/validations/is-multisite-domain-mapped.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
import nock from 'nock';
6-
import url from 'url';
76

87
import { API_URL } from '../../../src/lib/api';
98
import {
@@ -80,10 +79,10 @@ describe( 'is-multisite-domain-mapped', () => {
8079

8180
describe( 'isMultisitePrimaryDomainMapped', () => {
8281
beforeEach( () => {
83-
const { protocol, host, path } = url.parse( API_URL );
82+
const url = new URL( API_URL );
8483

85-
nock( `${ protocol }//${ host }` )
86-
.post( path )
84+
nock( url.origin )
85+
.post( url.pathname )
8786
.reply( 200, {
8887
data: {
8988
app: {

src/bin/vip-import-validate-files.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* External dependencies
55
*/
66
import chalk from 'chalk';
7-
import url from 'url';
87

98
/**
109
* Internal dependencies
@@ -29,9 +28,7 @@ export async function vipImportValidateFilesCmd( arg = [] ) {
2928
*
3029
* Manipulating the file path/name to extract the folder name
3130
*/
32-
const folder = arg.join(); // File comes in as an array as part of the args- turn it into a string
33-
arg = url.parse( folder ); // Then parse the file to its URL parts
34-
const filePath = arg.path; // Extract the path of the file
31+
const filePath = arg.join(); // File comes in as an array as part of the args- turn it into a string
3532

3633
if ( ! ( await isDirectory( filePath ) ) ) {
3734
console.error(

0 commit comments

Comments
 (0)