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

Commit 8601521

Browse files
authored
fix: use newer module exports plugin (#35)
* export string test * fix: follow ES6 when exporting default * remove commented out code
1 parent cda9378 commit 8601521

File tree

10 files changed

+175
-55
lines changed

10 files changed

+175
-55
lines changed

__snapshots__/e2e_spec.js

-35
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,6 @@ it('is a test', function () {
1414
1515
`
1616

17-
exports['math default exports'] = `
18-
(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){
19-
"use strict";
20-
21-
Object.defineProperty(exports, "__esModule", {
22-
value: true
23-
});
24-
exports["default"] = void 0;
25-
var _default = {
26-
add: function add(a, b) {
27-
return a + b;
28-
}
29-
};
30-
exports["default"] = _default;
31-
module.exports = exports.default;
32-
module.exports.default = exports.default;
33-
34-
},{}],2:[function(require,module,exports){
35-
"use strict";
36-
37-
var _math = require("./math");
38-
39-
context('math.js', function () {
40-
it('imports function', function () {
41-
expect(_math.add, 'add').to.be.a('function');
42-
});
43-
it('can add numbers', function () {
44-
expect((0, _math.add)(1, 2)).to.eq(3);
45-
});
46-
});
47-
48-
},{"./math":1}]},{},[2]);
49-
50-
`
51-
5217
exports['sub import'] = `
5318
(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){
5419
"use strict";

index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,10 @@ const defaultOptions = {
2929
babelrc: false,
3030
plugins: [
3131
...[
32+
'@babel/plugin-transform-modules-commonjs',
3233
'@babel/plugin-proposal-class-properties',
3334
'@babel/plugin-proposal-object-rest-spread',
3435
].map(require.resolve),
35-
// irons out differences between ES6 modules and node exports
36-
// https://github.com/59naga/babel-plugin-add-module-exports
37-
[require.resolve('babel-plugin-add-module-exports'), {
38-
'addDefaultProperty': true,
39-
}],
4036
[require.resolve('@babel/plugin-transform-runtime'), {
4137
absoluteRuntime: path.dirname(require.resolve('@babel/runtime/package')),
4238
}],

package-lock.json

+135-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@
6161
"@babel/core": "7.4.5",
6262
"@babel/plugin-proposal-class-properties": "7.3.0",
6363
"@babel/plugin-proposal-object-rest-spread": "7.3.2",
64+
"@babel/plugin-transform-modules-commonjs": "7.8.3",
6465
"@babel/plugin-transform-runtime": "7.2.0",
6566
"@babel/preset-env": "7.4.5",
6667
"@babel/preset-react": "7.0.0",
6768
"@babel/runtime": "7.3.1",
68-
"babel-plugin-add-module-exports": "1.0.2",
6969
"babelify": "10.0.0",
7070
"bluebird": "3.5.3",
7171
"browserify": "16.2.3",

test/e2e/e2e_spec.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ describe('imports and exports', () => {
3838
return bundle('math_spec.js').then((output) => {
3939
// check that bundled tests work
4040
eval(output)
41-
snapshot('math default exports', output)
4241
})
4342
})
4443

44+
it('named ES6', () => {
45+
return bundle('divide_spec.js').then((output) => {
46+
// check that bundled tests work
47+
eval(output)
48+
})
49+
})
50+
51+
4552
it('handles module.exports and import', () => {
4653
return bundle('sub_spec.js').then((output) => {
4754
// check that bundled tests work
@@ -60,4 +67,11 @@ describe('imports and exports', () => {
6067
// so as long as eval works, do not snapshot it
6168
})
6269
})
70+
71+
it('handles default string import', () => {
72+
return bundle('dom_spec.js').then((output) => {
73+
// check that bundled tests work
74+
eval(output)
75+
})
76+
})
6377
})

test/fixtures/divide.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// named export
2+
export const divide = (a, b) => a/b

test/fixtures/divide_spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { divide } from './divide'
2+
3+
context('ES6 named export and import', function () {
4+
it('works', () => {
5+
expect(divide, 'divide').to.be.a('function')
6+
expect(divide(10, 2)).to.eq(5)
7+
})
8+
})

test/fixtures/dom.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'dom'

test/fixtures/dom_spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const dom = require('./dom').default
2+
3+
context('imports default string', function () {
4+
it('works', () => {
5+
expect(dom, 'dom').to.be.a('string')
6+
expect(dom).to.equal('dom')
7+
})
8+
})

test/fixtures/math_spec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { add } from './math'
1+
// math exports default object
2+
// so if we want a property, first we need to grab the default
3+
import math from './math'
4+
const {add} = math
25

36
context('math.js', function () {
47
it('imports function', () => {

0 commit comments

Comments
 (0)