node/test/parallel/test-url-pathtofileurl.js
guybedford eef072fa08 url: provide pathToFileURL and fileURLToPath
PR-URL: https://github.com/nodejs/node/pull/22506
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
2018-09-04 16:08:21 +02:00

25 lines
556 B
JavaScript

'use strict';
const { isWindows } = require('../common');
const assert = require('assert');
const url = require('url');
{
const fileURL = url.pathToFileURL('test/').href;
assert.ok(fileURL.startsWith('file:///'));
assert.ok(fileURL.endsWith('/'));
}
{
const fileURL = url.pathToFileURL('test\\').href;
assert.ok(fileURL.startsWith('file:///'));
if (isWindows)
assert.ok(fileURL.endsWith('/'));
else
assert.ok(fileURL.endsWith('%5C'));
}
{
const fileURL = url.pathToFileURL('test/%').href;
assert.ok(fileURL.includes('%25'));
}