@@ -4,6 +4,8 @@ import { globs as appTreeGlob } from 'test-app/glob-imports';
4
4
5
5
const testTreeGlob = import . meta. glob ( './from-tests/**' , { eager : true } ) ;
6
6
7
+ const HERE = 'test-app/tests/glob-test/the-test' ;
8
+
7
9
module ( 'Glob tests' , function ( ) {
8
10
test ( 'works from app' , function ( assert ) {
9
11
let keys = Object . keys ( appTreeGlob ) ;
@@ -49,57 +51,56 @@ module('Glob tests', function () {
49
51
50
52
module ( 'underlying runtime' , function ( ) {
51
53
test ( 'extensions are stripped and the same as without using extensions' , ( assert ) => {
52
- let a = importMetaGlob ( './from-tests/**/*.js' , { eager : true } ) ;
53
- let b = importMetaGlob ( './from-tests/**/*' , { eager : true } ) ;
54
+ let a = importMetaGlob ( './from-tests/**/*.js' , { eager : true } , HERE ) ;
55
+ let b = importMetaGlob ( './from-tests/**/*' , { eager : true } , HERE ) ;
54
56
55
- assert . deepEqual ( a , b ) ;
57
+ assert . deepEqual ( Object . keys ( a ) , Object . keys ( b ) ) ;
58
+ assert . deepEqual ( Object . values ( a ) [ 0 ] . a , Object . values ( b ) [ 0 ] . a ) ;
59
+ assert . deepEqual ( Object . values ( a ) [ 1 ] . b , Object . values ( b ) [ 1 ] . b ) ;
60
+ assert . deepEqual ( Object . values ( a ) [ 2 ] . c , Object . values ( b ) [ 2 ] . c ) ;
56
61
} ) ;
57
62
58
63
module ( 'errors' , function ( ) {
59
64
module ( 'glob' , function ( ) {
60
65
test ( 'errors when trying to escape the app' , function ( assert ) {
61
66
assert . throws ( ( ) => {
62
- importMetaGlob (
63
- '../../../something' ,
64
- { eager : true } ,
65
- 'test-app/tests/glob-test/the-test' ,
66
- ) ;
67
- } , / n o t a v a l i d p a t h / ) ;
67
+ importMetaGlob ( '../../../something' , { eager : true } , HERE ) ;
68
+ } , / C a n n o t h a v e a p a t h t h a t e s c a p e s t h e a p p / ) ;
68
69
} ) ;
69
70
70
71
test ( 'errors when a sibling path tries to escape the app' , function ( assert ) {
71
72
assert . throws ( ( ) => {
72
73
importMetaGlob (
73
74
'./from-tests/../../../../something' ,
74
75
{ eager : true } ,
75
- 'test-app/tests/glob-test/the-test' ,
76
+ HERE ,
76
77
) ;
77
78
} , / C a n n o t h a v e a p a t h t h a t e s c a p e s t h e a p p / ) ;
78
79
} ) ;
79
80
80
81
test ( 'invalid glob' , function ( assert ) {
81
82
assert . throws ( ( ) => {
82
- importMetaGlob ( '**/*' ) ;
83
+ importMetaGlob ( '**/*' , HERE ) ;
83
84
} , / T h e g l o b p a t t e r n m u s t b e a r e l a t i v e p a t h s t a r t i n g w i t h e i t h e r / ) ;
84
85
} ) ;
85
86
} ) ;
86
87
87
88
module ( 'options' , function ( ) {
88
89
test ( 'errors with incorrect options' , function ( assert ) {
89
90
assert . throws ( ( ) => {
90
- importMetaGlob ( './**/*' , true ) ;
91
+ importMetaGlob ( './**/*' , true , HERE ) ;
91
92
} , / t h e s e c o n d a r g u m e n t t o i m p o r t .m e t a .g l o b m u s t b e a n o b j e c t / ) ;
92
93
} ) ;
93
94
94
95
test ( 'when passing options, cannot be empty' , function ( assert ) {
95
96
assert . throws ( ( ) => {
96
- importMetaGlob ( './**/*' , { } ) ;
97
+ importMetaGlob ( './**/*' , { } , HERE ) ;
97
98
} , / t h e o n l y s u p p o r t e d o p t i o n i s ' e a g e r ' / ) ;
98
99
} ) ;
99
100
100
101
test ( 'when passing options, only eager is allowed' , function ( assert ) {
101
102
assert . throws ( ( ) => {
102
- importMetaGlob ( './**/*' , { boop : 1 } ) ;
103
+ importMetaGlob ( './**/*' , { boop : 1 } , HERE ) ;
103
104
} , / t h e o n l y s u p p o r t e d o p t i o n i s ' e a g e r ' / ) ;
104
105
} ) ;
105
106
} ) ;
@@ -110,6 +111,12 @@ module('Glob tests', function () {
110
111
importMetaGlob ( './**/*' , { eager : true } ) ;
111
112
} , / t h e t h i r d a r g u m e n t t o i m p o r t .m e t a .g l o b m u s t b e p a s s e d a n d b e t h e m o d u l e p a t h / ) ;
112
113
} ) ;
114
+
115
+ test ( `errors with wrong path (can't be the entrypoint)` , function ( assert ) {
116
+ assert . throws ( ( ) => {
117
+ importMetaGlob ( '../../../something' , { eager : true } , 'test-app' ) ;
118
+ } , / n o t a v a l i d p a t h / ) ;
119
+ } ) ;
113
120
} ) ;
114
121
} ) ;
115
122
} ) ;
0 commit comments