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

Commit bd1724f

Browse files
committed
add imports and exports e2e test
1 parent 593eebd commit bd1724f

File tree

8 files changed

+71
-7
lines changed

8 files changed

+71
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ module.exports = (on) => {
165165
}
166166
```
167167

168+
## Debugging
169+
170+
Execute code with `DEBUG=cypress:browserify` environment variable.
171+
168172
## Contributing
169173

170174
Run all tests once:

__snapshots__/e2e_spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,36 @@ it('is a test', function () {
1414
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJ0ZXN0L2ZpeHR1cmVzL2V4YW1wbGVfc3BlYy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7O0FDQUEsRUFBRSxDQUFDLFdBQUQsRUFBYyxZQUFNO0FBQUEsTUFDYixDQURhLEdBQ0osQ0FESTtBQUFBLE1BQ1YsQ0FEVSxHQUNELENBREM7QUFFcEIsRUFBQSxNQUFNLENBQUMsQ0FBRCxDQUFOLENBQVUsRUFBVixDQUFhLEtBQWIsQ0FBbUIsQ0FBbkI7QUFDQSxFQUFBLE1BQU0sQ0FBQyxDQUFELENBQU4sQ0FBVSxFQUFWLENBQWEsS0FBYixDQUFtQixDQUFuQjtBQUNBLEVBQUEsTUFBTSxDQUFDLElBQUksQ0FBQyxHQUFMLE9BQUEsSUFBSSxFQUFRLENBQUMsQ0FBRCxFQUFJLENBQUosQ0FBUixDQUFMLENBQU4sQ0FBNEIsRUFBNUIsQ0FBK0IsS0FBL0IsQ0FBcUMsQ0FBckM7QUFDRCxDQUxDLENBQUYiLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXNDb250ZW50IjpbIihmdW5jdGlvbigpe2Z1bmN0aW9uIHIoZSxuLHQpe2Z1bmN0aW9uIG8oaSxmKXtpZighbltpXSl7aWYoIWVbaV0pe3ZhciBjPVwiZnVuY3Rpb25cIj09dHlwZW9mIHJlcXVpcmUmJnJlcXVpcmU7aWYoIWYmJmMpcmV0dXJuIGMoaSwhMCk7aWYodSlyZXR1cm4gdShpLCEwKTt2YXIgYT1uZXcgRXJyb3IoXCJDYW5ub3QgZmluZCBtb2R1bGUgJ1wiK2krXCInXCIpO3Rocm93IGEuY29kZT1cIk1PRFVMRV9OT1RfRk9VTkRcIixhfXZhciBwPW5baV09e2V4cG9ydHM6e319O2VbaV1bMF0uY2FsbChwLmV4cG9ydHMsZnVuY3Rpb24ocil7dmFyIG49ZVtpXVsxXVtyXTtyZXR1cm4gbyhufHxyKX0scCxwLmV4cG9ydHMscixlLG4sdCl9cmV0dXJuIG5baV0uZXhwb3J0c31mb3IodmFyIHU9XCJmdW5jdGlvblwiPT10eXBlb2YgcmVxdWlyZSYmcmVxdWlyZSxpPTA7aTx0Lmxlbmd0aDtpKyspbyh0W2ldKTtyZXR1cm4gb31yZXR1cm4gcn0pKCkiLCJpdCgnaXMgYSB0ZXN0JywgKCkgPT4ge1xuICBjb25zdCBbYSwgYl0gPSBbMSwgMl1cbiAgZXhwZWN0KGEpLnRvLmVxdWFsKDEpXG4gIGV4cGVjdChiKS50by5lcXVhbCgyKVxuICBleHBlY3QoTWF0aC5taW4oLi4uWzMsIDRdKSkudG8uZXF1YWwoMylcbn0pXG4iXX0=
1515
1616
`
17+
18+
exports['math default exports'] = `
19+
(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){
20+
"use strict";
21+
22+
Object.defineProperty(exports, "__esModule", {
23+
value: true
24+
});
25+
exports["default"] = void 0;
26+
var _default = {
27+
add: function add(a, b) {
28+
return a + b;
29+
}
30+
};
31+
exports["default"] = _default;
32+
33+
},{}],2:[function(require,module,exports){
34+
"use strict";
35+
36+
var _math = require("./math");
37+
38+
context('math.js', function () {
39+
it('imports function', function () {
40+
expect(_math.add, 'add').to.be.a('function');
41+
});
42+
it('can add numbers', function () {
43+
expect((0, _math.add)(1, 2)).to.eq(3);
44+
});
45+
});
46+
47+
},{"./math":1}]},{},[2]);
48+
49+
`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"ban": "ban",
2727
"deps": "deps-ok && dependency-check --no-dev .",
2828
"license": "license-checker --production --onlyunknown --csv",
29-
"lint": "eslint --fix *.js",
29+
"lint": "eslint --fix '*.js' 'test/unit/*.js' 'test/e2e/*.js'",
3030
"secure": "nsp check",
3131
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
3232
"precommit": "npm run lint",

test/e2e/e2e_spec.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,29 @@ beforeEach(function () {
88
fs.removeSync(path.join(__dirname, '_test-output'))
99
})
1010

11-
const bundle = (fixtureName) => {
11+
const bundle = (fixtureName, options) => {
1212
const on = () => {}
1313
const filePath = path.join(__dirname, '..', 'fixtures', fixtureName)
14-
const outputPath = path.join(__dirname, '..', '_test-output', 'output.js')
15-
return preprocessor()({ filePath, outputPath, on }).then(() => {
16-
return fs.readFileSync(outputPath).toString()
17-
})
14+
const outputPath = path.join(__dirname, '..', '_test-output', 'output.js')
15+
16+
return preprocessor(options)({ filePath, outputPath, on }).then(() => {
17+
return fs.readFileSync(outputPath).toString()
18+
})
1819
}
1920

2021
describe('browserify preprocessor - e2e', function () {
2122
it('correctly preprocesses the file', function () {
22-
return bundle('example_spec.js').then(output => {
23+
return bundle('example_spec.js').then((output) => {
2324
snapshot(output)
2425
})
2526
})
2627
})
28+
29+
describe('imports and exports', () => {
30+
it('handles imports and exports', () => {
31+
// do not generate source maps
32+
return bundle('math_spec.js', { browserifyOptions: { debug: false } }).then((output) => {
33+
snapshot('math default exports', output)
34+
})
35+
})
36+
})

test/fixtures/example_spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
it('is a test', () => {
22
const [a, b] = [1, 2]
3+
34
expect(a).to.equal(1)
45
expect(b).to.equal(2)
56
expect(Math.min(...[3, 4])).to.equal(3)

test/fixtures/math.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
add: (a, b) => {
3+
return a + b
4+
},
5+
}

test/fixtures/math_spec.js

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

test/unit/index_spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ describe('browserify preprocessor', function () {
272272

273273
it('false if user has explicitly set to false', function () {
274274
this.options.browserifyOptions = { debug: false }
275+
275276
return this.run().then(() => {
276277
expect(browserify.lastCall.args[0].debug).to.be.false
277278
})

0 commit comments

Comments
 (0)