@vitest/utils 4.1.0-beta.4 → 4.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/diff.js +2 -2
- package/dist/source-map/node.d.ts +6 -0
- package/dist/source-map/node.js +23 -0
- package/package.json +11 -2
package/dist/diff.js
CHANGED
|
@@ -2012,8 +2012,8 @@ function diff(a, b, options) {
|
|
|
2012
2012
|
}
|
|
2013
2013
|
aDisplay = truncate(aDisplay);
|
|
2014
2014
|
bDisplay = truncate(bDisplay);
|
|
2015
|
-
const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)}
|
|
2016
|
-
const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)}
|
|
2015
|
+
const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)}\n${aDisplay}`;
|
|
2016
|
+
const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)}\n${bDisplay}`;
|
|
2017
2017
|
return `${aDiff}\n\n${bDiff}`;
|
|
2018
2018
|
}
|
|
2019
2019
|
if (omitDifference) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import convertSourceMap from 'convert-source-map';
|
|
4
|
+
|
|
5
|
+
// based on vite
|
|
6
|
+
// https://github.com/vitejs/vite/blob/84079a84ad94de4c1ef4f1bdb2ab448ff2c01196/packages/vite/src/node/server/sourcemap.ts#L149
|
|
7
|
+
function extractSourcemapFromFile(code, filePath) {
|
|
8
|
+
const map = (convertSourceMap.fromSource(code) || convertSourceMap.fromMapFileSource(code, createConvertSourceMapReadMap(filePath)))?.toObject();
|
|
9
|
+
return map ? { map } : undefined;
|
|
10
|
+
}
|
|
11
|
+
function createConvertSourceMapReadMap(originalFileName) {
|
|
12
|
+
return (filename) => {
|
|
13
|
+
// convertSourceMap can detect invalid filename from comments.
|
|
14
|
+
// fallback to empty source map to avoid errors.
|
|
15
|
+
const targetPath = path.resolve(path.dirname(originalFileName), filename);
|
|
16
|
+
if (existsSync(targetPath)) {
|
|
17
|
+
return readFileSync(targetPath, "utf-8");
|
|
18
|
+
}
|
|
19
|
+
return "{}";
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { extractSourcemapFromFile };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.0-beta.
|
|
4
|
+
"version": "4.1.0-beta.5",
|
|
5
5
|
"description": "Shared Vitest utility functions",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -56,6 +56,10 @@
|
|
|
56
56
|
"types": "./dist/source-map.d.ts",
|
|
57
57
|
"default": "./dist/source-map.js"
|
|
58
58
|
},
|
|
59
|
+
"./source-map/node": {
|
|
60
|
+
"types": "./dist/source-map/node.d.ts",
|
|
61
|
+
"default": "./dist/source-map/node.js"
|
|
62
|
+
},
|
|
59
63
|
"./serialize": {
|
|
60
64
|
"types": "./dist/serialize.d.ts",
|
|
61
65
|
"default": "./dist/serialize.js"
|
|
@@ -69,6 +73,9 @@
|
|
|
69
73
|
"*": {
|
|
70
74
|
"source-map": [
|
|
71
75
|
"dist/source-map.d.ts"
|
|
76
|
+
],
|
|
77
|
+
"source-map/node": [
|
|
78
|
+
"dist/source-map/node.d.ts"
|
|
72
79
|
]
|
|
73
80
|
}
|
|
74
81
|
},
|
|
@@ -77,11 +84,13 @@
|
|
|
77
84
|
"dist"
|
|
78
85
|
],
|
|
79
86
|
"dependencies": {
|
|
87
|
+
"convert-source-map": "^2.0.0",
|
|
80
88
|
"tinyrainbow": "^3.0.3",
|
|
81
|
-
"@vitest/pretty-format": "4.1.0-beta.
|
|
89
|
+
"@vitest/pretty-format": "4.1.0-beta.5"
|
|
82
90
|
},
|
|
83
91
|
"devDependencies": {
|
|
84
92
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
93
|
+
"@types/convert-source-map": "^2.0.3",
|
|
85
94
|
"@types/estree": "^1.0.8",
|
|
86
95
|
"diff-sequences": "^29.6.3",
|
|
87
96
|
"loupe": "^3.2.1"
|