Skip to content

Commit 3f1eba9

Browse files
committed
Simplify test module matching
1 parent edfb9e4 commit 3f1eba9

14 files changed

Lines changed: 23 additions & 26 deletions

File tree

tests/class_method_cjs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn class_method_cjs() {
77
file!(),
88
false,
99
Config::new_single(InstrumentationConfig::new(
10-
ModuleMatcher::new("undici", ">=0.0.1", "tests/class_method_cjs/index.mjs").unwrap(),
10+
test_module_matcher(),
1111
FunctionQuery::class_method("Undici", "fetch", FunctionKind::Async),
1212
"Undici_fetch",
1313
)),

tests/common/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ fn transpile(
8383
.unwrap()
8484
}
8585

86+
static TEST_MODULE_NAME: &'static str = "undici";
87+
static TEST_MODULE_PATH: &'static str = "index.mjs";
88+
8689
pub fn transpile_and_test(test_file: &str, mjs: bool, config: Config) {
8790
let test_file = PathBuf::from(test_file);
8891
let test_dir = test_file.parent().expect("Couldn't find test directory");
8992

90-
let file_path = test_dir.join("index.mjs");
93+
let file_path = PathBuf::from("index.mjs");
9194
let mut instrumentor = Instrumentor::new(config);
9295
let mut instrumentations =
93-
instrumentor.get_matching_instrumentations("undici", "0.0.1", &file_path);
96+
instrumentor.get_matching_instrumentations(TEST_MODULE_NAME, "0.0.1", &file_path);
9497

9598
let extension = if mjs { "mjs" } else { "js" };
9699
let instrumentable = test_dir.join(format!("mod.{}", extension));
@@ -113,3 +116,7 @@ pub fn transpile_and_test(test_file: &str, mjs: bool, config: Config) {
113116
.assert()
114117
.success();
115118
}
119+
120+
pub fn test_module_matcher() -> ModuleMatcher {
121+
ModuleMatcher::new(TEST_MODULE_NAME, ">=0.0.1", TEST_MODULE_PATH).unwrap()
122+
}

tests/constructor_cjs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn constructor_cjs() {
77
file!(),
88
false,
99
Config::new_single(InstrumentationConfig::new(
10-
ModuleMatcher::new("undici", ">=0.0.1", "tests/constructor_cjs/index.mjs").unwrap(),
10+
test_module_matcher(),
1111
FunctionQuery::class_constructor("Undici"),
1212
"Undici_constructor",
1313
)),

tests/constructor_mjs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn constructor_mjs() {
77
file!(),
88
true,
99
Config::new_single(InstrumentationConfig::new(
10-
ModuleMatcher::new("undici", ">=0.0.1", "tests/constructor_mjs/index.mjs").unwrap(),
10+
test_module_matcher(),
1111
FunctionQuery::class_constructor("Undici"),
1212
"Undici_constructor",
1313
)),

tests/decl_cjs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn decl_cjs() {
77
file!(),
88
false,
99
Config::new_single(InstrumentationConfig::new(
10-
ModuleMatcher::new("undici", ">=0.0.1", "tests/decl_cjs/index.mjs").unwrap(),
10+
test_module_matcher(),
1111
FunctionQuery::function_declaration("fetch", FunctionKind::Async),
1212
"fetch_decl",
1313
)),

tests/decl_mjs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn decl_mjs() {
77
file!(),
88
true,
99
Config::new_single(InstrumentationConfig::new(
10-
ModuleMatcher::new("undici", ">=0.0.1", "tests/decl_mjs/index.mjs").unwrap(),
10+
test_module_matcher(),
1111
FunctionQuery::function_declaration("fetch", FunctionKind::Async),
1212
"fetch_decl",
1313
)),

tests/expr_cjs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn expr_cjs() {
77
file!(),
88
false,
99
Config::new_single(InstrumentationConfig::new(
10-
ModuleMatcher::new("undici", ">=0.0.1", "tests/expr_cjs/index.mjs").unwrap(),
10+
test_module_matcher(),
1111
FunctionQuery::function_expression("fetch", FunctionKind::Async),
1212
"fetch_expr",
1313
)),

tests/expr_mjs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn expr_mjs() {
77
file!(),
88
true,
99
Config::new_single(InstrumentationConfig::new(
10-
ModuleMatcher::new("undici", ">=0.0.1", "tests/expr_mjs/index.mjs").unwrap(),
10+
test_module_matcher(),
1111
FunctionQuery::function_expression("fetch", FunctionKind::Async),
1212
"fetch_expr",
1313
)),

tests/index_cjs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn index_cjs() {
77
file!(),
88
false,
99
Config::new_single(InstrumentationConfig::new(
10-
ModuleMatcher::new("undici", ">=0.0.1", "tests/index_cjs/index.mjs").unwrap(),
10+
test_module_matcher(),
1111
FunctionQuery::ClassMethod {
1212
class_name: "Undici".to_string(),
1313
method_name: "fetch".to_string(),

tests/multiple_class_method_cjs/mod.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,12 @@ fn multiple_class_method_cjs() {
99
Config::new(
1010
vec![
1111
InstrumentationConfig::new(
12-
ModuleMatcher::new(
13-
"undici",
14-
">=0.0.1",
15-
"tests/multiple_class_method_cjs/index.mjs",
16-
)
17-
.unwrap(),
12+
test_module_matcher(),
1813
FunctionQuery::class_method("Undici", "fetch1", FunctionKind::Async),
1914
"Undici_fetch1",
2015
),
2116
InstrumentationConfig::new(
22-
ModuleMatcher::new(
23-
"undici",
24-
">=0.0.1",
25-
"tests/multiple_class_method_cjs/index.mjs",
26-
)
27-
.unwrap(),
17+
test_module_matcher(),
2818
FunctionQuery::class_method("Undici", "fetch2", FunctionKind::Async),
2919
"Undici_fetch2",
3020
),

0 commit comments

Comments
 (0)