MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / CompiledServerHarness

Class CompiledServerHarness

test/test_sockets.py:159–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157
158
159class CompiledServerHarness:
160 def __init__(self, filename, args, listen_port):
161 self.process = None
162 self.filename = filename
163 self.listen_port = listen_port
164 self.args = args or []
165
166 def __enter__(self):
167 # assuming this is only used for WebSocket tests at the moment, validate that
168 # the ws module is installed
169 global npm_checked
170 if not npm_checked:
171 child = run_process([*config.NODE_JS, '-e', 'require("ws");'], check=False)
172 assert child.returncode == 0, '"ws" node module not found. Run "npm install" to obtain Node.js dev dependencies, or set environment variable EMTEST_SKIP_NODE_DEV_PACKAGES=1 to skip this test.'
173 npm_checked = True
174
175 # compile the server
176 suffix = '.mjs' if '-sEXPORT_ES6' in self.args else '.js'
177 proc = run_process([EMCC, '-Werror', test_file(self.filename), '-o', 'server' + suffix, f'-DSOCKK={self.listen_port}', *self.args])
178 print('Socket server build: out:', proc.stdout or '', '/ err:', proc.stderr or '')
179
180 self.process = Popen([*config.NODE_JS, 'server' + suffix])
181 return self
182
183 def __exit__(self, *args, **kwargs):
184 clean_process(self.process)
185
186 # always run these tests last
187 # make sure to use different ports in each one because it takes a while for the processes to be cleaned up
188
189
190# Executes a native executable server process

Calls

no outgoing calls