11import { outdent } from 'outdent' ;
2- import { addFileScope } from './addFileScope' ;
2+ import { sep , posix , win32 } from 'path' ;
3+
4+ import { addFileScope , normalizePath } from './addFileScope' ;
5+
6+ const raw = String . raw ;
7+
8+ // remove quotes around the snapshot
9+ expect . addSnapshotSerializer ( {
10+ test : ( val ) => typeof val === 'string' ,
11+ print : ( val ) => ( val as string ) . trim ( ) ,
12+ } ) ;
313
414describe ( 'ESM' , ( ) => {
515 test ( 'should add missing fileScope' , ( ) => {
@@ -17,16 +27,12 @@ describe('ESM', () => {
1727 packageName : 'my-package' ,
1828 } ) ,
1929 ) . toMatchInlineSnapshot ( `
20- "
21-
22- import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
23- setFileScope("app/app.css.ts", "my-package");
24- import {style} from '@vanilla-extract/css';
30+ import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
31+ setFileScope("app/app.css.ts", "my-package");
32+ import {style} from '@vanilla-extract/css';
2533
2634 export const myStyle = style({});
27- endFileScope();
28-
29- "
35+ endFileScope();
3036 ` ) ;
3137 } ) ;
3238
@@ -46,19 +52,15 @@ describe('ESM', () => {
4652 globalAdapterIdentifier : 'MY_GLOBAL_ADAPTER' ,
4753 } ) ,
4854 ) . toMatchInlineSnapshot ( `
49- "
50-
51- import * as __vanilla_css_adapter__ from "@vanilla-extract/css/adapter";
52- __vanilla_css_adapter__.setAdapter(MY_GLOBAL_ADAPTER);
53-
54- import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
55- setFileScope("app/app.css.ts", "my-package");
56- import {style} from '@vanilla-extract/css';
55+ import * as __vanilla_css_adapter__ from "@vanilla-extract/css/adapter";
56+ __vanilla_css_adapter__.setAdapter(MY_GLOBAL_ADAPTER);
57+ import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
58+ setFileScope("app/app.css.ts", "my-package");
59+ import {style} from '@vanilla-extract/css';
5760
5861 export const myStyle = style({});
59- endFileScope();
60- __vanilla_css_adapter__.removeAdapter();
61- "
62+ endFileScope();
63+ __vanilla_css_adapter__.removeAdapter();
6264 ` ) ;
6365 } ) ;
6466
@@ -80,12 +82,12 @@ describe('ESM', () => {
8082 packageName : 'my-package' ,
8183 } ) ,
8284 ) . toMatchInlineSnapshot ( `
83- " import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
85+ import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
8486 setFileScope("app/app.css.ts", "my-package");
8587 import {style} from '@vanilla-extract/css';
8688
8789 export const myStyle = style({});
88- endFileScope();"
90+ endFileScope();
8991 ` ) ;
9092 } ) ;
9193
@@ -110,12 +112,12 @@ describe('ESM', () => {
110112 packageName : 'my-package' ,
111113 } ) ,
112114 ) . toMatchInlineSnapshot ( `
113- " import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
115+ import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
114116 setFileScope("app/app.css.ts", "my-package");
115117 import {style} from '@vanilla-extract/css';
116118
117119 export const myStyle = style({});
118- endFileScope();"
120+ endFileScope();
119121 ` ) ;
120122 } ) ;
121123
@@ -137,13 +139,13 @@ describe('ESM', () => {
137139 packageName : 'my-package' ,
138140 } ) ,
139141 ) . toMatchInlineSnapshot ( `
140- " import * as vanillaFileScope from "@vanilla-extract/css/fileScope";
141- vanillaFileScope.setFileScope("app/app.css.ts", "my-package");
142- import {style} from '@vanilla-extract/css';
142+ import * as vanillaFileScope from "@vanilla-extract/css/fileScope";
143+ vanillaFileScope.setFileScope("app/app.css.ts", "my-package");
144+ import {style} from '@vanilla-extract/css';
143145
144- export const myStyle = style({});
145- vanillaFileScope.endFileScope();"
146- ` ) ;
146+ export const myStyle = style({});
147+ vanillaFileScope.endFileScope();
148+ ` ) ;
147149 } ) ;
148150} ) ;
149151
@@ -164,17 +166,13 @@ describe('CJS', () => {
164166 packageName : 'my-package' ,
165167 } ) ,
166168 ) . toMatchInlineSnapshot ( `
167- "
168-
169- const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
170- __vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
171- const _css = require('@vanilla-extract/css');
169+ const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
170+ __vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
171+ const _css = require('@vanilla-extract/css');
172172
173173 var myStyle = _css.style({});
174174 exports.myStyle = myStyle;
175- __vanilla_filescope__.endFileScope();
176- ;
177- "
175+ __vanilla_filescope__.endFileScope();
178176 ` ) ;
179177 } ) ;
180178
@@ -195,20 +193,16 @@ describe('CJS', () => {
195193 globalAdapterIdentifier : 'MY_GLOBAL_ADAPTER' ,
196194 } ) ,
197195 ) . toMatchInlineSnapshot ( `
198- "
199-
200- const __vanilla_css_adapter__ = require("@vanilla-extract/css/adapter");
201- __vanilla_css_adapter__.setAdapter(MY_GLOBAL_ADAPTER);
202-
203- const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
204- __vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
205- const _css = require('@vanilla-extract/css');
196+ const __vanilla_css_adapter__ = require("@vanilla-extract/css/adapter");
197+ __vanilla_css_adapter__.setAdapter(MY_GLOBAL_ADAPTER);
198+ const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
199+ __vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
200+ const _css = require('@vanilla-extract/css');
206201
207202 var myStyle = _css.style({});
208203 exports.myStyle = myStyle;
209- __vanilla_filescope__.endFileScope();
210- __vanilla_css_adapter__.removeAdapter();;
211- "
204+ __vanilla_filescope__.endFileScope();
205+ __vanilla_css_adapter__.removeAdapter();
212206 ` ) ;
213207 } ) ;
214208
@@ -231,13 +225,13 @@ describe('CJS', () => {
231225 packageName : 'my-package' ,
232226 } ) ,
233227 ) . toMatchInlineSnapshot ( `
234- " const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
228+ const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
235229 __vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
236230 const _css = require('@vanilla-extract/css');
237231
238232 var myStyle = _css.style({});
239233 exports.myStyle = myStyle;
240- __vanilla_filescope__.endFileScope();"
234+ __vanilla_filescope__.endFileScope();
241235 ` ) ;
242236 } ) ;
243237
@@ -263,13 +257,54 @@ describe('CJS', () => {
263257 packageName : 'my-package' ,
264258 } ) ,
265259 ) . toMatchInlineSnapshot ( `
266- " const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
260+ const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
267261 __vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
268262 const _css = require('@vanilla-extract/css');
269263
270264 const myStyle = _css.style({});
271265 exports.myStyle = myStyle;
272- __vanilla_filescope__.endFileScope();"
266+ __vanilla_filescope__.endFileScope();
273267 ` ) ;
274268 } ) ;
275269} ) ;
270+
271+ test ( 'platform-specific relative path' , ( ) => {
272+ const { rootPath, filePath } = {
273+ [ posix . sep ] : {
274+ rootPath : '/the-root' ,
275+ filePath : '/the-root/app/app.css.ts' ,
276+ } ,
277+ [ win32 . sep ] : {
278+ rootPath : raw `D:\the-root` ,
279+ filePath : raw `D:\the-root\app\app.css.ts` ,
280+ } ,
281+ } [ sep ] ;
282+
283+ const source = outdent `
284+ import { style } from '@vanilla-extract/css';
285+
286+ export const myStyle = style({});
287+ ` ;
288+
289+ // The snapshot should be the same for either platform
290+ expect (
291+ addFileScope ( {
292+ source,
293+ rootPath,
294+ filePath,
295+ packageName : 'my-package' ,
296+ } ) ,
297+ ) . toMatchInlineSnapshot ( `
298+ import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
299+ setFileScope("app/app.css.ts", "my-package");
300+ import { style } from '@vanilla-extract/css';
301+
302+ export const myStyle = style({});
303+ endFileScope();
304+ ` ) ;
305+ } ) ;
306+
307+ test ( 'normalizePath()' , ( ) => {
308+ expect ( normalizePath ( raw `foo\bar` ) ) . toMatchInlineSnapshot ( `foo/bar` ) ;
309+ expect ( normalizePath ( raw `foo/bar` ) ) . toMatchInlineSnapshot ( `foo/bar` ) ;
310+ } ) ;
0 commit comments