2016-07-27 02:51:32 +00:00
2019-10-08 18:45:38 +00:00
const glob = require ( 'glob' ) . sync ;
const readFile = require ( 'fs' ) . readFileSync ;
2016-07-27 02:51:32 +00:00
const IMPORT _REGEX = /(import|require).*common\/script/ ;
describe ( 'Use Proper Babel Paths' , ( ) => {
it ( 'uses proper babel files in website/server' , ( ) => {
2019-10-08 18:45:38 +00:00
const websiteServerPaths = glob ( './website/server/**/*.js' ) ;
2016-07-27 02:51:32 +00:00
if ( websiteServerPaths . length === 0 ) {
throw new Error ( 'Could not find any files in website/server/**/*.js' ) ;
}
2019-10-08 18:45:38 +00:00
websiteServerPaths . forEach ( filePath => {
const file = readFile ( filePath , { encoding : 'utf8' } ) ;
2016-07-27 02:51:32 +00:00
try {
expect ( file ) . to . not . match ( IMPORT _REGEX ) ;
} catch ( err ) {
// Nicer error reporting if this condition is violated
throw new Error ( ` ${ filePath } contains an invalid import statement to common/script, which will work in development but fail in production. See README in this directory for more details. ` ) ;
}
} ) ;
} ) ;
} ) ;