Skip to content

Commit

Permalink
Configure for expected CJS importing
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Mar 21, 2023
1 parent b150e0d commit 9ab7bd3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import '../../../../../../node_modules/chai/chai.js';
import defaultFoo from './modules/default-export.js';
import { namedFoo, namedBar } from './modules/named-exports.js';

// TODO: Ideally, we would be able to import named exports. But @rollup/plugin-commonjs does not support this yet
// see: https://github.com/rollup/plugins/issues/481
// import { compiledEsmFoo, compiledEsmBar } from '../src/compiled-esm-named-exports.js';
import compiledEsm from './modules/compiled-esm-named-exports.js';
import { compiledEsmFoo, compiledEsmBar } from './modules/compiled-esm-named-exports.js';
import compiledEsmDefault from './modules/compiled-esm-default-exports.js';

import requiredDefault from './modules/require-default.js';
Expand All @@ -24,17 +21,16 @@ describe('commonjs', () => {
});

it('can handle compiled es modules with named exports', () => {
console.log(compiledEsm);
expect(compiledEsm.compiledEsmFoo).to.equal('foo');
expect(compiledEsm.compiledEsmBar).to.equal('bar');
expect(compiledEsmFoo).to.equal('foo');
expect(compiledEsmBar).to.equal('bar');
});

it('can handle compiled es modules with a default export', () => {
expect(compiledEsmDefault).to.equal('bar');
});

it('can handle require default', () => {
expect(requiredDefault.default).to.equal('foo');
expect(requiredDefault).to.equal('foo');
});

it('can handle require named', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ exports.default = _default;`;
browsers: [chromeLauncher({ launchOptions: { devtools: false } })],
plugins: [
fromRollup(rollupCommonjs)({
requireReturnsDefault: 'preferred',
include: '**/commonjs/modules/**/*',
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ describe('rollup-plugin-html', () => {
}

const outputHtml = getAsset(output, 'index.html').source;
console.log(outputHtml);
expect(outputHtml).to.include(
'<link rel="apple-touch-icon" sizes="180x180" href="assets/image-a.png">',
);
Expand Down

0 comments on commit 9ab7bd3

Please sign in to comment.