Skip to content

Commit 0933eb7

Browse files
authored
Merge pull request #276 from kwonoj/test-e2e-path
2 parents 2917ee0 + 66b1a22 commit 0933eb7

File tree

15 files changed

+3385
-22
lines changed

15 files changed

+3385
-22
lines changed

.github/workflows/ci_main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ on:
99

1010
jobs:
1111
build:
12-
runs-on: ubuntu-latest
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest, windows-latest]
1316
name: Run test
1417

1518
steps:
@@ -44,6 +47,7 @@ jobs:
4447
run: |
4548
cargo check
4649
- name: Generate code coverage
50+
if: matrix.os == 'ubuntu-latest'
4751
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
4852
- uses: codecov/codecov-action@v2
4953
with:

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/target
2-
Cargo.lock
32
node_modules/
43
.swc/
54
*.log
@@ -10,4 +9,4 @@ spec/swc-coverage-custom-transform/target/
109
a.js
1110
swc-plugin-coverage-*.tgz
1211
/tmp
13-
trace-*.json
12+
trace-*.json

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ resolver = "2"
1212
#lto = true
1313

1414
[workspace.dependencies]
15-
istanbul-oxide = { path = "./packages/istanbul-oxide", version = "0.0.29" }
15+
istanbul-oxide = { path = "./packages/istanbul-oxide", version = "0.0.30" }
1616
swc-coverage-instrument = { path = "./packages/swc-coverage-instrument" }
1717

1818
getrandom = { version = "0.2.15" }

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swc-plugin-coverage-instrument",
3-
"version": "0.0.29",
3+
"version": "0.0.30",
44
"description": "SWC coverage instrumentation plugin",
55
"main": "./target/wasm32-wasip1/release/swc_plugin_coverage.wasm",
66
"napi": {

packages/istanbul-oxide/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license = "MIT"
66
name = "istanbul-oxide"
77
repository = "https://github.com/kwonoj/swc-coverage-instrument"
8-
version = "0.0.29"
8+
version = "0.0.30"
99

1010
[dependencies]
1111
indexmap = { workspace = true, features = ["serde"] }

packages/swc-coverage-instrument/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license = "MIT"
66
name = "swc-coverage-instrument"
77
repository = "https://github.com/kwonoj/swc-coverage-instrument"
8-
version = "0.0.29"
8+
version = "0.0.30"
99

1010
[dependencies]
1111
istanbul-oxide = { workspace = true }

packages/swc-plugin-coverage/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license = "MIT"
66
name = "swc-plugin-coverage"
77
repository = "https://github.com/kwonoj/swc-coverage-instrument"
8-
version = "0.0.29"
8+
version = "0.0.30"
99

1010
[lib]
1111
crate-type = ["cdylib"]

packages/swc-plugin-coverage/src/lib.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use typed_path::Utf8TypedPath;
1414
use wax::Pattern;
1515

1616
/// Normalize a file path to use forward slashes for consistent glob matching
17-
fn normalize_path_for_glob_matching(path: &str) -> String {
17+
fn normalize_path(path: &str) -> String {
1818
let typed_path = Utf8TypedPath::derive(path);
1919
if typed_path.is_windows() {
2020
typed_path.with_unix_encoding().to_string()
@@ -77,9 +77,14 @@ pub fn process(program: Program, metadata: TransformPluginProgramMetadata) -> Pr
7777
// compatible glob and the filename matches the pattern, the file will not be instrumented.
7878
// Note that the filename is provided by swc's core, may not be the full absolute path to the file name.
7979
if let Some(exclude) = &instrument_options.unstable_exclude {
80-
match wax::any(exclude.iter().map(|s| s.as_ref()).collect::<Vec<&str>>()) {
80+
let normalized_patterns = exclude
81+
.iter()
82+
.map(|s| normalize_path(s))
83+
.collect::<Vec<_>>();
84+
85+
match wax::any(normalized_patterns.iter().map(|s| s.as_str())) {
8186
Ok(p) => {
82-
let normalized_filename = normalize_path_for_glob_matching(filename);
87+
let normalized_filename = normalize_path(filename);
8388
if p.is_match(normalized_filename.as_str()) {
8489
return program;
8590
}
@@ -110,32 +115,32 @@ mod tests {
110115
#[test]
111116
fn test_normalize_path_for_glob_matching() {
112117
// Test Windows paths are normalized to Unix-style
113-
let result = normalize_path_for_glob_matching(r"C:\Users\project\test\index.test.ts");
118+
let result = normalize_path(r"C:\Users\project\test\index.test.ts");
114119
println!("Windows path result: {}", result);
115120
// The typed-path crate converts Windows paths to Unix format, but may strip the drive letter
116121
// The important thing is that backslashes are converted to forward slashes
117122
assert!(result.contains("/Users/project/test/index.test.ts"));
118123

119124
// Test mixed separators are normalized
120-
let result = normalize_path_for_glob_matching(r"C:\Users/project\test/file.js");
125+
let result = normalize_path(r"C:\Users/project\test/file.js");
121126
println!("Mixed separators result: {}", result);
122127
assert!(result.contains("/Users/project/test/file.js"));
123128

124129
// Test Unix paths remain unchanged
125130
assert_eq!(
126-
normalize_path_for_glob_matching("/home/user/project/src/utils/helper.js"),
131+
normalize_path("/home/user/project/src/utils/helper.js"),
127132
"/home/user/project/src/utils/helper.js"
128133
);
129134

130135
// Test relative Unix paths remain unchanged
131136
assert_eq!(
132-
normalize_path_for_glob_matching("src/components/Button.tsx"),
137+
normalize_path("src/components/Button.tsx"),
133138
"src/components/Button.tsx"
134139
);
135140

136141
// Test that backslashes are converted to forward slashes
137142
let windows_path = r"project\src\test\file.ts";
138-
let result = normalize_path_for_glob_matching(windows_path);
143+
let result = normalize_path(windows_path);
139144
println!("Relative Windows path result: {}", result);
140145
assert!(result.contains("project/src/test/file.ts"));
141146
}

0 commit comments

Comments
 (0)