remote-jobs/test/lib/index.js
James Nylen 8942a91a85
Add automated tests for validation script (#438)
* Update node

* Add mocha and chai

* Fix npm audit issue

https://nodesecurity.io/advisories/577

* Skip some redundant errors

* Catch duplicate headings

* Update the wording of a few errors

* Detect when headings are wrapped inside another element

* Build and validate the content of each profile section

* Add tests for validation script

* Remove empty sections in existing profiles
2018-06-22 23:50:06 -05:00

40 lines
1.1 KiB
JavaScript

const path = require( 'path' );
const fs = require( 'fs' );
const { spawnSync } = require( 'child_process' );
const { expect } = require( 'chai' );
const fixturesPath = path.join( __dirname, '..', 'fixtures' );
const validatePath = path.join( __dirname, '..', '..', 'bin', 'validate.js' );
exports.runValidationWithFixtures = ( dirName, env = {} ) => {
const result = spawnSync( process.execPath, [
validatePath,
path.join( fixturesPath, dirName ),
], { env } );
if ( result.error ) {
throw result.error;
}
expect( result.stderr.toString() ).to.equal( '' );
const output = result.stdout.toString().trim().split( '\n' );
const exitCode = result.status;
expect( output[ output.length - 1 ] ).to.equal(
exitCode + ' problem' + ( exitCode === 1 ? '' : 's' ) + ' detected'
);
if ( output.length >= 2 ) {
expect( output[ output.length - 2 ] ).to.equal( '' );
output.splice( -2 );
} else {
output.splice( -1 );
}
if ( process.env.DUMP_OUTPUT ) {
output.forEach( s => console.log( "'%s',", s.replace( /'/g, "\\'" ) ) );
}
return { output, exitCode };
};