Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

fix: use newer module exports plugin #35

Merged
merged 3 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions __snapshots__/e2e_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,6 @@ it('is a test', function () {

`

exports['math default exports'] = `
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _default = {
add: function add(a, b) {
return a + b;
}
};
exports["default"] = _default;
module.exports = exports.default;
module.exports.default = exports.default;

},{}],2:[function(require,module,exports){
"use strict";

var _math = require("./math");

context('math.js', function () {
it('imports function', function () {
expect(_math.add, 'add').to.be.a('function');
});
it('can add numbers', function () {
expect((0, _math.add)(1, 2)).to.eq(3);
});
});

},{"./math":1}]},{},[2]);

`

exports['sub import'] = `
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
Expand Down
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ const defaultOptions = {
babelrc: false,
plugins: [
...[
'@babel/plugin-transform-modules-commonjs',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
].map(require.resolve),
// irons out differences between ES6 modules and node exports
// https:/59naga/babel-plugin-add-module-exports
[require.resolve('babel-plugin-add-module-exports'), {
'addDefaultProperty': true,
}],
[require.resolve('@babel/plugin-transform-runtime'), {
absoluteRuntime: path.dirname(require.resolve('@babel/runtime/package')),
}],
Expand Down
147 changes: 135 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@
"@babel/core": "7.4.5",
"@babel/plugin-proposal-class-properties": "7.3.0",
"@babel/plugin-proposal-object-rest-spread": "7.3.2",
"@babel/plugin-transform-modules-commonjs": "7.8.3",
"@babel/plugin-transform-runtime": "7.2.0",
"@babel/preset-env": "7.4.5",
"@babel/preset-react": "7.0.0",
"@babel/runtime": "7.3.1",
"babel-plugin-add-module-exports": "1.0.2",
"babelify": "10.0.0",
"bluebird": "3.5.3",
"browserify": "16.2.3",
Expand Down
16 changes: 15 additions & 1 deletion test/e2e/e2e_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ describe('imports and exports', () => {
return bundle('math_spec.js').then((output) => {
// check that bundled tests work
eval(output)
snapshot('math default exports', output)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need, included absolute paths in the bundle

})
})

it('named ES6', () => {
return bundle('divide_spec.js').then((output) => {
// check that bundled tests work
eval(output)
})
})


it('handles module.exports and import', () => {
return bundle('sub_spec.js').then((output) => {
// check that bundled tests work
Expand All @@ -60,4 +67,11 @@ describe('imports and exports', () => {
// so as long as eval works, do not snapshot it
})
})

it('handles default string import', () => {
return bundle('dom_spec.js').then((output) => {
// check that bundled tests work
eval(output)
})
})
})
2 changes: 2 additions & 0 deletions test/fixtures/divide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// named export
export const divide = (a, b) => a/b
8 changes: 8 additions & 0 deletions test/fixtures/divide_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { divide } from './divide'

context('ES6 named export and import', function () {
it('works', () => {
expect(divide, 'divide').to.be.a('function')
expect(divide(10, 2)).to.eq(5)
})
})
1 change: 1 addition & 0 deletions test/fixtures/dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'dom'
8 changes: 8 additions & 0 deletions test/fixtures/dom_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const dom = require('./dom').default

context('imports default string', function () {
it('works', () => {
expect(dom, 'dom').to.be.a('string')
expect(dom).to.equal('dom')
})
})
5 changes: 4 additions & 1 deletion test/fixtures/math_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { add } from './math'
// math exports default object
// so if we want a property, first we need to grab the default
import math from './math'
const {add} = math

context('math.js', function () {
it('imports function', () => {
Expand Down