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

Commit

Permalink
add imports and exports e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Feb 5, 2020
1 parent 593eebd commit bd1724f
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ module.exports = (on) => {
}
```

## Debugging

Execute code with `DEBUG=cypress:browserify` environment variable.

## Contributing

Run all tests once:
Expand Down
33 changes: 33 additions & 0 deletions __snapshots__/e2e_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,36 @@ it('is a test', function () {
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJ0ZXN0L2ZpeHR1cmVzL2V4YW1wbGVfc3BlYy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7O0FDQUEsRUFBRSxDQUFDLFdBQUQsRUFBYyxZQUFNO0FBQUEsTUFDYixDQURhLEdBQ0osQ0FESTtBQUFBLE1BQ1YsQ0FEVSxHQUNELENBREM7QUFFcEIsRUFBQSxNQUFNLENBQUMsQ0FBRCxDQUFOLENBQVUsRUFBVixDQUFhLEtBQWIsQ0FBbUIsQ0FBbkI7QUFDQSxFQUFBLE1BQU0sQ0FBQyxDQUFELENBQU4sQ0FBVSxFQUFWLENBQWEsS0FBYixDQUFtQixDQUFuQjtBQUNBLEVBQUEsTUFBTSxDQUFDLElBQUksQ0FBQyxHQUFMLE9BQUEsSUFBSSxFQUFRLENBQUMsQ0FBRCxFQUFJLENBQUosQ0FBUixDQUFMLENBQU4sQ0FBNEIsRUFBNUIsQ0FBK0IsS0FBL0IsQ0FBcUMsQ0FBckM7QUFDRCxDQUxDLENBQUYiLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXNDb250ZW50IjpbIihmdW5jdGlvbigpe2Z1bmN0aW9uIHIoZSxuLHQpe2Z1bmN0aW9uIG8oaSxmKXtpZighbltpXSl7aWYoIWVbaV0pe3ZhciBjPVwiZnVuY3Rpb25cIj09dHlwZW9mIHJlcXVpcmUmJnJlcXVpcmU7aWYoIWYmJmMpcmV0dXJuIGMoaSwhMCk7aWYodSlyZXR1cm4gdShpLCEwKTt2YXIgYT1uZXcgRXJyb3IoXCJDYW5ub3QgZmluZCBtb2R1bGUgJ1wiK2krXCInXCIpO3Rocm93IGEuY29kZT1cIk1PRFVMRV9OT1RfRk9VTkRcIixhfXZhciBwPW5baV09e2V4cG9ydHM6e319O2VbaV1bMF0uY2FsbChwLmV4cG9ydHMsZnVuY3Rpb24ocil7dmFyIG49ZVtpXVsxXVtyXTtyZXR1cm4gbyhufHxyKX0scCxwLmV4cG9ydHMscixlLG4sdCl9cmV0dXJuIG5baV0uZXhwb3J0c31mb3IodmFyIHU9XCJmdW5jdGlvblwiPT10eXBlb2YgcmVxdWlyZSYmcmVxdWlyZSxpPTA7aTx0Lmxlbmd0aDtpKyspbyh0W2ldKTtyZXR1cm4gb31yZXR1cm4gcn0pKCkiLCJpdCgnaXMgYSB0ZXN0JywgKCkgPT4ge1xuICBjb25zdCBbYSwgYl0gPSBbMSwgMl1cbiAgZXhwZWN0KGEpLnRvLmVxdWFsKDEpXG4gIGV4cGVjdChiKS50by5lcXVhbCgyKVxuICBleHBlY3QoTWF0aC5taW4oLi4uWzMsIDRdKSkudG8uZXF1YWwoMylcbn0pXG4iXX0=
`

exports['math default exports'] = `
(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";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _default = {
add: function add(a, b) {
return a + b;
}
};
exports["default"] = _default;
},{}],2:[function(require,module,exports){
"use strict";
var _math = require("./math");
context('math.js', function () {
it('imports function', function () {
expect(_math.add, 'add').to.be.a('function');
});
it('can add numbers', function () {
expect((0, _math.add)(1, 2)).to.eq(3);
});
});
},{"./math":1}]},{},[2]);
`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ban": "ban",
"deps": "deps-ok && dependency-check --no-dev .",
"license": "license-checker --production --onlyunknown --csv",
"lint": "eslint --fix *.js",
"lint": "eslint --fix '*.js' 'test/unit/*.js' 'test/e2e/*.js'",
"secure": "nsp check",
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
"precommit": "npm run lint",
Expand Down
22 changes: 16 additions & 6 deletions test/e2e/e2e_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,29 @@ beforeEach(function () {
fs.removeSync(path.join(__dirname, '_test-output'))
})

const bundle = (fixtureName) => {
const bundle = (fixtureName, options) => {
const on = () => {}
const filePath = path.join(__dirname, '..', 'fixtures', fixtureName)
const outputPath = path.join(__dirname, '..', '_test-output', 'output.js')
return preprocessor()({ filePath, outputPath, on }).then(() => {
return fs.readFileSync(outputPath).toString()
})
const outputPath = path.join(__dirname, '..', '_test-output', 'output.js')

return preprocessor(options)({ filePath, outputPath, on }).then(() => {
return fs.readFileSync(outputPath).toString()
})
}

describe('browserify preprocessor - e2e', function () {
it('correctly preprocesses the file', function () {
return bundle('example_spec.js').then(output => {
return bundle('example_spec.js').then((output) => {
snapshot(output)
})
})
})

describe('imports and exports', () => {
it('handles imports and exports', () => {
// do not generate source maps
return bundle('math_spec.js', { browserifyOptions: { debug: false } }).then((output) => {
snapshot('math default exports', output)
})
})
})
1 change: 1 addition & 0 deletions test/fixtures/example_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
it('is a test', () => {
const [a, b] = [1, 2]

expect(a).to.equal(1)
expect(b).to.equal(2)
expect(Math.min(...[3, 4])).to.equal(3)
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/math.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
add: (a, b) => {
return a + b
},
}
10 changes: 10 additions & 0 deletions test/fixtures/math_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { add } from './math'

context('math.js', function () {
it('imports function', () => {
expect(add, 'add').to.be.a('function')
})
it('can add numbers', function () {
expect(add(1, 2)).to.eq(3)
})
})
1 change: 1 addition & 0 deletions test/unit/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ describe('browserify preprocessor', function () {

it('false if user has explicitly set to false', function () {
this.options.browserifyOptions = { debug: false }

return this.run().then(() => {
expect(browserify.lastCall.args[0].debug).to.be.false
})
Expand Down

0 comments on commit bd1724f

Please sign in to comment.