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

Commit a6cb120

Browse files
committed
add simple e2e test
1 parent 51bdaca commit a6cb120

File tree

7 files changed

+52
-5
lines changed

7 files changed

+52
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
.DS_Store
33
npm-debug.log
4+
_test-output

__snapshots__/e2e_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
exports['browserify preprocessor - e2e correctly preprocesses the file 1'] = `
2+
(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){
3+
'use strict';
4+
5+
it('is a test', function () {
6+
var a = 1,
7+
b = 2;
8+
9+
expect(a).to.equal(1);
10+
expect(b).to.equal(2);
11+
expect(Math.min.apply(Math, [3, 4])).to.equal(3);
12+
});
13+
14+
},{}]},{},[1]);
15+
16+
`

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
3232
"precommit": "npm run lint",
3333
"pretest": "npm run lint",
34-
"test": "mocha",
34+
"test": "npm run test-unit && npm run test-e2e",
35+
"test-e2e": "mocha test/e2e/*.js",
36+
"test-unit": "mocha test/unit/*.js",
3537
"test-debug": "node --inspect --debug-brk ./node_modules/.bin/_mocha",
36-
"test-watch": "chokidar '*.js' 'test/*.js' -c 'npm test'",
38+
"test-watch": "chokidar '*.js' 'test/unit/*.js' -c 'npm test'",
3739
"semantic-release": "semantic-release pre && npm publish --access public && semantic-release post"
3840
},
3941
"devDependencies": {
@@ -56,7 +58,8 @@
5658
"semantic-release": "8.2.0",
5759
"simple-commit-message": "3.3.1",
5860
"sinon": "3.2.1",
59-
"sinon-chai": "2.13.0"
61+
"sinon-chai": "2.13.0",
62+
"snap-shot-it": "5.0.1"
6063
},
6164
"dependencies": {
6265
"babel-plugin-add-module-exports": "0.2.1",

test/e2e/e2e_spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const path = require('path')
2+
const snapshot = require('snap-shot-it')
3+
4+
const fs = require('../../fs')
5+
const preprocessor = require('../../index')
6+
7+
describe('browserify preprocessor - e2e', function () {
8+
const on = () => {}
9+
10+
beforeEach(function () {
11+
fs.removeSync(path.join(__dirname, '_test-output'))
12+
})
13+
14+
it('correctly preprocesses the file', function () {
15+
const filePath = path.join(__dirname, '..', 'fixtures', 'example_spec.js')
16+
const outputPath = path.join(__dirname, '..', '_test-output', 'output.js')
17+
return preprocessor()({ filePath, outputPath, on }).then(() => {
18+
snapshot(fs.readFileSync(outputPath).toString())
19+
})
20+
})
21+
})

test/e2e/output.js

Whitespace-only changes.

test/fixtures/example_spec.js

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

test/index_spec.js renamed to test/unit/index_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const streamApi = {
2020
}
2121
streamApi.on = sandbox.stub().returns(streamApi)
2222

23-
const fs = require('../fs')
24-
const preprocessor = require('../index')
23+
const fs = require('../../fs')
24+
const preprocessor = require('../../index')
2525

2626
describe('browserify preprocessor', function () {
2727
beforeEach(function () {

0 commit comments

Comments
 (0)