11import path from 'node:path' ;
2- import { expect } from 'vitest' ;
3- import { test } from 'vitest' ;
42import { createSnapshotSerializer } from 'path-serializer' ;
3+ import { describe , expect } from 'vitest' ;
4+ import { test } from 'vitest' ;
55
66expect . addSnapshotSerializer (
77 createSnapshotSerializer ( {
@@ -13,44 +13,39 @@ expect.addSnapshotSerializer(
1313 } ) ,
1414) ;
1515
16- test ( 'should serialize file content without escaping \\" ' , ( ) => {
17- const fileContent = `"use strict";
18- const a = " ${ require . resolve ( '@rslib/core' ) } ";
19- ` ;
16+ test ( 'transformWin32Path ' , ( ) => {
17+ const fileContent = `{
18+ loader: 'D:\\Users\\user\\Documents\\code\\user\\fe-dev-scripts\\src\\utils.ts',
19+ } `;
2020
2121 expect ( fileContent ) . toMatchInlineSnapshot ( `
22- "use strict";
23- const a = "<ROOT>/node_modules/<PNPM_INNER>/@rslib/core/dist/index.js";
22+ {
23+ loader: '/d/Users/user/Documents/code/user/fe-dev-scripts/src/utils.ts',
24+ }
2425 ` ) ;
2526} ) ;
2627
27- test ( 'should serialize webpack output content' , ( ) => {
28- const fileContent = `;// CONCATENATED MODULE: ../../../../node_modules/.pnpm/@[email protected] /node_modules/@swc/helpers/esm/_class_private_method_get.js 29- function _class_private_method_get(receiver, privateSet, fn) {
30- if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
28+ test ( 'transformWin32RelativePath' , ( ) => {
29+ const case1 = `Cannot find file "..\\..\\getting-started\\next"` ;
3130
32- return fn;
33- }
34- ` ;
35-
36- expect ( fileContent ) . toMatchInlineSnapshot ( `
37- ;// CONCATENATED MODULE: ../../../../node_modules/<PNPM_INNER>/@swc/helpers/esm/_class_private_method_get.js
38- function _class_private_method_get(receiver, privateSet, fn) {
39- if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
31+ expect ( case1 ) . toMatchInlineSnapshot (
32+ `Cannot find file "../../getting-started/next"` ,
33+ ) ;
4034
41- return fn;
42- }
43- ` ) ;
35+ const case2 = `Cannot find file "..\\getting-started\\next"` ;
36+ expect ( case2 ) . toMatchInlineSnapshot (
37+ `Cannot find file "../getting-started/next"` ,
38+ ) ;
4439} ) ;
4540
46- test ( 'should serialize the Win32 path' , ( ) => {
47- const fileContent = `{
48- loader: 'D:\\Users\\user\\Documents\\code\\user\\fe-dev-scripts\\src\\utils.ts',
49- }` ;
41+ describe ( 'transformCLR' , ( ) => {
42+ test ( 'should transform the color' , ( ) => {
43+ const input = '\u001b[1mBold Text\u001b[0m' ;
44+ expect ( input ) . toMatchInlineSnapshot ( '<CLR=BOLD>Bold Text<CLR=0>' ) ;
45+ } ) ;
5046
51- expect ( fileContent ) . toMatchInlineSnapshot ( `
52- {
53- loader: '/d/Users/user/Documents/code/user/fe-dev-scripts/src/utils.ts',
54- }
55- ` ) ;
47+ test ( 'bad case 1' , ( ) => {
48+ const input = 'static/react.svg' ; // bad case: 'static/reactXsvg'
49+ expect ( input ) . toMatchInlineSnapshot ( 'static/react.svg' ) ;
50+ } ) ;
5651} ) ;
0 commit comments