Skip to content

Commit d8d3280

Browse files
authored
Add a new decorator @requires_npm_package('package-name') (#24430)
Add a new decorator `@requires_npm_package('package-name')` to allow disabling tests that require on a specific NPM development package. This allows running the test suite with production-only packages.
1 parent 83b9faf commit d8d3280

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

test/common.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,23 @@ def decorated(self, *args, **kwargs):
274274
return decorated
275275

276276

277+
# Used to mark dependencies in various tests to npm developer dependency
278+
# packages, which might not be installed on Emscripten end users' systems.
279+
def requires_dev_dependency(package):
280+
assert not callable(package)
281+
282+
def decorator(f):
283+
assert callable(f)
284+
285+
@wraps(f)
286+
def decorated(self, *args, **kwargs):
287+
if 'EMTEST_SKIP_NODE_DEV_PACKAGES' in os.environ:
288+
self.skipTest(f'test requires npm development package "{package}" and EMTEST_SKIP_NODE_DEV_PACKAGES is set')
289+
f(self, *args, **kwargs)
290+
return decorated
291+
return decorator
292+
293+
277294
def requires_wasm64(func):
278295
assert callable(func)
279296

test/test_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from common import RunnerCore, path_from_root, requires_native_clang, test_file, create_file
2727
from common import skip_if, no_windows, no_mac, is_slow_test, parameterized, parameterize
2828
from common import env_modify, with_env_modify, disabled, flaky, node_pthreads, also_with_wasm_bigint
29-
from common import read_file, read_binary, requires_v8, requires_node, requires_wasm2js, requires_node_canary
29+
from common import read_file, read_binary, requires_v8, requires_node, requires_dev_dependency, requires_wasm2js, requires_node_canary
3030
from common import compiler_for, crossplatform, no_4gb, no_2gb, also_with_minimal_runtime, also_with_modularize
3131
from common import with_all_fs, also_with_nodefs, also_with_nodefs_both, also_with_noderawfs, also_with_wasmfs
3232
from common import with_all_eh_sjlj, with_all_sjlj, also_with_standalone_wasm, can_do_standalone, no_wasm64, requires_wasm_eh, requires_jspi
@@ -7751,6 +7751,7 @@ def test_embind_sync_if_pthread_delayed(self):
77517751
@no_wasm2js('TODO: source maps in wasm2js')
77527752
@also_with_minimal_runtime
77537753
@requires_node
7754+
@requires_dev_dependency('source-map')
77547755
def test_source_map(self):
77557756
if '-g' not in self.emcc_args:
77567757
self.emcc_args.append('-g')

test/test_other.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from common import RunnerCore, path_from_root, is_slow_test, ensure_dir, disabled, make_executable
3535
from common import env_modify, no_mac, no_windows, only_windows, requires_native_clang, with_env_modify
3636
from common import create_file, parameterized, NON_ZERO, node_pthreads, TEST_ROOT, test_file
37-
from common import compiler_for, EMBUILDER, requires_v8, requires_node, requires_wasm64, requires_node_canary
37+
from common import compiler_for, EMBUILDER, requires_v8, requires_node, requires_wasm64, requires_node_canary, requires_dev_dependency
3838
from common import requires_wasm_eh, crossplatform, with_all_eh_sjlj, with_all_sjlj, requires_jspi
3939
from common import also_with_standalone_wasm, also_with_wasm2js, also_with_noderawfs
4040
from common import also_with_modularize, also_with_wasmfs, with_all_fs
@@ -3463,6 +3463,7 @@ def test_jspi_add_function(self):
34633463
'-Wno-experimental']
34643464
self.do_runf('other/test_jspi_add_function.c', 'done')
34653465

3466+
@requires_dev_dependency('typescript')
34663467
@parameterized({
34673468
'commonjs': [['-sMODULARIZE'], ['--module', 'commonjs', '--moduleResolution', 'node']],
34683469
'esm': [['-sEXPORT_ES6'], ['--module', 'NodeNext', '--moduleResolution', 'nodenext']],
@@ -3488,6 +3489,7 @@ def test_embind_tsgen_end_to_end(self, opts, tsc_opts):
34883489
self.assertContained('main ran\nts ran', self.run_js('main.js'))
34893490

34903491
@is_slow_test
3492+
@requires_dev_dependency('typescript')
34913493
def test_embind_tsgen_ignore(self):
34923494
create_file('fail.js', 'assert(false);')
34933495
self.emcc_args += ['-lembind', '--emit-tsd', 'embind_tsgen.d.ts']
@@ -3634,6 +3636,7 @@ def test_embind_jsgen_method_pointer_stability(self):
36343636
# AOT JS generation still works correctly.
36353637
self.do_runf('other/embind_jsgen_method_pointer_stability.cpp', 'done')
36363638

3639+
@requires_dev_dependency('typescript')
36373640
def test_emit_tsd(self):
36383641
self.run_process([EMCC, test_file('other/test_emit_tsd.c'),
36393642
'--emit-tsd', 'test_emit_tsd.d.ts', '-sEXPORT_ES6',
@@ -3645,6 +3648,7 @@ def test_emit_tsd(self):
36453648
cmd = shared.get_npm_cmd('tsc') + [test_file('other/test_tsd.ts'), '--noEmit']
36463649
shared.check_call(cmd)
36473650

3651+
@requires_dev_dependency('typescript')
36483652
def test_emit_tsd_sync_compilation(self):
36493653
self.run_process([EMCC, test_file('other/test_emit_tsd.c'),
36503654
'--emit-tsd', 'test_emit_tsd_sync.d.ts',
@@ -14389,6 +14393,7 @@ def test_hello_function(self):
1438914393
'O3': (['-O3'],),
1439014394
})
1439114395
@crossplatform
14396+
@requires_dev_dependency('es-check')
1439214397
def test_es5_transpile(self, args):
1439314398
self.emcc_args += ['-Wno-transpile'] + args
1439414399

@@ -16030,6 +16035,7 @@ def test_late_module_api_assignment(self):
1603016035
self.do_runf('hello_world.c', expected, emcc_args=['--post-js=post.js', '-sWASM_ASYNC_COMPILATION=0'], assert_returncode=NON_ZERO)
1603116036

1603216037
@crossplatform
16038+
@requires_dev_dependency('rollup')
1603316039
def test_rollup(self):
1603416040
copytree(test_file('rollup_node'), '.')
1603516041
self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6', '-sEXIT_RUNTIME', '-sENVIRONMENT=node', '-sMODULARIZE', '-o', 'hello.mjs'])

0 commit comments

Comments
 (0)