11import { resolveIfNotPlain } from '../core/resolve.js' ;
22import assert from 'assert' ;
33
4- describe ( 'Simple normalization tests' , function ( ) {
4+ describe ( 'Simple normalization tests' , function ( ) {
55 it ( 'Should trim whitespace from URLs' , function ( ) {
66 assert . equal ( resolveIfNotPlain ( ' c:\\some\\path ' , 'file:///c:/adsf/asdf' ) , 'file:///c:/some/path' ) ;
77 } ) ;
88 it ( 'Should resolve relative with protocol' , function ( ) {
99 assert . equal ( resolveIfNotPlain ( './x:y' , 'https://x.com/y' ) , 'https://x.com/x:y' ) ;
1010 } ) ;
11- it ( 'Should resolve windows paths as file:/// URLs' , function ( ) {
11+ it ( 'Should resolve windows paths as file:/// URLs' , function ( ) {
1212 assert . equal ( resolveIfNotPlain ( 'c:\\some\\path' , 'file:///c:/adsf/asdf' ) , 'file:///c:/some/path' ) ;
1313 } ) ;
14- it ( 'Should resolve relative windows paths' , function ( ) {
14+ it ( 'Should resolve relative windows paths' , function ( ) {
1515 assert . equal ( resolveIfNotPlain ( './test.js' , 'file:///C:/some/path/' ) , 'file:///C:/some/path/test.js' ) ;
1616 } ) ;
17- it ( 'Should resolve unix file paths as file:/// URLs' , function ( ) {
17+ it ( 'Should resolve unix file paths as file:/// URLs' , function ( ) {
1818 assert . equal ( resolveIfNotPlain ( '/some/file/path.js' , 'file:///home/path/to/project' ) , 'file:///some/file/path.js' ) ;
1919 } ) ;
20- it ( 'Should be able to resolve to plain names' , function ( ) {
20+ it ( 'Should be able to resolve to plain names' , function ( ) {
2121 assert . equal ( resolveIfNotPlain ( '../../asdf/./asdf/.asdf/asdf' , 'a/b/c/d' ) , 'a/asdf/asdf/.asdf/asdf' ) ;
2222 } ) ;
23- it ( 'Should support resolving plain URI forms' , function ( ) {
23+ it ( 'Should support resolving plain URI forms' , function ( ) {
2424 assert . equal ( resolveIfNotPlain ( './asdf' , 'npm:lodash/' ) , 'npm:lodash/asdf' ) ;
2525 } ) ;
26- it ( 'Should not support backtracking below base in plain URI forms' , function ( ) {
26+ it ( 'Should not support backtracking below base in plain URI forms' , function ( ) {
2727 var thrown = false ;
2828 try {
2929 resolveIfNotPlain ( '../asdf' , 'npm:lodash/path' ) ;
@@ -34,7 +34,7 @@ describe('Simple normalization tests', function() {
3434 if ( ! thrown )
3535 throw new Error ( 'Test should have thrown a RangeError exception' ) ;
3636 } ) ;
37- it ( 'Should not support backtracking exactly to the base in plain URI forms' , function ( ) {
37+ it ( 'Should not support backtracking exactly to the base in plain URI forms' , function ( ) {
3838 var thrown = false ;
3939 try {
4040 resolveIfNotPlain ( '../' , 'npm:lodash/asdf/y' ) ;
@@ -45,32 +45,35 @@ describe('Simple normalization tests', function() {
4545 if ( thrown )
4646 throw new Error ( 'Test should not have thrown a RangeError exception' ) ;
4747 } ) ;
48- it ( 'Should support "." for resolution' , function ( ) {
48+ it ( 'Should support "." for resolution' , function ( ) {
4949 assert . equal ( resolveIfNotPlain ( '.' , 'https://www.google.com/asdf/asdf' ) , 'https://www.google.com/asdf/' ) ;
5050 } ) ;
51- it ( 'Should support ".." resolution' , function ( ) {
51+ it ( 'Should support ".." resolution' , function ( ) {
5252 assert . equal ( resolveIfNotPlain ( '..' , 'https://www.google.com/asdf/asdf/asdf' ) , 'https://www.google.com/asdf/' ) ;
5353 } ) ;
54- it ( 'Should support "./" for resolution' , function ( ) {
54+ it ( 'Should support "./" for resolution' , function ( ) {
5555 assert . equal ( resolveIfNotPlain ( './' , 'https://www.google.com/asdf/asdf' ) , 'https://www.google.com/asdf/' ) ;
5656 } ) ;
57- it ( 'Should support "../" resolution' , function ( ) {
57+ it ( 'Should support "../" resolution' , function ( ) {
5858 assert . equal ( resolveIfNotPlain ( '../' , 'https://www.google.com/asdf/asdf/asdf' ) , 'https://www.google.com/asdf/' ) ;
5959 } ) ;
60- it ( 'Should leave a trailing "/"' , function ( ) {
60+ it ( 'Should leave a trailing "/"' , function ( ) {
6161 assert . equal ( resolveIfNotPlain ( './asdf/' , 'file:///x/y' ) , 'file:///x/asdf/' ) ;
6262 } ) ;
63- it ( 'Should leave a trailing "//"' , function ( ) {
63+ it ( 'Should leave a trailing "//"' , function ( ) {
6464 assert . equal ( resolveIfNotPlain ( './asdf//' , 'file:///x/y' ) , 'file:///x/asdf//' ) ;
6565 } ) ;
66+ it ( 'Should support a trailing ".."' , function ( ) {
67+ assert . equal ( resolveIfNotPlain ( '../..' , 'path/to/test/module.js' ) , 'path/' ) ;
68+ } ) ;
6669} ) ;
6770
6871import fs from 'fs' ;
6972var testCases = eval ( '(' + fs . readFileSync ( 'test/fixtures/url-resolution-cases.json' ) + ')' ) ;
7073
71- describe ( 'URL resolution selected WhatWG URL spec tests' , function ( ) {
74+ describe ( 'URL resolution selected WhatWG URL spec tests' , function ( ) {
7275 var run = 0 ;
73- testCases . forEach ( function ( test ) {
76+ testCases . forEach ( function ( test ) {
7477 if ( typeof test == 'string' )
7578 return ;
7679
@@ -121,7 +124,7 @@ describe('URL resolution selected WhatWG URL spec tests', function() {
121124 if ( test . input == '' )
122125 return ;
123126
124- it ( 'Should resolve "' + test . input + '" to "' + test . base + '"' , function ( ) {
127+ it ( 'Should resolve "' + test . input + '" to "' + test . base + '"' , function ( ) {
125128 var failed = false ;
126129 try {
127130 var resolved = resolveIfNotPlain ( test . input , test . base ) || resolveIfNotPlain ( './' + test . input , test . base ) ;
0 commit comments