import 'mocha' ; import { expect } from 'chai' ; import WindowsData from 'raw-loader!@/application/collections/windows.yaml' ; import MacOsData from 'raw-loader!@/application/collections/macos.yaml' ; describe ( 'collection files to have no unintended inlining' , async ( ) => { const testCases = [ { name : 'macos' , fileContent : MacOsData , } , { name : 'windows' , fileContent : WindowsData , } , ] ; for ( const testCase of testCases ) { it ( `${ testCase . name }` , async ( ) => { const lines = await findBadLineNumbers ( testCase . fileContent ) ; expect ( lines ) . to . be . have . lengthOf ( 0 , printMessage ( ) ) ; function printMessage ( ) { return 'Did you intend to have multi-lined string in lines: ' + lines . map ( ( ( line ) => line . toString ( ) ) ) . join ( ', ' ) ; } } ) ; } } ) ; async function findBadLineNumbers ( fileContent ) { return [ ... findLineNumbersEndingWith ( fileContent , 'revertCode:' ) , ... findLineNumbersEndingWith ( fileContent , 'code:' ) , ] ; } function findLineNumbersEndingWith ( content , ending ) { sanityCheck ( content , ending ) ; return content . split ( /\r\n|\r|\n/ ) . map ( ( line , index ) => ( { text : line , index } ) ) . filter ( ( line ) => line . text . trim ( ) . endsWith ( ending ) ) . map ( ( line ) => line . index + 1 ) ; } function sanityCheck ( content , ending ) { if ( ! content . includes ( ending ) ) { throw new Error ( `File does not contain string "${ ending }" string at all.` + `Did the word "${ ending }" change? Or is this sanity check wrong?` ) ; } }