|
| 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 | +}) |
0 commit comments