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

Commit cda9378

Browse files
authored
Add a few more e2e tests (#34)
* fix: restore default export * another e2e test * test default import * do not snapshot mul e2e test value
1 parent d49ec2b commit cda9378

File tree

6 files changed

+73
-1
lines changed

6 files changed

+73
-1
lines changed

__snapshots__/e2e_spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,33 @@ context('math.js', function () {
4848
},{"./math":1}]},{},[2]);
4949
5050
`
51+
52+
exports['sub import'] = `
53+
(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){
54+
"use strict";
55+
56+
var sub = function sub(a, b) {
57+
return a - b;
58+
};
59+
60+
module.exports = {
61+
sub: sub
62+
};
63+
64+
},{}],2:[function(require,module,exports){
65+
"use strict";
66+
67+
var _sub = require("./sub");
68+
69+
context('sub.js', function () {
70+
it('imports function', function () {
71+
expect(_sub.sub, 'sub').to.be.a('function');
72+
});
73+
it('can subtract numbers', function () {
74+
expect((0, _sub.sub)(1, 2)).to.eq(-1);
75+
});
76+
});
77+
78+
},{"./sub":1}]},{},[2]);
79+
80+
`

test/e2e/e2e_spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,29 @@ describe('browserify preprocessor - e2e', function () {
3535

3636
describe('imports and exports', () => {
3737
it('handles imports and exports', () => {
38-
3938
return bundle('math_spec.js').then((output) => {
4039
// check that bundled tests work
4140
eval(output)
4241
snapshot('math default exports', output)
4342
})
4443
})
44+
45+
it('handles module.exports and import', () => {
46+
return bundle('sub_spec.js').then((output) => {
47+
// check that bundled tests work
48+
eval(output)
49+
snapshot('sub import', output)
50+
})
51+
})
52+
53+
it('handles module.exports and default import', () => {
54+
return bundle('mul_spec.js').then((output) => {
55+
// check that bundled tests work
56+
eval(output)
57+
// for some reason, this bundle included full resolved path
58+
// to interop require module
59+
// which on CI generates different path.
60+
// so as long as eval works, do not snapshot it
61+
})
62+
})
4563
})

test/fixtures/mul.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = (a, b) => a * b

test/fixtures/mul_spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import mul from './mul'
2+
3+
context('mul.js imports default', function () {
4+
it('imports function', () => {
5+
expect(mul, 'mul').to.be.a('function')
6+
})
7+
it('can multiply numbers', function () {
8+
expect(mul(3, 2)).to.eq(6)
9+
})
10+
})

test/fixtures/sub.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const sub = (a, b) => a - b
2+
3+
module.exports = {sub}

test/fixtures/sub_spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { sub } from './sub'
2+
3+
context('sub.js', function () {
4+
it('imports function', () => {
5+
expect(sub, 'sub').to.be.a('function')
6+
})
7+
it('can subtract numbers', function () {
8+
expect(sub(1, 2)).to.eq(-1)
9+
})
10+
})

0 commit comments

Comments
 (0)