11import { npmCommand } from '../../src/lib/tools.js' ;
2+ import { glslifyInit , glslifyProcessSource } from '../../src/lib/glslify.js' ;
23import { rollup } from 'rollup' ;
34import { assert } from 'chai' ;
45import * as fsSync from 'fs' ;
56
7+ const consoleOrig = global . console ;
8+ let outBuf ;
9+ function mockConsoleError ( ) {
10+ outBuf = '' ;
11+ global . console = { ...consoleOrig } ;
12+ global . console . error = ( ...args ) => {
13+ outBuf += `${ args . map ( String ) . join ( ' ' ) } \n` ;
14+ } ;
15+ global . console . warn = global . console . error ;
16+ }
17+ function unMockConsoleError ( ) {
18+ global . console = consoleOrig ;
19+ return outBuf ;
20+ }
21+
622async function glslifyUninstall ( ) {
723 await npmCommand ( [ 'uninstall' , 'glslify' , 'glsl-noise' ] ) ;
824 assert . isFalse ( fsSync . existsSync ( 'node_modules/glslify' ) , 'glslify failed to uninstall' ) ;
@@ -13,7 +29,6 @@ async function glslifyInstall() {
1329 assert . isTrue ( fsSync . existsSync ( 'node_modules/glslify' ) , 'glslify failed to install' ) ;
1430}
1531
16-
1732/**
1833 * @param {typeof import('../../src/index.js').default } glslOptimize
1934 */
@@ -33,6 +48,14 @@ export function glslifyTests(glslOptimize) {
3348 this . timeout ( 30000 ) ;
3449 before ( 'install glslify' , glslifyInstall ) ;
3550 after ( 'uninstall glslify' , glslifyUninstall ) ;
51+ it ( 'should warn about glslify failing to find includes' , async function ( ) {
52+ await glslifyInit ( ) ;
53+ mockConsoleError ( ) ;
54+ await glslifyProcessSource ( 'does/not/exist/' , '' , { basedir : '/does/not/exist' } , ( message ) => {
55+ throw new Error ( message ) ;
56+ } ) ;
57+ assert . include ( unMockConsoleError ( ) , 'glslify may fail to find includes' ) ;
58+ } ) ;
3659 it ( 'should pass with glslify enabled but unused' , async function ( ) {
3760 const bundle = await rollup ( {
3861 input : 'test/fixtures/basic.js' ,
0 commit comments