1
1
import { resolveIfNotPlain } from '../core/resolve.js' ;
2
2
import assert from 'assert' ;
3
3
4
- describe ( 'Simple normalization tests' , function ( ) {
4
+ describe ( 'Simple normalization tests' , function ( ) {
5
5
it ( 'Should trim whitespace from URLs' , function ( ) {
6
6
assert . equal ( resolveIfNotPlain ( ' c:\\some\\path ' , 'file:///c:/adsf/asdf' ) , 'file:///c:/some/path' ) ;
7
7
} ) ;
8
8
it ( 'Should resolve relative with protocol' , function ( ) {
9
9
assert . equal ( resolveIfNotPlain ( './x:y' , 'https://x.com/y' ) , 'https://x.com/x:y' ) ;
10
10
} ) ;
11
- it ( 'Should resolve windows paths as file:/// URLs' , function ( ) {
11
+ it ( 'Should resolve windows paths as file:/// URLs' , function ( ) {
12
12
assert . equal ( resolveIfNotPlain ( 'c:\\some\\path' , 'file:///c:/adsf/asdf' ) , 'file:///c:/some/path' ) ;
13
13
} ) ;
14
- it ( 'Should resolve relative windows paths' , function ( ) {
14
+ it ( 'Should resolve relative windows paths' , function ( ) {
15
15
assert . equal ( resolveIfNotPlain ( './test.js' , 'file:///C:/some/path/' ) , 'file:///C:/some/path/test.js' ) ;
16
16
} ) ;
17
- it ( 'Should resolve unix file paths as file:/// URLs' , function ( ) {
17
+ it ( 'Should resolve unix file paths as file:/// URLs' , function ( ) {
18
18
assert . equal ( resolveIfNotPlain ( '/some/file/path.js' , 'file:///home/path/to/project' ) , 'file:///some/file/path.js' ) ;
19
19
} ) ;
20
- it ( 'Should be able to resolve to plain names' , function ( ) {
20
+ it ( 'Should be able to resolve to plain names' , function ( ) {
21
21
assert . equal ( resolveIfNotPlain ( '../../asdf/./asdf/.asdf/asdf' , 'a/b/c/d' ) , 'a/asdf/asdf/.asdf/asdf' ) ;
22
22
} ) ;
23
- it ( 'Should support resolving plain URI forms' , function ( ) {
23
+ it ( 'Should support resolving plain URI forms' , function ( ) {
24
24
assert . equal ( resolveIfNotPlain ( './asdf' , 'npm:lodash/' ) , 'npm:lodash/asdf' ) ;
25
25
} ) ;
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 ( ) {
27
27
var thrown = false ;
28
28
try {
29
29
resolveIfNotPlain ( '../asdf' , 'npm:lodash/path' ) ;
@@ -34,7 +34,7 @@ describe('Simple normalization tests', function() {
34
34
if ( ! thrown )
35
35
throw new Error ( 'Test should have thrown a RangeError exception' ) ;
36
36
} ) ;
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 ( ) {
38
38
var thrown = false ;
39
39
try {
40
40
resolveIfNotPlain ( '../' , 'npm:lodash/asdf/y' ) ;
@@ -45,32 +45,35 @@ describe('Simple normalization tests', function() {
45
45
if ( thrown )
46
46
throw new Error ( 'Test should not have thrown a RangeError exception' ) ;
47
47
} ) ;
48
- it ( 'Should support "." for resolution' , function ( ) {
48
+ it ( 'Should support "." for resolution' , function ( ) {
49
49
assert . equal ( resolveIfNotPlain ( '.' , 'https://www.google.com/asdf/asdf' ) , 'https://www.google.com/asdf/' ) ;
50
50
} ) ;
51
- it ( 'Should support ".." resolution' , function ( ) {
51
+ it ( 'Should support ".." resolution' , function ( ) {
52
52
assert . equal ( resolveIfNotPlain ( '..' , 'https://www.google.com/asdf/asdf/asdf' ) , 'https://www.google.com/asdf/' ) ;
53
53
} ) ;
54
- it ( 'Should support "./" for resolution' , function ( ) {
54
+ it ( 'Should support "./" for resolution' , function ( ) {
55
55
assert . equal ( resolveIfNotPlain ( './' , 'https://www.google.com/asdf/asdf' ) , 'https://www.google.com/asdf/' ) ;
56
56
} ) ;
57
- it ( 'Should support "../" resolution' , function ( ) {
57
+ it ( 'Should support "../" resolution' , function ( ) {
58
58
assert . equal ( resolveIfNotPlain ( '../' , 'https://www.google.com/asdf/asdf/asdf' ) , 'https://www.google.com/asdf/' ) ;
59
59
} ) ;
60
- it ( 'Should leave a trailing "/"' , function ( ) {
60
+ it ( 'Should leave a trailing "/"' , function ( ) {
61
61
assert . equal ( resolveIfNotPlain ( './asdf/' , 'file:///x/y' ) , 'file:///x/asdf/' ) ;
62
62
} ) ;
63
- it ( 'Should leave a trailing "//"' , function ( ) {
63
+ it ( 'Should leave a trailing "//"' , function ( ) {
64
64
assert . equal ( resolveIfNotPlain ( './asdf//' , 'file:///x/y' ) , 'file:///x/asdf//' ) ;
65
65
} ) ;
66
+ it ( 'Should support a trailing ".."' , function ( ) {
67
+ assert . equal ( resolveIfNotPlain ( '../..' , 'path/to/test/module.js' ) , 'path/' ) ;
68
+ } ) ;
66
69
} ) ;
67
70
68
71
import fs from 'fs' ;
69
72
var testCases = eval ( '(' + fs . readFileSync ( 'test/fixtures/url-resolution-cases.json' ) + ')' ) ;
70
73
71
- describe ( 'URL resolution selected WhatWG URL spec tests' , function ( ) {
74
+ describe ( 'URL resolution selected WhatWG URL spec tests' , function ( ) {
72
75
var run = 0 ;
73
- testCases . forEach ( function ( test ) {
76
+ testCases . forEach ( function ( test ) {
74
77
if ( typeof test == 'string' )
75
78
return ;
76
79
@@ -121,7 +124,7 @@ describe('URL resolution selected WhatWG URL spec tests', function() {
121
124
if ( test . input == '' )
122
125
return ;
123
126
124
- it ( 'Should resolve "' + test . input + '" to "' + test . base + '"' , function ( ) {
127
+ it ( 'Should resolve "' + test . input + '" to "' + test . base + '"' , function ( ) {
125
128
var failed = false ;
126
129
try {
127
130
var resolved = resolveIfNotPlain ( test . input , test . base ) || resolveIfNotPlain ( './' + test . input , test . base ) ;
0 commit comments