@@ -5347,6 +5347,35 @@ def test_wasmfs_opfs_errors(self):
53475347 args = ['-sWASMFS' , '-pthread' , '-sPROXY_TO_PTHREAD' , '--post-js' , postjs ]
53485348 self .btest (test , cflags = args , expected = '0' )
53495349
5350+ def test_wasmfs_multi_environment (self ):
5351+ # Test that WasmFS's Node backend can be enabled conditionally, allowing
5352+ # the same binaries to run on both web and Node.js environments.
5353+ create_file ('main.c' , r'''
5354+ #include <stdio.h>
5355+ #include <assert.h>
5356+ #include <unistd.h>
5357+
5358+ #include <emscripten/emscripten.h>
5359+ #include <emscripten/wasmfs.h>
5360+
5361+ EM_JS(bool, is_node, (), { return ENVIRONMENT_IS_NODE; });
5362+
5363+ // This is equivalent to building with `-sWASMFS -sNODERAWFS`, except
5364+ // that the Wasm binary can also be used on the web.
5365+ backend_t wasmfs_create_root_dir() {
5366+ return is_node() ? wasmfs_create_node_backend("")
5367+ : wasmfs_create_memory_backend();
5368+ }
5369+
5370+ int main(int argc, char** argv) {
5371+ printf("testing access to /tmp\n");
5372+ int rtn = access("/tmp", F_OK);
5373+ assert(rtn == 0);
5374+ return 0;
5375+ }
5376+ ''' )
5377+ self .btest_exit ('main.c' , cflags = ['-sWASMFS' , '-sENVIRONMENT=web,node' ])
5378+
53505379 @no_firefox ('no 4GB support yet' )
53515380 def test_emmalloc_memgrowth (self ):
53525381 if not self .is_4gb ():
0 commit comments