1
1
import { denoPlugin } from "./mod.ts" ;
2
- import { esbuild } from "./test_deps.ts" ;
2
+ import { esbuildNative , esbuildWasm } from "./test_deps.ts" ;
3
3
import { assert , assertEquals } from "./test_deps.ts" ;
4
4
5
- const ALL = [ "native" , "portable" ] as const ;
5
+ const LOADERS = [ "native" , "portable" ] as const ;
6
+ const PLATFORMS = { "native" : esbuildNative , "wasm" : esbuildWasm } ;
7
+
8
+ const DEFAULT_OPTS = {
9
+ write : false ,
10
+ format : "esm" ,
11
+ // TODO(lucacasonato): remove when https://github.com/evanw/esbuild/pull/2968 is fixed
12
+ absWorkingDir : Deno . cwd ( ) ,
13
+ } as const ;
6
14
7
15
function test (
8
16
name : string ,
9
17
loaders : readonly ( "native" | "portable" ) [ ] ,
10
- fn : ( loader : "native" | "portable" ) => Promise < void > ,
18
+ fn : (
19
+ esbuild : typeof esbuildNative ,
20
+ loader : "native" | "portable" ,
21
+ ) => Promise < void > ,
11
22
) {
12
- for ( const loader of loaders ) {
13
- Deno . test ( `[${ loader } ] ${ name } ` , async ( ) => {
14
- try {
15
- await esbuild . initialize ( { } ) ;
16
- await fn ( loader ) ;
17
- } finally {
18
- esbuild . stop ( ) ;
19
- }
20
- } ) ;
23
+ for ( const [ platform , esbuild ] of Object . entries ( PLATFORMS ) ) {
24
+ for ( const loader of loaders ) {
25
+ Deno . test ( {
26
+ name : `[${ loader } , ${ platform } ] ${ name } ` ,
27
+ sanitizeOps : platform === "wasm" ,
28
+ sanitizeResources : platform === "wasm" ,
29
+ ignore : platform === "wasm" && Deno . build . os === "windows" ,
30
+ fn : async ( ) => {
31
+ try {
32
+ await esbuild . initialize ( { } ) ;
33
+ await fn ( esbuild , loader ) ;
34
+ } finally {
35
+ esbuild . stop ( ) ;
36
+ }
37
+ } ,
38
+ } ) ;
39
+ }
21
40
}
22
41
}
23
42
24
- test ( "remote ts" , ALL , async ( loader ) => {
43
+ test ( "remote ts" , LOADERS , async ( esbuild , loader ) => {
25
44
const res = await esbuild . build ( {
45
+ ...DEFAULT_OPTS ,
26
46
plugins : [ denoPlugin ( { loader } ) ] ,
27
- write : false ,
28
47
entryPoints : [ "https://deno.land/std@0.173.0/collections/without_all.ts" ] ,
29
48
} ) ;
30
49
assertEquals ( res . warnings , [ ] ) ;
@@ -36,10 +55,10 @@ test("remote ts", ALL, async (loader) => {
36
55
assertEquals ( withoutAll ( [ 1 , 2 , 3 ] , [ 2 , 3 , 4 ] ) , [ 1 ] ) ;
37
56
} ) ;
38
57
39
- test ( "local ts" , ALL , async ( loader ) => {
58
+ test ( "local ts" , LOADERS , async ( esbuild , loader ) => {
40
59
const res = await esbuild . build ( {
60
+ ...DEFAULT_OPTS ,
41
61
plugins : [ denoPlugin ( { loader } ) ] ,
42
- write : false ,
43
62
entryPoints : [ "./testdata/mod.ts" ] ,
44
63
} ) ;
45
64
assertEquals ( res . warnings , [ ] ) ;
@@ -51,10 +70,10 @@ test("local ts", ALL, async (loader) => {
51
70
assertEquals ( bool , "asd2" ) ;
52
71
} ) ;
53
72
54
- test ( "remote mts" , ALL , async ( loader ) => {
73
+ test ( "remote mts" , LOADERS , async ( esbuild , loader ) => {
55
74
const res = await esbuild . build ( {
75
+ ...DEFAULT_OPTS ,
56
76
plugins : [ denoPlugin ( { loader } ) ] ,
57
- write : false ,
58
77
entryPoints : [
59
78
"https://gist.githubusercontent.com/lucacasonato/4ad57db57ee8d44e4ec08d6a912e93a7/raw/f33e698b4445a7243d72dbfe95afe2d004c7ffc6/mod.mts" ,
60
79
] ,
@@ -68,10 +87,10 @@ test("remote mts", ALL, async (loader) => {
68
87
assertEquals ( bool , "asd2" ) ;
69
88
} ) ;
70
89
71
- test ( "local mts" , ALL , async ( loader ) => {
90
+ test ( "local mts" , LOADERS , async ( esbuild , loader ) => {
72
91
const res = await esbuild . build ( {
92
+ ...DEFAULT_OPTS ,
73
93
plugins : [ denoPlugin ( { loader } ) ] ,
74
- write : false ,
75
94
entryPoints : [ "./testdata/mod.mts" ] ,
76
95
} ) ;
77
96
assertEquals ( res . warnings , [ ] ) ;
@@ -83,10 +102,10 @@ test("local mts", ALL, async (loader) => {
83
102
assertEquals ( bool , "asd2" ) ;
84
103
} ) ;
85
104
86
- test ( "remote js" , ALL , async ( loader ) => {
105
+ test ( "remote js" , LOADERS , async ( esbuild , loader ) => {
87
106
const res = await esbuild . build ( {
107
+ ...DEFAULT_OPTS ,
88
108
plugins : [ denoPlugin ( { loader } ) ] ,
89
- write : false ,
90
109
entryPoints : [ "https://crux.land/266TSp" ] ,
91
110
} ) ;
92
111
assertEquals ( res . warnings , [ ] ) ;
@@ -98,10 +117,10 @@ test("remote js", ALL, async (loader) => {
98
117
assertEquals ( bool , "asd" ) ;
99
118
} ) ;
100
119
101
- test ( "local js" , ALL , async ( loader ) => {
120
+ test ( "local js" , LOADERS , async ( esbuild , loader ) => {
102
121
const res = await esbuild . build ( {
122
+ ...DEFAULT_OPTS ,
103
123
plugins : [ denoPlugin ( { loader } ) ] ,
104
- write : false ,
105
124
entryPoints : [ "./testdata/mod.js" ] ,
106
125
} ) ;
107
126
assertEquals ( res . warnings , [ ] ) ;
@@ -113,10 +132,10 @@ test("local js", ALL, async (loader) => {
113
132
assertEquals ( bool , "asd" ) ;
114
133
} ) ;
115
134
116
- test ( "remote mjs" , ALL , async ( loader ) => {
135
+ test ( "remote mjs" , LOADERS , async ( esbuild , loader ) => {
117
136
const res = await esbuild . build ( {
137
+ ...DEFAULT_OPTS ,
118
138
plugins : [ denoPlugin ( { loader } ) ] ,
119
- write : false ,
120
139
entryPoints : [
121
140
"https://gist.githubusercontent.com/lucacasonato/4ad57db57ee8d44e4ec08d6a912e93a7/raw/f33e698b4445a7243d72dbfe95afe2d004c7ffc6/mod.mjs" ,
122
141
] ,
@@ -130,10 +149,10 @@ test("remote mjs", ALL, async (loader) => {
130
149
assertEquals ( bool , "asd" ) ;
131
150
} ) ;
132
151
133
- test ( "local mjs" , ALL , async ( loader ) => {
152
+ test ( "local mjs" , LOADERS , async ( esbuild , loader ) => {
134
153
const res = await esbuild . build ( {
154
+ ...DEFAULT_OPTS ,
135
155
plugins : [ denoPlugin ( { loader } ) ] ,
136
- write : false ,
137
156
entryPoints : [ "./testdata/mod.mjs" ] ,
138
157
} ) ;
139
158
assertEquals ( res . warnings , [ ] ) ;
@@ -145,10 +164,10 @@ test("local mjs", ALL, async (loader) => {
145
164
assertEquals ( bool , "asd" ) ;
146
165
} ) ;
147
166
148
- test ( "remote jsx" , ALL , async ( loader ) => {
167
+ test ( "remote jsx" , LOADERS , async ( esbuild , loader ) => {
149
168
const res = await esbuild . build ( {
169
+ ...DEFAULT_OPTS ,
150
170
plugins : [ denoPlugin ( { loader } ) ] ,
151
- write : false ,
152
171
entryPoints : [ "https://crux.land/GeaWJ" ] ,
153
172
} ) ;
154
173
assertEquals ( res . warnings , [ ] ) ;
@@ -160,10 +179,10 @@ test("remote jsx", ALL, async (loader) => {
160
179
assertEquals ( m . default , "foo" ) ;
161
180
} ) ;
162
181
163
- test ( "local jsx" , ALL , async ( loader ) => {
182
+ test ( "local jsx" , LOADERS , async ( esbuild , loader ) => {
164
183
const res = await esbuild . build ( {
184
+ ...DEFAULT_OPTS ,
165
185
plugins : [ denoPlugin ( { loader } ) ] ,
166
- write : false ,
167
186
entryPoints : [ "./testdata/mod.jsx" ] ,
168
187
} ) ;
169
188
assertEquals ( res . warnings , [ ] ) ;
@@ -175,10 +194,10 @@ test("local jsx", ALL, async (loader) => {
175
194
assertEquals ( m . default , "foo" ) ;
176
195
} ) ;
177
196
178
- test ( "remote tsx" , ALL , async ( loader ) => {
197
+ test ( "remote tsx" , LOADERS , async ( esbuild , loader ) => {
179
198
const res = await esbuild . build ( {
199
+ ...DEFAULT_OPTS ,
180
200
plugins : [ denoPlugin ( { loader } ) ] ,
181
- write : false ,
182
201
entryPoints : [ "https://crux.land/2Qjyo7" ] ,
183
202
} ) ;
184
203
assertEquals ( res . warnings , [ ] ) ;
@@ -190,10 +209,10 @@ test("remote tsx", ALL, async (loader) => {
190
209
assertEquals ( m . default , "foo" ) ;
191
210
} ) ;
192
211
193
- test ( "local tsx" , ALL , async ( loader ) => {
212
+ test ( "local tsx" , LOADERS , async ( esbuild , loader ) => {
194
213
const res = await esbuild . build ( {
214
+ ...DEFAULT_OPTS ,
195
215
plugins : [ denoPlugin ( { loader } ) ] ,
196
- write : false ,
197
216
entryPoints : [ "./testdata/mod.tsx" ] ,
198
217
} ) ;
199
218
assertEquals ( res . warnings , [ ] ) ;
@@ -205,10 +224,10 @@ test("local tsx", ALL, async (loader) => {
205
224
assertEquals ( m . default , "foo" ) ;
206
225
} ) ;
207
226
208
- test ( "bundle remote imports" , ALL , async ( loader ) => {
227
+ test ( "bundle remote imports" , LOADERS , async ( esbuild , loader ) => {
209
228
const res = await esbuild . build ( {
229
+ ...DEFAULT_OPTS ,
210
230
plugins : [ denoPlugin ( { loader } ) ] ,
211
- write : false ,
212
231
bundle : true ,
213
232
platform : "neutral" ,
214
233
entryPoints : [ "https://deno.land/std@0.173.0/uuid/mod.ts" ] ,
@@ -224,12 +243,12 @@ test("bundle remote imports", ALL, async (loader) => {
224
243
225
244
const importMapURL = new URL ( "./testdata/importmap.json" , import . meta. url ) ;
226
245
227
- test ( "bundle import map" , ALL , async ( loader ) => {
246
+ test ( "bundle import map" , LOADERS , async ( esbuild , loader ) => {
228
247
const res = await esbuild . build ( {
248
+ ...DEFAULT_OPTS ,
229
249
plugins : [
230
250
denoPlugin ( { importMapURL, loader } ) ,
231
251
] ,
232
- write : false ,
233
252
bundle : true ,
234
253
platform : "neutral" ,
235
254
entryPoints : [ "./testdata/importmap.js" ] ,
@@ -243,11 +262,10 @@ test("bundle import map", ALL, async (loader) => {
243
262
assertEquals ( bool , "asd2" ) ;
244
263
} ) ;
245
264
246
- test ( "local json" , ALL , async ( loader ) => {
265
+ test ( "local json" , LOADERS , async ( esbuild , loader ) => {
247
266
const res = await esbuild . build ( {
267
+ ...DEFAULT_OPTS ,
248
268
plugins : [ denoPlugin ( { loader } ) ] ,
249
- write : false ,
250
- format : "esm" ,
251
269
entryPoints : [ "./testdata/data.json" ] ,
252
270
} ) ;
253
271
assertEquals ( res . warnings , [ ] ) ;
0 commit comments