Skip to content

Commit 124f715

Browse files
anonrigtargos
authored andcommitted
test: move more url tests to node:test
PR-URL: #54636 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent d2ec961 commit 124f715

9 files changed

Lines changed: 533 additions & 528 deletions
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
'use strict';
22

3-
constcommon=require('../common');
4-
if(!common.hasIntl)
5-
common.skip('missing Intl');
3+
const{ hasIntl }=require('../common');
64

7-
conststrictEqual=require('assert').strictEqual;
8-
consturl=require('url');
9-
10-
constdomainToASCII=url.domainToASCII;
11-
constdomainToUnicode=url.domainToUnicode;
5+
const{ strictEqual }=require('node:assert');
6+
const{ domainToASCII, domainToUnicode }=require('node:url');
7+
const{ test }=require('node:test');
128

139
constdomainWithASCII=[
1410
['ıíd','xn--d-iga7r'],
@@ -21,11 +17,11 @@ const domainWithASCII = [
2117
['भारत.org','xn--h2brj9c.org'],
2218
];
2319

24-
domainWithASCII.forEach((pair)=>{
25-
constdomain=pair[0];
26-
constascii=pair[1];
27-
constdomainConvertedToASCII=domainToASCII(domain);
28-
strictEqual(domainConvertedToASCII,ascii);
29-
constasciiConvertedToUnicode=domainToUnicode(ascii);
30-
strictEqual(asciiConvertedToUnicode,domain);
20+
test('domainToASCII and domainToUnicode',{skip: !hasIntl},()=>{
21+
for(const[domain,ascii]ofdomainWithASCII){
22+
constdomainConvertedToASCII=domainToASCII(domain);
23+
strictEqual(domainConvertedToASCII,ascii);
24+
constasciiConvertedToUnicode=domainToUnicode(ascii);
25+
strictEqual(asciiConvertedToUnicode,domain);
26+
}
3127
});

‎test/parallel/test-url-fileurltopath.js‎

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
'use strict';
22
const{ isWindows }=require('../common');
3-
constassert=require('assert');
4-
consturl=require('url');
53

6-
functiontestInvalidArgs(...args){
7-
for(constargofargs){
4+
const{ test }=require('node:test');
5+
constassert=require('node:assert');
6+
consturl=require('node:url');
7+
8+
test('invalid arguments',()=>{
9+
for(constargof[null,undefined,1,{},true]){
810
assert.throws(()=>url.fileURLToPath(arg),{
911
code: 'ERR_INVALID_ARG_TYPE'
1012
});
1113
}
12-
}
13-
14-
// Input must be string or URL
15-
testInvalidArgs(null,undefined,1,{},true);
14+
});
1615

17-
// Input must be a file URL
18-
assert.throws(()=>url.fileURLToPath('https://a/b/c'),{
19-
code: 'ERR_INVALID_URL_SCHEME'
16+
test('input must be a file URL',()=>{
17+
assert.throws(()=>url.fileURLToPath('https://a/b/c'),{
18+
code: 'ERR_INVALID_URL_SCHEME'
19+
});
2020
});
2121

22-
{
22+
test('fileURLToPath with host',()=>{
2323
constwithHost=newURL('file://host/a');
2424

2525
if(isWindows){
@@ -29,9 +29,9 @@ assert.throws(() => url.fileURLToPath('https://a/b/c'), {
2929
code: 'ERR_INVALID_FILE_URL_HOST'
3030
});
3131
}
32-
}
32+
});
3333

34-
{
34+
test('fileURLToPath with invalid path',()=>{
3535
if(isWindows){
3636
assert.throws(()=>url.fileURLToPath('file:///C:/a%2F/'),{
3737
code: 'ERR_INVALID_FILE_URL_PATH'
@@ -47,7 +47,7 @@ assert.throws(() => url.fileURLToPath('https://a/b/c'), {
4747
code: 'ERR_INVALID_FILE_URL_PATH'
4848
});
4949
}
50-
}
50+
});
5151

5252
constwindowsTestCases=[
5353
// Lowercase ascii alpha
@@ -95,6 +95,7 @@ const windowsTestCases = [
9595
// UNC path (see https://docs.microsoft.com/en-us/archive/blogs/ie/file-uris-in-windows)
9696
{path: '\\\\nas\\My Docs\\File.doc',fileURL: 'file://nas/My%20Docs/File.doc'},
9797
];
98+
9899
constposixTestCases=[
99100
// Lowercase ascii alpha
100101
{path: '/foo',fileURL: 'file:///foo'},
@@ -140,29 +141,37 @@ const posixTestCases = [
140141
{path: '/🚀',fileURL: 'file:///%F0%9F%9A%80'},
141142
];
142143

143-
for(const{ path, fileURL }ofwindowsTestCases){
144-
constfromString=url.fileURLToPath(fileURL,{windows: true});
145-
assert.strictEqual(fromString,path);
146-
constfromURL=url.fileURLToPath(newURL(fileURL),{windows: true});
147-
assert.strictEqual(fromURL,path);
148-
}
144+
test('fileURLToPath with windows path',{skip: !isWindows},()=>{
145+
146+
for(const{ path, fileURL }ofwindowsTestCases){
147+
constfromString=url.fileURLToPath(fileURL,{windows: true});
148+
assert.strictEqual(fromString,path);
149+
constfromURL=url.fileURLToPath(newURL(fileURL),{windows: true});
150+
assert.strictEqual(fromURL,path);
151+
}
152+
});
149153

150-
for(const{ path, fileURL }ofposixTestCases){
151-
constfromString=url.fileURLToPath(fileURL,{windows: false});
152-
assert.strictEqual(fromString,path);
153-
constfromURL=url.fileURLToPath(newURL(fileURL),{windows: false});
154-
assert.strictEqual(fromURL,path);
155-
}
154+
test('fileURLToPath with posix path',{skip: isWindows},()=>{
155+
for(const{ path, fileURL }ofposixTestCases){
156+
constfromString=url.fileURLToPath(fileURL,{windows: false});
157+
assert.strictEqual(fromString,path);
158+
constfromURL=url.fileURLToPath(newURL(fileURL),{windows: false});
159+
assert.strictEqual(fromURL,path);
160+
}
161+
});
156162

157163
constdefaultTestCases=isWindows ? windowsTestCases : posixTestCases;
158164

159-
// Test when `options` is null
160-
constwhenNullActual=url.fileURLToPath(newURL(defaultTestCases[0].fileURL),null);
161-
assert.strictEqual(whenNullActual,defaultTestCases[0].path);
165+
test('options is null',()=>{
166+
constwhenNullActual=url.fileURLToPath(newURL(defaultTestCases[0].fileURL),null);
167+
assert.strictEqual(whenNullActual,defaultTestCases[0].path);
168+
});
162169

163-
for(const{ path, fileURL }ofdefaultTestCases){
164-
constfromString=url.fileURLToPath(fileURL);
165-
assert.strictEqual(fromString,path);
166-
constfromURL=url.fileURLToPath(newURL(fileURL));
167-
assert.strictEqual(fromURL,path);
168-
}
170+
test('defaultTestCases',()=>{
171+
for(const{ path, fileURL }ofdefaultTestCases){
172+
constfromString=url.fileURLToPath(fileURL);
173+
assert.strictEqual(fromString,path);
174+
constfromURL=url.fileURLToPath(newURL(fileURL));
175+
assert.strictEqual(fromURL,path);
176+
}
177+
});
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
'use strict';
2-
constcommon=require('../common');
3-
constassert=require('assert');
4-
consturl=require('url');
52

6-
constthrowsObjsAndReportTypes=[
7-
undefined,
8-
null,
9-
true,
10-
false,
11-
0,
12-
function(){},
13-
Symbol('foo'),
14-
];
3+
require('../common');
154

16-
for(consturlObjectofthrowsObjsAndReportTypes){
17-
assert.throws(()=>{
18-
url.format(urlObject);
19-
},{
20-
code: 'ERR_INVALID_ARG_TYPE',
21-
name: 'TypeError',
22-
message: 'The "urlObject" argument must be one of type object or string.'+
23-
common.invalidArgTypeHelper(urlObject)
24-
});
25-
}
26-
assert.strictEqual(url.format(''),'');
27-
assert.strictEqual(url.format({}),'');
5+
constassert=require('node:assert');
6+
consturl=require('node:url');
7+
const{ test }=require('node:test');
8+
9+
test('format invalid input',()=>{
10+
constthrowsObjsAndReportTypes=[
11+
undefined,
12+
null,
13+
true,
14+
false,
15+
0,
16+
function(){},
17+
Symbol('foo'),
18+
];
19+
20+
for(consturlObjectofthrowsObjsAndReportTypes){
21+
assert.throws(()=>{
22+
url.format(urlObject);
23+
},{
24+
code: 'ERR_INVALID_ARG_TYPE',
25+
name: 'TypeError',
26+
});
27+
}
28+
assert.strictEqual(url.format(''),'');
29+
assert.strictEqual(url.format({}),'');
30+
});

0 commit comments

Comments
 (0)