You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if(!error)thrownewError(`\`testReadThrow()\` failed. Expected \`bundleAsync()\` to throw, but it did not.`);
184
-
// TODO: need support for napi-rs to propagate errors.
185
-
// if (!error.message.includes(`\`read()\` threw error:`) || !error.message.includes(`Oh noes! Failed to read \`foo.css\`.`)) {
186
-
// throw new Error(`\`testReadThrow()\` failed. Expected \`bundleAsync()\` to throw a specific error message, but it threw a different error:\n${error.message}`);
187
-
// }
184
+
assert.equal(error.message,`Oh noes! Failed to read \`foo.css\`.`);
185
+
assert.equal(error.loc,undefined);// error occurred when reading initial file, no location info available.
if(!error)thrownewError(`\`testReadThrow()\` failed. Expected \`bundleAsync()\` to throw, but it did not.`);
206
-
// TODO: need support for napi-rs to propagate errors.
207
-
// if (!error.message.includes(`\`read()\` threw error:`) || !error.message.includes(`Oh noes! Failed to read \`foo.css\`.`)) {
208
-
// throw new Error(`\`testReadThrow()\` failed. Expected \`bundleAsync()\` to throw a specific error message, but it threw a different error:\n${error.message}`);
209
-
// }
204
+
assert.equal(error.message,`Oh noes! Failed to read \`foo.css\`.`);
205
+
assert.equal(error.loc,undefined);// error occurred when reading initial file, no location info available.
206
+
});
207
+
208
+
test('read throw with location info',async()=>{
209
+
leterror=undefined;
210
+
try{
211
+
awaitbundleAsync({
212
+
filename: 'foo.css',
213
+
resolver: {
214
+
read(file){
215
+
if(file==='foo.css'){
216
+
return'@import "bar.css"';
217
+
}
218
+
thrownewError(`Oh noes! Failed to read \`${file}\`.`);
219
+
}
220
+
},
221
+
});
222
+
}catch(err){
223
+
error=err;
224
+
}
225
+
226
+
if(!error)thrownewError(`\`testReadThrow()\` failed. Expected \`bundleAsync()\` to throw, but it did not.`);
227
+
assert.equal(error.message,`Oh noes! Failed to read \`bar.css\`.`);
228
+
assert.equal(error.fileName,'foo.css');
229
+
assert.equal(error.loc,{
230
+
line: 1,
231
+
column: 1
232
+
});
233
+
});
234
+
235
+
test('async read throw with location info',async()=>{
236
+
leterror=undefined;
237
+
try{
238
+
awaitbundleAsync({
239
+
filename: 'foo.css',
240
+
resolver: {
241
+
asyncread(file){
242
+
if(file==='foo.css'){
243
+
return'@import "bar.css"';
244
+
}
245
+
thrownewError(`Oh noes! Failed to read \`${file}\`.`);
246
+
}
247
+
},
248
+
});
249
+
}catch(err){
250
+
error=err;
251
+
}
252
+
253
+
if(!error)thrownewError(`\`testReadThrow()\` failed. Expected \`bundleAsync()\` to throw, but it did not.`);
254
+
assert.equal(error.message,`Oh noes! Failed to read \`bar.css\`.`);
if(!error)thrownewError(`\`testResolveThrow()\` failed. Expected \`bundleAsync()\` to throw, but it did not.`);
228
-
// TODO: need support for napi-rs to propagate errors.
229
-
// if (!error.message.includes(`\`resolve()\` threw error:`) || !error.message.includes(`Oh noes! Failed to resolve \`root:hello/world.css\` from \`tests/testdata/css/foo.css\`.`)) {
230
-
// throw new Error(`\`testResolveThrow()\` failed. Expected \`bundleAsync()\` to throw a specific error message, but it threw a different error:\n${error.message}`);
231
-
// }
278
+
assert.equal(error.message,`Oh noes! Failed to resolve \`root:hello/world.css\` from \`tests/testdata/foo.css\`.`);
if(!error)thrownewError(`\`testResolveThrow()\` failed. Expected \`bundleAsync()\` to throw, but it did not.`);
250
-
// TODO: need support for napi-rs to propagate errors.
251
-
// if (!error.message.includes(`\`resolve()\` threw error:`) || !error.message.includes(`Oh noes! Failed to resolve \`root:hello/world.css\` from \`tests/testdata/css/foo.css\`.`)) {
252
-
// throw new Error(`\`testResolveThrow()\` failed. Expected \`bundleAsync()\` to throw a specific error message, but it threw a different error:\n${error.message}`);
253
-
// }
302
+
assert.equal(error.message,`Oh noes! Failed to resolve \`root:hello/world.css\` from \`tests/testdata/foo.css\`.`);
thrownewError(`\`testReadReturnNonString()\` failed. Expected \`bundleAsync()\` to throw a specific error message, but it threw a different error:\n${error.message}`);
thrownewError(`\`testResolveReturnNonString()\` failed. Expected \`bundleAsync()\` to throw a specific error message, but it threw a different error:\n${error.message}`);
0 commit comments