mirror of
https://github.com/remoteintech/remote-jobs
synced 2024-12-29 05:43:09 +00:00
41 lines
1.1 KiB
JavaScript
41 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 };
|
||
|
};
|