11import assert from 'assert' ;
22import fs from 'node:fs/promises' ;
33import http from 'http' ;
4+ import path from 'path' ;
5+ import { fileURLToPath } from 'url' ;
46import { chromium } from 'playwright' ;
57
8+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
9+ const pkgPath = path . join ( __dirname , '../package.json' ) ;
10+ const { version } = JSON . parse ( await fs . readFile ( pkgPath , 'utf-8' ) ) ;
11+
612const fixture = `<svg xmlns="http://www.w3.org/2000/svg">
713 <g attr1="val1">
814 <g attr2="val2">
@@ -24,11 +30,12 @@ const expected = `<svg xmlns="http://www.w3.org/2000/svg">
2430
2531const content = `
2632<script type="module">
27- import { optimize } from '/svgo.browser.js';
33+ import { VERSION, optimize } from '/svgo.browser.js';
2834const result = optimize(${ JSON . stringify ( fixture ) } , {
2935 plugins : [],
3036 js2svg : { pretty: true, indent: 2 }
3137});
38+ globalThis.version = VERSION;
3239globalThis.result = result.data;
3340</script>
3441` ;
@@ -50,8 +57,15 @@ const runTest = async () => {
5057 const context = await browser . newContext ( ) ;
5158 const page = await context . newPage ( ) ;
5259 await page . goto ( 'http://localhost:5000' ) ;
53- const actual = await page . evaluate ( ( ) => globalThis . result ) ;
54- assert . equal ( actual , expected ) ;
60+
61+ const actual = await page . evaluate ( ( ) => ( {
62+ version : globalThis . version ,
63+ result : globalThis . result ,
64+ } ) ) ;
65+
66+ assert . strictEqual ( actual . version , version ) ;
67+ assert . equal ( actual . result , expected ) ;
68+
5569 await browser . close ( ) ;
5670} ;
5771
0 commit comments