|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const chai = require('chai'); |
| 4 | +const lint = require('./../../../src/rules/prefer-property-order').lint; |
| 5 | + |
| 6 | +const should = chai.should(); |
| 7 | + |
| 8 | +describe('prefer-property-order Unit Tests', function() { |
| 9 | + context('when the properties in the package.json file are in the desired order', function() { |
| 10 | + it('true should be returned', function() { |
| 11 | + const packageJsonData = { |
| 12 | + name: 'awesome-module', |
| 13 | + version: '1.0.0', |
| 14 | + description: 'description' |
| 15 | + }; |
| 16 | + const preferredOrder = [ |
| 17 | + 'name', |
| 18 | + 'version', |
| 19 | + 'description' |
| 20 | + ]; |
| 21 | + const response = lint(packageJsonData, 'error', preferredOrder); |
| 22 | + |
| 23 | + response.should.be.true; |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + context('when the actual node list does not have the same number of nodes as the desired list', function() { |
| 28 | + it('LintIssue object should be returned', function() { |
| 29 | + const packageJsonData = { |
| 30 | + name: 'awesome-module', |
| 31 | + version: '1.0.0' |
| 32 | + }; |
| 33 | + const preferredOrder = [ |
| 34 | + 'name', |
| 35 | + 'version', |
| 36 | + 'description' |
| 37 | + ]; |
| 38 | + const response = lint(packageJsonData, 'error', preferredOrder); |
| 39 | + |
| 40 | + response.lintId.should.equal('prefer-property-order'); |
| 41 | + response.lintType.should.equal('error'); |
| 42 | + response.node.should.equal(''); |
| 43 | + response.lintMessage.should.equal('Your package.json properties are not in the desired order. Please add description at the end of the file.'); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + context('when the actual node list is in a different order than desired', function() { |
| 48 | + it('LintIssue object should be returned', function() { |
| 49 | + const packageJsonData = { |
| 50 | + name: 'awesome-module', |
| 51 | + description: 'description', |
| 52 | + version: '1.0.0' |
| 53 | + }; |
| 54 | + const preferredOrder = [ |
| 55 | + 'name', |
| 56 | + 'version', |
| 57 | + 'description' |
| 58 | + ]; |
| 59 | + const response = lint(packageJsonData, 'error', preferredOrder); |
| 60 | + |
| 61 | + response.lintId.should.equal('prefer-property-order'); |
| 62 | + response.lintType.should.equal('error'); |
| 63 | + response.node.should.equal(''); |
| 64 | + response.lintMessage.should.equal('Your package.json properties are not in the desired order. Please move description after version.'); |
| 65 | + }); |
| 66 | + }); |
| 67 | +}); |
0 commit comments