Skip to content

Commit 58480ce

Browse files
committed
Use more proper throwsAsync & notThrowsAsync assertions
1 parent 9f2e8a6 commit 58480ce

File tree

2 files changed

+58
-68
lines changed

2 files changed

+58
-68
lines changed

packages/babel/test/as-input-plugin.js

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ test('generates sourcemap by default', async (t) => {
122122
});
123123

124124
test('works with proposal-decorators (#18)', async (t) => {
125-
await rollup({
126-
input: 'fixtures/proposal-decorators/main.js',
127-
plugins: [babelPlugin({ babelHelpers: 'bundled' })]
128-
});
129-
t.pass();
125+
await t.notThrowsAsync(() =>
126+
rollup({
127+
input: 'fixtures/proposal-decorators/main.js',
128+
plugins: [babelPlugin({ babelHelpers: 'bundled' })]
129+
})
130+
);
130131
});
131132

132133
test('checks config per-file', async (t) => {
@@ -199,16 +200,12 @@ export default Foo;
199200
});
200201

201202
test('allows transform-runtime to be used instead of bundled helpers, but throws when CommonJS is used', async (t) => {
202-
try {
203-
await generate('fixtures/runtime-helpers-commonjs/main.js', { babelHelpers: 'runtime' });
204-
t.fail();
205-
} catch (error) {
206-
t.true(
207-
error.message.includes(
208-
'Rollup requires that your Babel configuration keeps ES6 module syntax intact.'
209-
)
210-
);
211-
}
203+
await t.throwsAsync(
204+
() => generate('fixtures/runtime-helpers-commonjs/main.js', { babelHelpers: 'runtime' }),
205+
{
206+
message: /Rollup requires that your Babel configuration keeps ES6 module syntax intact/
207+
}
208+
);
212209
});
213210

214211
test('allows using external-helpers plugin in combination with @babel/plugin-external-helpers', async (t) => {
@@ -242,11 +239,12 @@ test('correctly renames helpers (#22)', async (t) => {
242239
});
243240

244241
test('runs preflight check correctly in absence of class transformer (#23)', async (t) => {
245-
await rollup({
246-
input: 'fixtures/no-class-transformer/main.js',
247-
plugins: [babelPlugin({ babelHelpers: 'bundled' })]
248-
});
249-
t.pass();
242+
await t.notThrowsAsync(() =>
243+
rollup({
244+
input: 'fixtures/no-class-transformer/main.js',
245+
plugins: [babelPlugin({ babelHelpers: 'bundled' })]
246+
})
247+
);
250248
});
251249

252250
test('produces valid code with typeof helper', async (t) => {
@@ -289,58 +287,56 @@ test('transpiles only files with whitelisted extensions', async (t) => {
289287
});
290288

291289
test('throws when trying to add babel helper unavailable in used @babel/core version', async (t) => {
292-
try {
293-
await generate('fixtures/basic/main.js', {
294-
plugins: [
295-
function testPlugin() {
296-
return {
297-
visitor: {
298-
Program(path, state) {
299-
state.file.addHelper('__nonexistentHelper');
290+
await t.throwsAsync(
291+
() =>
292+
generate('fixtures/basic/main.js', {
293+
plugins: [
294+
function testPlugin() {
295+
return {
296+
visitor: {
297+
Program(path, state) {
298+
state.file.addHelper('__nonexistentHelper');
299+
}
300300
}
301-
}
302-
};
303-
}
304-
]
305-
});
306-
t.fail();
307-
} catch (err) {
308-
t.is(
309-
err.message,
310-
`${nodePath.resolve(
301+
};
302+
}
303+
]
304+
}),
305+
{
306+
message: `${nodePath.resolve(
311307
__dirname,
312308
'fixtures',
313309
'basic',
314310
'main.js'
315311
)}: Unknown helper __nonexistentHelper`
316-
);
317-
}
312+
}
313+
);
318314
});
319315

320316
test('works with minified bundled helpers', async (t) => {
321317
const BASE_CHAR_CODE = 'a'.charCodeAt(0);
322318
let counter = 0;
323319

324-
await generate('fixtures/class/main.js', {
325-
plugins: [
326-
function testPlugin({ types }) {
327-
return {
328-
visitor: {
329-
FunctionDeclaration(path) {
330-
// super simple mangling
331-
path
332-
.get('id')
333-
.replaceWith(types.identifier(String.fromCharCode(BASE_CHAR_CODE + counter)));
334-
335-
counter += 1;
336-
}
337-
}
338-
};
339-
}
340-
]
341-
});
320+
await t.notThrowsAsync(() =>
321+
generate('fixtures/class/main.js', {
322+
plugins: [
323+
function testPlugin({ types }) {
324+
return {
325+
visitor: {
326+
FunctionDeclaration(path) {
327+
// super simple mangling
328+
path
329+
.get('id')
330+
.replaceWith(types.identifier(String.fromCharCode(BASE_CHAR_CODE + counter)));
342331

343-
t.pass();
332+
counter += 1;
333+
}
334+
}
335+
};
336+
}
337+
]
338+
})
339+
);
344340
});
345341

346342
test('supports customizing the loader', async (t) => {

packages/babel/test/as-output-plugin.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,9 @@ test('supports customizing the loader', async (t) => {
291291
});
292292

293293
test('throws when using a Rollup output format other than esm or cjs', async (t) => {
294-
try {
295-
await generate('fixtures/basic/main.js', {}, { format: 'iife' });
296-
t.fail('Rollup did not throw');
297-
} catch (error) {
298-
t.is(
299-
error.message,
300-
`Using Babel on the generated chunks is strongly discouraged for formats other than "esm" or "cjs" as it can easily break wrapper code and lead to accidentally created global variables. Instead, you should set "output.format" to "esm" and use Babel to transform to another format, e.g. by adding "presets: [['@babel/env', { modules: 'umd' }]]" to your Babel options. If you still want to proceed, add "allowAllFormats: true" to your plugin options.`
301-
);
302-
}
294+
await t.throwsAsync(() => generate('fixtures/basic/main.js', {}, { format: 'iife' }), {
295+
message: `Using Babel on the generated chunks is strongly discouraged for formats other than "esm" or "cjs" as it can easily break wrapper code and lead to accidentally created global variables. Instead, you should set "output.format" to "esm" and use Babel to transform to another format, e.g. by adding "presets: [['@babel/env', { modules: 'umd' }]]" to your Babel options. If you still want to proceed, add "allowAllFormats: true" to your plugin options.`
296+
});
303297
});
304298

305299
test('allows using a Rollup output format other than esm or cjs with allowAllFormats', async (t) => {

0 commit comments

Comments
 (0)