Skip to content

Commit 6a261eb

Browse files
committed
test: configure stylex with test mode and remove custom snapshot serializer
1 parent 93d5187 commit 6a261eb

3 files changed

Lines changed: 11 additions & 60 deletions

File tree

internal/test-utils/src/setup.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,55 +56,3 @@ if (typeof window.matchMedia === 'undefined') {
5656
}),
5757
});
5858
}
59-
60-
import {expect} from 'vitest';
61-
62-
let isNormalizing = false;
63-
64-
if (typeof expect !== 'undefined' && expect.addSnapshotSerializer) {
65-
expect.addSnapshotSerializer({
66-
serialize(
67-
val: Element,
68-
config: object,
69-
indentation: string,
70-
depth: number,
71-
refs: unknown[],
72-
printer: (
73-
val: Element,
74-
config: object,
75-
indentation: string,
76-
depth: number,
77-
refs: unknown[],
78-
) => string,
79-
) {
80-
isNormalizing = true;
81-
try {
82-
const clone = val.cloneNode(true) as Element;
83-
if (clone.setAttribute && clone.getAttribute) {
84-
const styleSrc = clone.getAttribute('data-style-src');
85-
if (styleSrc) {
86-
clone.setAttribute('data-style-src', styleSrc.replace(/\\/g, '/'));
87-
}
88-
const elements = clone.querySelectorAll('[data-style-src]');
89-
for (const el of elements) {
90-
const src = el.getAttribute('data-style-src');
91-
if (src) {
92-
el.setAttribute('data-style-src', src.replace(/\\/g, '/'));
93-
}
94-
}
95-
}
96-
return printer(clone, config, indentation, depth, refs);
97-
} finally {
98-
isNormalizing = false;
99-
}
100-
},
101-
test(val: unknown) {
102-
return (
103-
!isNormalizing &&
104-
val != null &&
105-
typeof val === 'object' &&
106-
(val as Element).nodeType === 1
107-
);
108-
},
109-
});
110-
}

packages/core/src/FormLayout/__snapshots__/FormLayout.test.tsx.snap

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
exports[`FormLayout > matches snapshot for horizontal direction 1`] = `
44
<div
5-
class="astryx-form-layout horizontal FormLayout__styles.base xdt5ytf x18g69wz FormLayout__styles.horizontal xrvj5dj x1mt1orb xu6a5m6"
5+
class="astryx-form-layout horizontal FormLayout__styles.base FormLayout__styles.horizontal"
66
data-direction="horizontal"
7-
data-style-src="@astryxdesign/core:src/FormLayout/FormLayout.tsx:40; @astryxdesign/core:src/FormLayout/FormLayout.tsx:45"
87
data-testid="layout"
98
>
109
<input
@@ -18,9 +17,8 @@ exports[`FormLayout > matches snapshot for horizontal direction 1`] = `
1817

1918
exports[`FormLayout > matches snapshot for horizontal-labels direction 1`] = `
2019
<div
21-
class="astryx-form-layout horizontal-labels FormLayout__styles.base xdt5ytf FormLayout__styles.horizontalLabels xrvj5dj x1pmbctz xlaq8a2 x7a106z xedohl4 x1rpgqan x1a1jff"
20+
class="astryx-form-layout horizontal-labels FormLayout__styles.base FormLayout__styles.horizontalLabels"
2221
data-direction="horizontal-labels"
23-
data-style-src="@astryxdesign/core:src/FormLayout/FormLayout.tsx:40; @astryxdesign/core:src/FormLayout/FormLayout.tsx:50"
2422
data-testid="layout"
2523
>
2624
<label>
@@ -34,9 +32,8 @@ exports[`FormLayout > matches snapshot for horizontal-labels direction 1`] = `
3432

3533
exports[`FormLayout > matches snapshot for vertical direction 1`] = `
3634
<div
37-
class="astryx-form-layout vertical FormLayout__styles.base x78zum5 xdt5ytf x18g69wz"
35+
class="astryx-form-layout vertical FormLayout__styles.base"
3836
data-direction="vertical"
39-
data-style-src="@astryxdesign/core:src/FormLayout/FormLayout.tsx:40"
4037
data-testid="layout"
4138
>
4239
<input

vitest.config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ export default defineConfig({
2525
'@stylexjs/babel-plugin',
2626
{
2727
dev: true,
28+
test: true,
2829
runtimeInjection: true,
2930
genConditionalClasses: true,
3031
treeshakeCompensation: true,
3132
aliases: {
32-
'@astryxdesign/core/*': [path.join(rootDir, 'packages/core/src/*')],
33+
'@astryxdesign/core/*': [
34+
path.join(rootDir, 'packages/core/src/*'),
35+
],
3336
'@astryxdesign/core': [path.join(rootDir, 'packages/core/src')],
3437
},
3538
unstable_moduleResolution: {
@@ -47,7 +50,10 @@ export default defineConfig({
4750
// Map @astryxdesign/core subpath imports to source for lab package tests.
4851
// Must use regex to match subpaths like @astryxdesign/core/Dialog, @astryxdesign/core/theme/tokens.stylex
4952
// while not breaking core's own relative imports.
50-
{find: /^@astryxdesign\/core\/(.*)$/, replacement: path.join(coreSrc, '$1')},
53+
{
54+
find: /^@astryxdesign\/core\/(.*)$/,
55+
replacement: path.join(coreSrc, '$1'),
56+
},
5157
],
5258
},
5359
test: {

0 commit comments

Comments
 (0)