Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit c4556f2

Browse files
committed
add e2e test
1 parent 6e36d7c commit c4556f2

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
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
*.log*
4+
_test-output

__snapshots__/e2e_spec.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
"pretest": "npm run lint",
2929
"secure": "nsp check",
3030
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
31-
"test": "mocha",
32-
"test-watch": "chokidar '*.js' 'test/*.js' -c 'mocha'",
31+
"test": "npm run test-unit && npm run test-e2e",
32+
"test-e2e": "mocha test/e2e/*.js",
33+
"test-unit": "mocha test/unit/*.js",
34+
"test-debug": "node --inspect --debug-brk ./node_modules/.bin/_mocha",
35+
"test-watch": "chokidar '*.js' 'test/unit/*.js' -c 'npm run test-unit'",
3336
"semantic-release": "semantic-release pre && npm publish --access public && semantic-release post"
3437
},
3538
"devDependencies": {
@@ -46,6 +49,7 @@
4649
"eslint": "4.6.1",
4750
"eslint-plugin-cypress-dev": "1.1.1",
4851
"eslint-plugin-mocha": "4.11.0",
52+
"fs-extra": "8.1.0",
4953
"github-post-release": "1.13.1",
5054
"license-checker": "13.0.3",
5155
"mocha": "3.5.0",
@@ -56,6 +60,7 @@
5660
"simple-commit-message": "3.3.1",
5761
"sinon": "3.2.1",
5862
"sinon-chai": "2.13.0",
63+
"snap-shot-it": "7.9.0",
5964
"webpack": "^4.18.1"
6065
},
6166
"peerDependencies": {

test/e2e/e2e_spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const EventEmitter = require('events').EventEmitter
2+
const expect = require('chai').expect
3+
const fs = require('fs-extra')
4+
const path = require('path')
5+
const snapshot = require('snap-shot-it')
6+
7+
const preprocessor = require('../../index')
8+
9+
describe('webpack preprocessor - e2e', () => {
10+
const outputPath = path.join(__dirname, '..', '_test-output', 'output.js')
11+
12+
let file
13+
let filePath
14+
15+
beforeEach(() => {
16+
fs.removeSync(path.join(__dirname, '_test-output'))
17+
18+
const originalFilePath = path.join(__dirname, '..', 'fixtures', 'example_spec.js')
19+
20+
filePath = path.join(__dirname, '..', '_test-output', 'example_spec.js')
21+
fs.copyFileSync(originalFilePath, filePath)
22+
23+
file = Object.assign(new EventEmitter(), {
24+
filePath,
25+
outputPath,
26+
})
27+
})
28+
29+
it('correctly preprocesses the file', () => {
30+
return preprocessor()(file).then(() => {
31+
snapshot(fs.readFileSync(outputPath).toString())
32+
})
33+
})
34+
})

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
@@ -14,8 +14,8 @@ mockery.enable({
1414
})
1515
mockery.registerMock('webpack', webpack)
1616

17-
const preprocessor = require('../index')
18-
const stubbableRequire = require('../stubbable-require')
17+
const preprocessor = require('../../index')
18+
const stubbableRequire = require('../../stubbable-require')
1919

2020
describe('webpack preprocessor', function () {
2121
beforeEach(function () {

0 commit comments

Comments
 (0)