Skip to content

Commit

Permalink
Add test for generating/writing closed bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Nov 30, 2020
1 parent 6e7116f commit 0d25a8c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/utils/error.ts
Expand Up @@ -381,7 +381,7 @@ export function errFailedValidation(message: string) {
export function errAlreadyClosed() {
return {
code: Errors.ALREADY_CLOSED,
message: "Bundle is already closed, no more calls to 'generate' or 'write' is allowed."
message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
};
}

Expand Down
35 changes: 34 additions & 1 deletion test/misc/sanity-checks.js
@@ -1,6 +1,6 @@
const assert = require('assert');
const rollup = require('../../dist/rollup');
const { loader } = require('../utils.js');
const { loader, compareError } = require('../utils.js');

describe('sanity checks', () => {
it('exists', () => {
Expand Down Expand Up @@ -236,4 +236,37 @@ describe('sanity checks', () => {
'You must set "output.dir" instead of "output.file" when using the "output.preserveModules" option.'
);
});

it('prevents generating and writing from a closed bundle', async () => {
let error = null;
const bundle = await rollup.rollup({
input: 'x',
plugins: [loader({ x: 'console.log( "x" );' })]
});
bundle.close();
// Can be safely called multiple times
bundle.close();

try {
await bundle.generate({ file: 'x', format: 'es' });
} catch (generateError) {
error = generateError;
}
compareError(error, {
code: 'ALREADY_CLOSED',
message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
});
error = null;

try {
await bundle.write({ file: 'x', format: 'es' });
} catch (writeError) {
error = writeError;
}
compareError(error, {
code: 'ALREADY_CLOSED',
message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
});
error = null;
});
});

0 comments on commit 0d25a8c

Please sign in to comment.