Skip to content

Commit 20f9d69

Browse files
authored
fix(react/testing-library): generate same snapshot for Windows (#1011)
## Summary <!-- Can you explain the reasoning behind implementing this change? What problem or issue does this pull request resolve? --> Similar to #1007, we normalize the relative path to ensure consistent snapshot generation across Windows, Linux, and macOS. > [!NOTE] > The testing library does not work on Windows now since we are using `environment` with a absolute path. > An error "Cannot find dependency 'vitest-environment-C:\Users\Admin\colin\lynx-stack\packages\react\testing-library\dist\env\vitest.js'" would occur. > > I've submitted a fix at vitest-dev/vitest#8105 <!-- It would be helpful if you could provide any relevant context, such as GitHub issues or related discussions. --> issue: #81 ## Checklist <!--- Check and mark with an "x" --> - [ ] Tests updated (or not required). - [ ] Documentation updated (or not required).
1 parent 97e45e3 commit 20f9d69

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.changeset/shaggy-regions-sit.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
3+
---

packages/react/testing-library/src/vitest.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ export const createVitestConfig = async (options) => {
4747
'@lynx-js/react/transform',
4848
);
4949
// relativePath should be stable between different runs with different cwd
50-
const relativePath = path.relative(
50+
const relativePath = normalizeSlashes(path.relative(
5151
__dirname,
5252
sourcePath,
53-
);
53+
));
5454
const basename = path.basename(sourcePath);
5555
const result = transformReactLynxSync(sourceText, {
5656
mode: 'test',
@@ -123,3 +123,7 @@ export const createVitestConfig = async (options) => {
123123
},
124124
});
125125
};
126+
127+
function normalizeSlashes(file) {
128+
return file.replaceAll(path.win32.sep, '/');
129+
}

0 commit comments

Comments
 (0)