Skip to content

Commit 311ef14

Browse files
committed
Unit test custom commands 😇
1 parent 715c15d commit 311ef14

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

lib/index.spec.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* global describe, it */
2+
3+
var rewire = require('rewire')
4+
var sinon = require('sinon')
5+
var expect = require('chai').expect
6+
7+
var GitRevisionPlugin = rewire('.')
8+
9+
describe('git-revision-webpack-plugin (unit)', function () {
10+
describe('on setting custom commithash command', function () {
11+
it('should run the build on .apply', function () {
12+
var buildFile = sinon.spy()
13+
GitRevisionPlugin.__set__('buildFile', buildFile)
14+
15+
new GitRevisionPlugin({
16+
commithashCommand: 'custom commithash command'
17+
}).apply()
18+
19+
var commithashCall = buildFile.args.find(function (calls) {
20+
return calls[4] === 'COMMITHASH'
21+
})
22+
23+
expect(commithashCall[2]).to.eql('custom commithash command')
24+
})
25+
26+
it('should run the custom git command on .commithash', function () {
27+
var runGitCommand = sinon.spy()
28+
GitRevisionPlugin.__set__('runGitCommand', runGitCommand)
29+
30+
new GitRevisionPlugin({
31+
commithashCommand: 'custom commithash command'
32+
}).commithash()
33+
34+
expect(runGitCommand.args[0][1]).to.eql('custom commithash command')
35+
})
36+
})
37+
38+
describe('on setting custom version command', function () {
39+
it('should run the build on .apply', function () {
40+
var buildFile = sinon.spy()
41+
GitRevisionPlugin.__set__('buildFile', buildFile)
42+
43+
new GitRevisionPlugin({
44+
versionCommand: 'custom version command'
45+
}).apply()
46+
47+
var commithashCall = buildFile.args.find(function (calls) {
48+
return calls[4] === 'VERSION'
49+
})
50+
51+
expect(commithashCall[2]).to.eql('custom version command')
52+
})
53+
54+
it('should run the custom git command on .version', function () {
55+
var runGitCommand = sinon.spy()
56+
GitRevisionPlugin.__set__('runGitCommand', runGitCommand)
57+
58+
new GitRevisionPlugin({
59+
versionCommand: 'custom version command'
60+
}).version()
61+
62+
expect(runGitCommand.args[0][1]).to.eql('custom version command')
63+
})
64+
})
65+
})

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
"file-loader": "^0.8.5",
3535
"fs-extra": "^0.30.0",
3636
"mocha": "^2.4.5",
37+
"rewire": "^2.5.2",
38+
"sinon": "^1.17.5",
3739
"standard": "^6.0.5",
3840
"webpack": "^1.13.0"
3941
}

0 commit comments

Comments
 (0)