UNPKG

postman-runtime

Version:

Underlying library of executing Postman Collections (used by Newman)

185 lines (151 loc) 7.13 kB
/** * @fileOverview This test specs runs tests on the package.json file of repository. It has a set of strict tests on the * content of the file as well. Any change to package.json must be accompanied by valid test case in this spec-sheet. */ var _ = require('lodash'), yml = require('js-yaml'), parseIgnore = require('parse-gitignore'), fs = require('fs'); describe('project repository', function () { describe('package.json', function () { var content, json; it('should exist', function (done) { fs.stat('./package.json', done); }); it('should have readable JSON content', function () { expect(content = fs.readFileSync('./package.json').toString(), 'Should have readable content').to.be.ok; }); it('should have valid JSON content', function () { expect(json = JSON.parse(content), 'Should have valid JSON content').to.be.ok; }); describe('package.json JSON data', function () { it('should have valid name, description and author', function () { expect(json).to.deep.include({ name: 'postman-runtime', description: 'Underlying library of executing Postman Collections (used by Newman)', author: 'Postman Labs <help@getpostman.com>', license: 'Apache-2.0' }); }); it('should have a valid version string in form of <major>.<minor>.<revision>', function () { expect(json.version) // eslint-disable-next-line max-len .to.match(/^((\d+)\.(\d+)\.(\d+))(?:-([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?(?:\+([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?$/); }); }); describe('script definitions', function () { it('should have valid, existing files', function () { var scriptRegex = /^node\snpm\/.+\.js$/; expect(json.scripts).to.be.ok; json.scripts && Object.keys(json.scripts).forEach(function (scriptName) { if (scriptName === 'memory-check') { return; } expect(json.scripts[scriptName]).to.match(scriptRegex); expect(fs.statSync('npm/' + scriptName + '.js')).to.be.ok; }); }); it('should have the hashbang defined', function () { json.scripts && Object.keys(json.scripts).forEach(function (scriptName) { if (scriptName === 'memory-check') { return; } var fileContent = fs.readFileSync('npm/' + scriptName + '.js').toString(); expect(fileContent).to.match(/^#!\/(bin\/bash|usr\/bin\/env\snode)[\r\n][\W\w]*$/g); }); }); }); describe('dependencies', function () { it('should exist', function () { expect(json.dependencies).to.be.an('object'); }); it('should point to a valid semver', function () { var packages = _.without(Object.keys(json.dependencies), // These are trusted packages 'postman-request', 'postman-collection', 'serialised-error'); packages.forEach(function (dependencyName) { expect(json.dependencies[dependencyName]).to.match(new RegExp('^((\\d+)\\.(\\d+)\\.(\\d+))(?:-' + '([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?(?:\\+([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?$')); }); }); }); describe('devDependencies', function () { it('should exist', function () { expect(json.devDependencies).to.be.an('object'); }); it('should point to a valid semver', function () { Object.keys(json.devDependencies).forEach(function (dependencyName) { expect(json.devDependencies[dependencyName]).to.match(new RegExp('((\\d+)\\.(\\d+)\\.(\\d+))(?:-' + '([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?(?:\\+([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?$')); }); }); it('should not overlap devDependencies', function () { var clean = []; Object.keys(json.devDependencies).forEach(function (dependencyName) { !json.dependencies[dependencyName] && clean.push(dependencyName); }); expect(Object.keys(json.devDependencies)).to.eql(clean); }); }); describe('main entry script', function () { it('should point to a valid file', function (done) { expect(json.main).to.equal('index.js'); fs.stat(json.main, done); }); }); }); describe('README.md', function () { it('should exist', function (done) { fs.stat('./README.md', done); }); it('should have readable content', function () { expect(fs.readFileSync('./README.md').toString()).to.be.ok; }); }); describe('LICENSE.md', function () { it('should exist', function (done) { fs.stat('./LICENSE.md', done); }); it('should have readable content', function () { expect(fs.readFileSync('./LICENSE.md').toString()).to.be.ok; }); }); describe('.gitattributes', function () { it('should exist', function (done) { fs.stat('./.gitattributes', done); }); it('should have readable content', function () { expect(fs.readFileSync('./.gitattributes').toString()).to.be.ok; }); }); describe('.ignore files', function () { var gitignorePath = '.gitignore', npmignorePath = '.npmignore', npmignore = parseIgnore(npmignorePath), gitignore = parseIgnore(gitignorePath); describe(gitignorePath, function () { it('should exist', function (done) { fs.stat(gitignorePath, done); }); it('should have valid content', function () { expect(gitignore).to.not.be.empty; }); }); describe(npmignorePath, function () { it('should exist', function (done) { fs.stat(npmignorePath, done); }); it('should have valid content', function () { expect(npmignore).to.not.be.empty; }); }); it('should have .gitignore coverage must be a subset of .npmignore coverage', function () { expect(_.intersection(gitignore, npmignore)).to.eql(gitignore); }); }); describe('CHANGELOG.yaml', function () { it('should exist', function (done) { fs.stat('./CHANGELOG.yaml', done); }); it('should have readable content', function () { expect(yml.safeLoad(fs.readFileSync('./CHANGELOG.yaml')), 'not a valid yaml').to.be.ok; }); }); });