Debian Codegraph @

node/test/BUILD.bazel

raw
1 load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
2 load("@aspect_rules_js//js:defs.bzl", "js_library", "js_test")
3
4 package(default_visibility = ["//visibility:public"])
5
6 # Self-contained runtime sandbox mirroring an npm-install layout. node/opencc.js
7 # computes its package root from its own location and looks for the addon under
8 # <packageRoot>/build/Release, so the addon, its JS API, the config/dictionary
9 # assets, and the testcases are assembled into one tree here. The addon is
10 # located by a plain filesystem lookup (no node-gyp-build), so the test needs no
11 # npm packages at all.
12 copy_to_directory(
13 name = "node_test_release",
14 srcs = [
15 "//data/config:config",
16 "//data/dictionary:binary_dictionaries",
17 "//node:js_srcs",
18 "//node:opencc",
19 "//scripts:prepare_node_prebuild_artifacts",
20 "//test/testcases:testcases_js",
21 ],
22 out = "sandbox",
23 replace_prefixes = {
24 "node/opencc.node": "build/Release/opencc.node",
25 "data/config": "build/Release",
26 "data/dictionary": "build/Release",
27 },
28 )
29
30 js_library(
31 name = "test_entry",
32 srcs = ["test_entry.js"],
33 )
34
35 # Run node/test.js with Node's built-in test runner against the Bazel-built
36 # addon. node:test ships with the Node runtime and opencc.js locates the addon
37 # without node-gyp-build, so the test has no npm dependencies (no pnpm-lock).
38 js_test(
39 name = "node_test",
40 size = "medium",
41 data = [
42 ":node_test_release",
43 ":test_entry",
44 ],
45 entry_point = "test_entry.js",
46 # Force the concise spec reporter; otherwise node:test defaults to the
47 # verbose TAP reporter when stdout is not a TTY (e.g. under Bazel/CI).
48 node_options = [
49 "--test-reporter=spec",
50 "--test-reporter-destination=stdout",
51 ],
52 )