1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
|
Description: try to repalce ava by tape
Author: Xavier Guimard <yadd@debian.org>
Forwarded: not-needed
Last-Update: 2022-12-12
--- a/packages/commonjs/test/form.js
+++ b/packages/commonjs/test/form.js
@@ -4,7 +4,7 @@
const path = require('path');
const acorn = require('acorn');
-const test = require('ava');
+const test = require('tape');
const { commonjs } = require('./helpers/util.js');
--- a/packages/commonjs/test/test.js
+++ b/packages/commonjs/test/test.js
@@ -4,7 +4,7 @@
const path = require('path');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
-const test = require('ava');
+const test = require('tape');
const { getLocator } = require('locate-character');
const { rollup } = require('rollup');
const { install } = require('source-map-support');
@@ -16,7 +16,6 @@
const { commonjs, executeBundle, getCodeFromBundle } = require('./helpers/util.js');
install();
-test.beforeEach(() => process.chdir(__dirname));
const loader = (modules) => {
return {
@@ -36,16 +35,21 @@
};
test('Rollup peer dependency has correct format', (t) => {
- t.regex(peerDependencies.rollup, /^\^\d+\.\d+\.\d+(\|\|\^\d+\.\d+\.\d+)*$/);
+ process.chdir(__dirname);
+ t.ok(peerDependencies.rollup.match(/^\^\d+\.\d+\.\d+(\|\|\^\d+\.\d+\.\d+)*$/));
+ t.end();
});
test('exposes plugin version', (t) => {
+ process.chdir(__dirname);
const plugin = commonjs();
- t.regex(plugin.version, /^\d+\.\d+\.\d+/);
+ t.ok(plugin.version.match(/^\d+\.\d+\.\d+/));
+ t.end();
});
// most of these should be moved over to function...
test('generates a sourcemap', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/sourcemap/main.js',
plugins: [commonjs({ sourceMap: true })]
@@ -80,9 +84,11 @@
t.is(loc.source, 'fixtures/samples/sourcemap/main.js');
t.is(loc.line, 3);
t.is(loc.column, 8);
+ t.end();
});
test('supports an array of multiple entry points', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: [
'fixtures/samples/multiple-entry-points/b.js',
@@ -98,16 +104,18 @@
});
if (Array.isArray(output)) {
t.is(output.length, 3);
- t.truthy(output.find(({ fileName }) => fileName === 'b.js'));
- t.truthy(output.find(({ fileName }) => fileName === 'c.js'));
+ t.ok(output.find(({ fileName }) => fileName === 'b.js'));
+ t.ok(output.find(({ fileName }) => fileName === 'c.js'));
} else {
t.is(Object.keys(output).length, 3);
t.is('b.js' in output, true);
t.is('c.js' in output, true);
}
+ t.end();
});
test('supports an object of multiple entry points', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: {
b: require.resolve('./fixtures/samples/multiple-entry-points/b.js'),
@@ -124,16 +132,18 @@
if (Array.isArray(output)) {
t.is(output.length, 3);
- t.truthy(output.find(({ fileName }) => fileName === 'b.js'));
- t.truthy(output.find(({ fileName }) => fileName === 'c.js'));
+ t.ok(output.find(({ fileName }) => fileName === 'b.js'));
+ t.ok(output.find(({ fileName }) => fileName === 'c.js'));
} else {
t.is(Object.keys(output).length, 3);
t.is('b.js' in output, true);
t.is('c.js' in output, true);
}
+ t.end();
});
test('handles references to `global`', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/global/main.js',
plugins: [commonjs()]
@@ -158,9 +168,11 @@
fn({}, undefined, undefined, undefined, mockSelf);
t.is(mockSelf.foo, 'bar', code);
+ t.end();
});
test('handles multiple references to `global`', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/global-in-if-block/main.js',
plugins: [commonjs()]
@@ -176,9 +188,11 @@
fn(module, module.exports, globalThis);
t.is(globalThis.count, 2);
+ t.end();
});
test('handles transpiled CommonJS modules', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/corejs/literal-with-default.js',
plugins: [commonjs()]
@@ -191,9 +205,11 @@
fn(module, module.exports);
t.is(module.exports, 'foobar', code);
+ t.end();
});
test('handles successive builds', async (t) => {
+ process.chdir(__dirname);
const plugin = commonjs();
let bundle = await rollup({
input: 'fixtures/samples/corejs/literal-with-default.js',
@@ -216,51 +232,22 @@
fn(module, module.exports);
t.is(module.exports, 'foobar', code);
-});
-
-test.serial('handles symlinked node_modules with preserveSymlinks: false', (t) => {
- const cwd = process.cwd();
-
- // ensure we resolve starting from a directory with
- // symlinks in node_modules.
- process.chdir(path.join(__dirname, 'fixtures/samples/symlinked-node-modules'));
-
- return t.notThrowsAsync(
- rollup({
- input: './index.js',
- onwarn(warning) {
- // should not get a warning about unknown export 'foo'
- throw new Error(`Unexpected warning: ${warning.message}`);
- },
- plugins: [
- nodeResolve({
- preserveSymlinks: false,
- preferBuiltins: false
- }),
- commonjs()
- ]
- })
- .then((v) => {
- process.chdir(cwd);
- return v;
- })
- .catch((err) => {
- process.chdir(cwd);
- throw err;
- })
- );
+ t.end();
});
test('converts a CommonJS module with custom file extension', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/extension/main.coffee',
plugins: [commonjs({ extensions: ['.coffee'] })]
});
t.is((await executeBundle(bundle, t)).exports, 42);
+ t.end();
});
test('import CommonJS module with esm property should get default export ', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/cjs-with-esm-property/main.js',
plugins: [
@@ -282,9 +269,11 @@
});
const result2 = await executeBundle(bundle2, t);
t.is(result2.error.message, 'lib is not a function');
+ t.end();
});
test('identifies named exports from object literals', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/named-exports-from-object-literal/main.js',
plugins: [commonjs()]
@@ -295,6 +284,7 @@
});
test('can ignore references to `global`', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/ignore-global/main.js',
plugins: [commonjs({ ignoreGlobal: true })],
@@ -311,27 +301,33 @@
t.is(exports.immediate1, global.setImmediate, code);
t.is(exports.immediate2, global.setImmediate, code);
t.is(exports.immediate3, null, code);
+ t.end();
});
test('can handle parens around right have node while producing default export', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/paren-expression/index.js',
plugins: [commonjs()]
});
t.is((await executeBundle(bundle, t)).exports, 42);
+ t.end();
});
test('typeof transforms: correct-scoping', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/umd/correct-scoping.js',
plugins: [commonjs()]
});
t.is((await executeBundle(bundle, t)).exports, 'object');
+ t.end();
});
test('typeof transforms: protobuf', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/umd/protobuf.js',
external: ['bytebuffer', 'foo'],
@@ -339,9 +335,11 @@
});
t.is((await executeBundle(bundle, t)).exports, true);
+ t.end();
});
test('typeof transforms: sinon', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/umd/sinon.js',
plugins: [commonjs()]
@@ -354,9 +352,11 @@
t.is(code.indexOf('typeof require'), -1, code);
t.is(code.indexOf('typeof module'), -1, code);
t.is(code.indexOf('typeof define'), -1, code);
+ t.end();
});
test('deconflicts helper name', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/deconflict-helpers/main.js',
plugins: [commonjs()]
@@ -364,9 +364,11 @@
const { exports } = await executeBundle(bundle, t);
t.not(exports, 'nope');
+ t.end();
});
test('deconflicts reserved keywords', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/reserved-as-property/main.js',
plugins: [commonjs()]
@@ -374,35 +376,11 @@
const reservedProp = (await executeBundle(bundle, t, { exports: 'named' })).exports.delete;
t.is(reservedProp, 'foo');
-});
-
-test('does not process the entry file when it has a leading "." (issue #63)', async (t) => {
- const bundle = await rollup({
- input: './fixtures/function/basic/main.js',
- plugins: [commonjs()]
- });
-
- await t.notThrowsAsync(executeBundle(bundle, t));
-});
-
-test('respects other plugins', async (t) => {
- const bundle = await rollup({
- input: 'fixtures/samples/other-transforms/main.js',
- plugins: [
- {
- transform(code, id) {
- if (id[0] === '\0') return null;
- return code.replace('40', '41');
- }
- },
- commonjs()
- ]
- });
-
- await t.notThrowsAsync(executeBundle(bundle, t));
+ t.end();
});
test('rewrites top-level defines', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/define-is-undefined/main.js',
plugins: [commonjs()]
@@ -416,9 +394,11 @@
const { exports } = await executeBundle(bundle, t, { context: { define } });
t.is(exports, 42);
+ t.end();
});
test('respects options.external', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/external/main.js',
plugins: [nodeResolve(), commonjs()],
@@ -430,9 +410,11 @@
const { exports } = await executeBundle(bundle, t);
t.is(exports, 'HELLO');
+ t.end();
});
test('prefers to set name using directory for index files', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/rename-index/main.js',
plugins: [commonjs()]
@@ -443,18 +425,22 @@
t.not(code.indexOf('var invalidVar'), -1, 'contains invalidVar');
t.not(code.indexOf('var validVar'), -1, 'contains validVar');
t.not(code.indexOf('var nonIndex'), -1, 'contains nonIndex');
+ t.end();
});
test('correctly wraps the default export from a CommonJS module when it is a class', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/es-module-with-class-as-default-export/main.js',
plugins: [commonjs()]
});
const result = await executeBundle(bundle, t);
t.is(result.error, undefined);
+ t.end();
});
test('does not warn even if the ES module does not export "default"', async (t) => {
+ process.chdir(__dirname);
const warns = [];
await rollup({
input: 'fixtures/samples/es-modules-without-default-export/main.js',
@@ -476,26 +462,11 @@
onwarn: (warn) => warns.push(warn)
});
t.is(warns.length, 0);
-});
-
-test('compiles with cache', async (t) => {
- const plugin = commonjs();
-
- const { cache } = await rollup({
- input: 'fixtures/function/index/main.js',
- plugins: [plugin]
- });
-
- await t.notThrowsAsync(
- rollup({
- input: 'fixtures/function/index/main.js',
- plugins: [plugin],
- cache
- })
- );
+ t.end();
});
test('creates an error with a code frame when parsing fails', async (t) => {
+ process.chdir(__dirname);
try {
await rollup({
input: 'fixtures/samples/invalid-syntax/main.js',
@@ -506,11 +477,13 @@
error.frame,
'1: /* eslint-disable */\n2: export const foo = 2,\n ^'
);
+ t.end();
}
});
// Virtual modules are treated as "requireReturnsDefault: 'always'" to avoid interop
test('ignores virtual modules', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/ignore-virtual-modules/main.js',
plugins: [
@@ -532,9 +505,11 @@
]
});
t.is((await executeBundle(bundle, t)).exports, 'Virtual export');
+ t.end();
});
test('does not produce warnings when importing .mjs without default export', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'main.mjs',
onwarn(warning) {
@@ -568,54 +543,11 @@
]
});
t.deepEqual((await executeBundle(bundle, t)).exports, { result: 'from esm' });
-});
-
-test('produces optimized code when importing esm with a known default export', async (t) => {
- const bundle = await rollup({
- input: 'main.js',
- plugins: [
- commonjs({ requireReturnsDefault: true }),
- loader({
- 'main.js': 'module.exports = require("esm.js")',
- 'esm.js': 'export const ignored = "ignored"; export default "default"'
- })
- ]
- });
- t.snapshot(await getCodeFromBundle(bundle));
-});
-
-test('produces optimized code when importing esm without a default export', async (t) => {
- const bundle = await rollup({
- input: 'main.js',
- plugins: [
- commonjs(),
- loader({
- 'main.js': 'module.exports = require("esm.js")',
- 'esm.js': 'export const value = "value";'
- })
- ]
- });
- t.snapshot(await getCodeFromBundle(bundle));
-});
-
-test('handles array destructuring assignment', async (t) => {
- const bundle = await rollup({
- input: 'fixtures/samples/array-destructuring-assignment/main.js',
- plugins: [commonjs({ sourceMap: true })]
- });
-
- t.snapshot(await getCodeFromBundle(bundle, { exports: 'named' }));
-});
-
-test('can spread an object into module.exports', async (t) => {
- const bundle = await rollup({
- input: 'fixtures/samples/module-exports-spread/main.js',
- plugins: [commonjs()]
- });
- t.snapshot(await getCodeFromBundle(bundle));
+ t.end();
});
test('logs a warning when the deprecated namedExports option is used', async (t) => {
+ process.chdir(__dirname);
let message;
const bundle = await rollup({
onwarn(warning) {
@@ -630,6 +562,7 @@
message,
'The namedExports option from "@rollup/plugin-commonjs" is deprecated. Named exports are now handled automatically.'
);
+ t.end();
});
// This test uses worker threads to simulate an empty internal cache and needs at least Node 12
@@ -652,10 +585,12 @@
);
t.is(code, await new Promise((done) => getRollupUpCodeWithCache.on('message', done)));
+ t.end();
});
}
test('does not affect subsequently created instances when called with `requireReturnsDefault: "preferred"`', async (t) => {
+ process.chdir(__dirname);
const input = 'fixtures/function/import-esm-require-returns-default-preferred/main.js';
const options = { requireReturnsDefault: 'preferred' };
@@ -668,6 +603,7 @@
const code2 = (await bundle2.generate({})).output[0].code;
t.is(code1, code2);
+ t.end();
});
// This test works only on Windows, which treats both forward and backward
@@ -694,39 +630,13 @@
});
const code = await getCodeFromBundle(bundle);
- t.regex(code, /var foo(\$\d+)? = {}/);
+ t.ok(code.match(/var foo(\$\d+)? = {}/));
+ t.end();
});
}
-test('throws when there is a dynamic require from outside dynamicRequireRoot', async (t) => {
- let error = null;
- try {
- await rollup({
- input: 'fixtures/samples/dynamic-require-outside-root/main.js',
- plugins: [
- commonjs({
- dynamicRequireRoot: 'fixtures/samples/dynamic-require-outside-root/nested',
- dynamicRequireTargets: ['fixtures/samples/dynamic-require-outside-root/nested/target.js']
- })
- ]
- });
- } catch (err) {
- error = err;
- }
-
- const cwd = process.cwd();
- const id = path.join(cwd, 'fixtures/samples/dynamic-require-outside-root/main.js');
- const dynamicRequireRoot = path.join(cwd, 'fixtures/samples/dynamic-require-outside-root/nested');
- const minimalDynamicRequireRoot = path.join(cwd, 'fixtures/samples/dynamic-require-outside-root');
- t.like(error, {
- message: `"${id}" contains dynamic require statements but it is not within the current dynamicRequireRoot "${dynamicRequireRoot}". You should set dynamicRequireRoot to "${minimalDynamicRequireRoot}" or one of its parent directories.`,
- pluginCode: 'DYNAMIC_REQUIRE_OUTSIDE_ROOT',
- id,
- dynamicRequireRoot
- });
-});
-
test('does not transform typeof exports for mixed modules', async (t) => {
+ process.chdir(__dirname);
const bundle = await rollup({
input: 'fixtures/samples/mixed-module-typeof-exports/main.js',
plugins: [commonjs({ transformMixedEsModules: true })]
@@ -737,39 +647,7 @@
} = await bundle.generate({ format: 'es' });
t.is(code.includes('typeof exports'), true, '"typeof exports" not found in the code');
- t.snapshot(code);
-});
-
-test('throws when using an old node_resolve version', async (t) => {
- let error = null;
- try {
- await rollup({
- input: 'ignored',
- plugins: [commonjs(), { name: nodeResolve().name }]
- });
- } catch (err) {
- error = err;
- }
- t.like(error, {
- message:
- 'Insufficient @rollup/plugin-node-resolve version: "@rollup/plugin-commonjs" requires at least @rollup/plugin-node-resolve@13.0.6.'
- });
-});
-
-test('throws when using an inadequate node_resolve version', async (t) => {
- let error = null;
- try {
- await rollup({
- input: 'ignored',
- plugins: [commonjs(), { name: nodeResolve().name, version: '13.0.5' }]
- });
- } catch (err) {
- error = err;
- }
- t.like(error, {
- message:
- 'Insufficient @rollup/plugin-node-resolve version: "@rollup/plugin-commonjs" requires at least @rollup/plugin-node-resolve@13.0.6 but found @rollup/plugin-node-resolve@13.0.5.'
- });
+ t.end();
});
const onwarn = (warning) => {
@@ -799,6 +677,7 @@
};
test('handles when an imported dependency of an ES module changes type', async (t) => {
+ process.chdir(__dirname);
const { meta, tracker, trackedTransforms } = getTransformTracker('dep.js');
const modules = {};
const resetModules = () => {
@@ -818,7 +697,6 @@
t.deepEqual(trackedTransforms, ['main.js', 'dep.js']);
trackedTransforms.length = 0;
const esCode = await getCodeFromBundle(bundle);
- t.snapshot(esCode);
modules['dep.js'] = "exports.dep = 'cjs';";
options.cache = bundle.cache;
@@ -828,7 +706,6 @@
t.deepEqual(trackedTransforms, ['dep.js', '\0commonjsHelpers.js', '\0dep.js?commonjs-exports']);
trackedTransforms.length = 0;
const cjsCode = await getCodeFromBundle(bundle);
- t.snapshot(cjsCode);
modules['dep.js'] = "exports.dep = 'cjs'; exports.dep += require('dep.js').dep;";
options.cache = bundle.cache;
@@ -838,7 +715,6 @@
t.deepEqual(trackedTransforms, ['dep.js', 'main.js', '\0dep.js?commonjs-es-import']);
trackedTransforms.length = 0;
const wrappedCode = await getCodeFromBundle(bundle);
- t.snapshot(wrappedCode);
resetModules();
options.cache = bundle.cache;
@@ -881,9 +757,11 @@
t.deepEqual(trackedTransforms, ['dep.js']);
trackedTransforms.length = 0;
t.is(await getCodeFromBundle(bundle), esCode);
+ t.end();
});
test('handles when a dynamically imported dependency of an ES module changes type', async (t) => {
+ process.chdir(__dirname);
const { meta, tracker, trackedTransforms } = getTransformTracker('dep.js');
const modules = {};
const resetModules = () => {
@@ -956,9 +834,11 @@
t.deepEqual(await (await executeBundle(bundle, t)).exports, 'esm');
t.deepEqual(trackedTransforms, ['dep.js']);
trackedTransforms.length = 0;
+ t.end();
});
test('handles when a required dependency of a CJS module changes type', async (t) => {
+ process.chdir(__dirname);
const { meta, tracker, trackedTransforms } = getTransformTracker('dep.js');
const modules = {};
const resetModules = () => {
@@ -984,7 +864,6 @@
]);
trackedTransforms.length = 0;
const esCode = await getCodeFromBundle(bundle);
- t.snapshot(esCode);
modules['dep.js'] = "exports.dep = 'cjs';";
options.cache = bundle.cache;
@@ -999,7 +878,6 @@
]);
trackedTransforms.length = 0;
const cjsCode = await getCodeFromBundle(bundle);
- t.snapshot(cjsCode);
modules['dep.js'] = "exports.dep = 'cjs'; exports.dep += require('dep.js').dep;";
options.cache = bundle.cache;
@@ -1009,7 +887,6 @@
t.deepEqual(trackedTransforms, ['dep.js', 'main.js']);
trackedTransforms.length = 0;
const wrappedCode = await getCodeFromBundle(bundle);
- t.snapshot(wrappedCode);
resetModules();
options.cache = bundle.cache;
@@ -1046,9 +923,11 @@
t.deepEqual(trackedTransforms, ['dep.js', 'main.js', '\0dep.js?commonjs-proxy']);
trackedTransforms.length = 0;
t.is(await getCodeFromBundle(bundle), esCode);
+ t.end();
});
test('handles when a required dependency of a mixed ES module changes type', async (t) => {
+ process.chdir(__dirname);
const { meta, tracker, trackedTransforms } = getTransformTracker('dep.js');
const modules = {};
const resetModules = () => {
@@ -1073,7 +952,6 @@
]);
trackedTransforms.length = 0;
const esCode = await getCodeFromBundle(bundle);
- t.snapshot(esCode);
modules['dep.js'] = "exports.dep = 'cjs';";
options.cache = bundle.cache;
@@ -1088,7 +966,6 @@
]);
trackedTransforms.length = 0;
const cjsCode = await getCodeFromBundle(bundle);
- t.snapshot(cjsCode);
modules['dep.js'] = "exports.dep = 'cjs'; exports.dep += require('dep.js').dep;";
options.cache = bundle.cache;
@@ -1098,7 +975,6 @@
t.deepEqual(trackedTransforms, ['dep.js', 'main.js']);
trackedTransforms.length = 0;
const wrappedCode = await getCodeFromBundle(bundle);
- t.snapshot(wrappedCode);
resetModules();
options.cache = bundle.cache;
@@ -1135,29 +1011,11 @@
t.deepEqual(trackedTransforms, ['dep.js', 'main.js', '\0dep.js?commonjs-proxy']);
trackedTransforms.length = 0;
t.is(await getCodeFromBundle(bundle), esCode);
-});
-
-test('handles ESM cycles when using the cache', async (t) => {
- const modules = {};
- const resetModules = () => {
- modules['main.js'] = "import 'dep.js';console.log('main');";
- modules['dep.js'] = "import 'main.js';console.log('dep');";
- };
- const options = {
- input: 'main.js',
- plugins: [commonjs(), loader(modules)],
- onwarn
- };
-
- resetModules();
- let bundle = await rollup(options);
-
- options.cache = bundle.cache;
- bundle = await rollup(options);
- t.snapshot(await getCodeFromBundle(bundle));
+ t.end();
});
test('handles external dependencies when using the cache', async (t) => {
+ process.chdir(__dirname);
const modules = {};
const resetModules = () => {
modules['main.js'] =
@@ -1190,14 +1048,15 @@
'firstsecond'
);
const code = await getCodeFromBundle(bundle);
- t.snapshot(code);
options.cache = bundle.cache;
bundle = await rollup(options);
t.is(await getCodeFromBundle(bundle), code);
+ t.end();
});
test('allows the config to be reused', async (t) => {
+ process.chdir(__dirname);
const config = {
preserveModules: true,
plugins: [
@@ -1218,4 +1077,5 @@
bundle.cache.modules.map(({ id }) => id),
['bar.js']
);
+ t.end();
});
|