Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test default import
  • Loading branch information
bahmutov committed Feb 5, 2020
commit f750655048ce2e18dfd4d98c8a9d547cc9200cc8
36 changes: 36 additions & 0 deletions __snapshots__/e2e_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@ context('math.js', function () {

`

exports['mul 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){
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}

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

module.exports = function (a, b) {
return a * b;
};

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

var _interopRequireDefault = require("/Users/gleb/git/cypress-browserify-preprocessor/node_modules/@babel/runtime/helpers/interopRequireDefault");

var _mul = _interopRequireDefault(require("./mul"));

context('mul.js imports default', function () {
it('imports function', function () {
expect(_mul["default"], 'mul').to.be.a('function');
});
it('can multiply numbers', function () {
expect((0, _mul["default"])(3, 2)).to.eq(6);
});
});

},{"./mul":2,"/Users/gleb/git/cypress-browserify-preprocessor/node_modules/@babel/runtime/helpers/interopRequireDefault":1}]},{},[3]);

`

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
8 changes: 8 additions & 0 deletions test/e2e/e2e_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ describe('imports and exports', () => {
snapshot('sub import', output)
})
})

it('handles module.exports and default import', () => {
return bundle('mul_spec.js').then((output) => {
// check that bundled tests work
eval(output)
snapshot('mul import', output)
})
})
})
1 change: 1 addition & 0 deletions test/fixtures/mul.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (a, b) => a * b
10 changes: 10 additions & 0 deletions test/fixtures/mul_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import mul from './mul'

context('mul.js imports default', function () {
it('imports function', () => {
expect(mul, 'mul').to.be.a('function')
})
it('can multiply numbers', function () {
expect(mul(3, 2)).to.eq(6)
})
})