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

Commit

Permalink
Add a few more e2e tests (#34)
Browse files Browse the repository at this point in the history
* fix: restore default export

* another e2e test

* test default import

* do not snapshot mul e2e test value
  • Loading branch information
bahmutov authored Feb 5, 2020
1 parent d49ec2b commit cda9378
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1 deletion.
30 changes: 30 additions & 0 deletions __snapshots__/e2e_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,33 @@ context('math.js', function () {
},{"./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";
var sub = function sub(a, b) {
return a - b;
};
module.exports = {
sub: sub
};
},{}],2:[function(require,module,exports){
"use strict";
var _sub = require("./sub");
context('sub.js', function () {
it('imports function', function () {
expect(_sub.sub, 'sub').to.be.a('function');
});
it('can subtract numbers', function () {
expect((0, _sub.sub)(1, 2)).to.eq(-1);
});
});
},{"./sub":1}]},{},[2]);
`
20 changes: 19 additions & 1 deletion test/e2e/e2e_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,29 @@ describe('browserify preprocessor - e2e', function () {

describe('imports and exports', () => {
it('handles imports and exports', () => {

return bundle('math_spec.js').then((output) => {
// check that bundled tests work
eval(output)
snapshot('math default exports', output)
})
})

it('handles module.exports and import', () => {
return bundle('sub_spec.js').then((output) => {
// check that bundled tests work
eval(output)
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)
// for some reason, this bundle included full resolved path
// to interop require module
// which on CI generates different path.
// so as long as eval works, do not snapshot it
})
})
})
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)
})
})
3 changes: 3 additions & 0 deletions test/fixtures/sub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const sub = (a, b) => a - b

module.exports = {sub}
10 changes: 10 additions & 0 deletions test/fixtures/sub_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { sub } from './sub'

context('sub.js', function () {
it('imports function', () => {
expect(sub, 'sub').to.be.a('function')
})
it('can subtract numbers', function () {
expect(sub(1, 2)).to.eq(-1)
})
})

0 comments on commit cda9378

Please sign in to comment.