|  | 
| 1 |  | -import { URL } from 'node:url' | 
|  | 1 | +import { URL, fileURLToPath } from 'node:url' | 
|  | 2 | +import { promisify } from 'node:util' | 
|  | 3 | +import { execFile } from 'node:child_process' | 
| 2 | 4 | import { describe, expect, test } from 'vitest' | 
| 3 | 5 | import { mapFileCommentRegex } from 'convert-source-map' | 
| 4 | 6 | import { commentSourceMap } from '../foo-with-sourcemap-plugin' | 
| @@ -170,4 +172,39 @@ describe.runIf(isBuild)('build tests', () => { | 
| 170 | 172 |     const js = findAssetFile(/after-preload-dynamic-no-dep-[-\w]{8}\.js$/) | 
| 171 | 173 |     expect(js).not.toMatch(/__vite__mapDeps/) | 
| 172 | 174 |   }) | 
|  | 175 | + | 
|  | 176 | +  test('sourcemap is correct when using object as "define" value', async () => { | 
|  | 177 | +    const map = findAssetFile(/with-define-object.*\.js\.map/) | 
|  | 178 | +    expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(` | 
|  | 179 | +      { | 
|  | 180 | +        "mappings": "qBAEA,SAASA,GAAO,CACJC,GACZ,CAEA,SAASA,GAAY,CAEX,QAAA,MAAM,qBAAsBC,CAAkB,CACxD,CAEAF,EAAK", | 
|  | 181 | +        "sources": [ | 
|  | 182 | +          "../../with-define-object.ts", | 
|  | 183 | +        ], | 
|  | 184 | +        "sourcesContent": [ | 
|  | 185 | +          "// test complicated stack since broken sourcemap | 
|  | 186 | +      // might still look correct with a simple case | 
|  | 187 | +      function main() { | 
|  | 188 | +        mainInner() | 
|  | 189 | +      } | 
|  | 190 | +
 | 
|  | 191 | +      function mainInner() { | 
|  | 192 | +        // @ts-expect-error "define" | 
|  | 193 | +        console.trace('with-define-object', __testDefineObject) | 
|  | 194 | +      } | 
|  | 195 | +
 | 
|  | 196 | +      main() | 
|  | 197 | +      ", | 
|  | 198 | +        ], | 
|  | 199 | +        "version": 3, | 
|  | 200 | +      } | 
|  | 201 | +    `) | 
|  | 202 | +  }) | 
|  | 203 | + | 
|  | 204 | +  test('correct sourcemap during ssr dev when using object as "define" value', async () => { | 
|  | 205 | +    const execFileAsync = promisify(execFile) | 
|  | 206 | +    await execFileAsync('node', ['test-ssr-dev.js'], { | 
|  | 207 | +      cwd: fileURLToPath(new URL('..', import.meta.url)), | 
|  | 208 | +    }) | 
|  | 209 | +  }) | 
| 173 | 210 | }) | 
0 commit comments