Skip to content

Commit

Permalink
fix test and ensure test outputs are cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
leowrites committed Sep 10, 2024
1 parent 22cc090 commit 503d5ae
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
36 changes: 35 additions & 1 deletion memory-viz/src/tests/__snapshots__/cli.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`memory-viz CLI output path should overwrite existing svg when the output path is a file that exists 1`] = `""`;
exports[`memory-viz CLI output path should overwrite existing svg when the output path is a file that exists 1`] = `
"<svg width="1300" height="292" xmlns="http://www.w3.org/2000/svg"><style>
text {
font-family: Consolas, Courier;
font-size: 20px;
}
text.default {
fill: rgb(0, 0, 0);
text-anchor: middle;
}
text.attribute {
fill: rgb(27, 14, 139);
text-anchor: start;
}
text.variable {
fill: rgb(0, 0, 0);
text-anchor: start;
}
text.id {
fill: rgb(150, 100, 28);
text-anchor: middle;
}
text.type {
fill: rgb(27, 14, 139);
text-anchor: middle;
}
text.value {
fill: rgb(27, 14, 139);
text-anchor: middle;
}
path {
stroke: rgb(0, 0, 0);
}
</style><g><path d="M49.843418531864884 25.055951649695636 L250.04208245798947 25.16232960894704 L249.8125534825027 154.76915388777851 L50.02731695696711 155.2168297596276" stroke="none" stroke-width="0" fill="yellow"/><path d="M49.97535771877145 24.898081216673646 C91.0057945744059 25.575490199694347, 132.00435620649756 25.147657713407945, 249.7667616337151 24.66557146147655 M50.098402258448 24.91264554324035 C119.51811093515735 24.933516715353758, 189.22328251818155 25.117830294270043, 250.1472592261093 24.995461922298784 M249.65860744193196 24.839829497784375 C249.41087262187153 76.7476857740432, 249.6819302991405 128.6928032502532, 250.3871857471764 155.24320195242763 M250.0668587591499 25.13916292525828 C249.79199180010704 50.96997084096074, 249.99955778721719 77.23471773676575, 249.81720564626158 154.93375069238246 M250.20828779616468 154.7506806660367 C182.31153810889924 154.87295696579682, 114.14583508627462 155.10524777323295, 50.03373873164973 155.0093650638822 M250.14608710244562 154.93424775242954 C194.87608436399668 155.1867432236352, 139.39943716667707 155.00908079448416, 49.939513140720024 155.1144612963485 M50.154903227835895 154.73371086642146 C50.21252727624029 113.04486663602293, 49.84796941395849 71.12155508995055, 50.056322414427996 25.339266853779556 M49.99176651500166 155.1614456448704 C49.89525366704911 117.62324508428574, 49.98948728721589 80.18961338661612, 50.17477255128324 25.045822993293406" stroke="#000" stroke-width="4" fill="none"/></g><g><path d="M43.87952692325466 18.50173162575378 C87.06902513689869 21.91085690283547, 130.10268930999553 19.819236590718607, 254.85972636458496 17.36502008017468 M44.48107651738775 18.57293482386445 C117.19604804377738 18.70271748519725, 191.3066125471911 19.603803863201254, 256.71993221260584 18.97781389725634 M254.29303720965981 18.19914748892188 C252.96260237347335 75.6326685871929, 254.31789075981825 133.25249568521977, 257.93592873588204 162.21600976213813 M256.33429379574955 19.695814626291394 C254.8946174579486 47.066258697211744, 255.9324473934993 76.60639766864479, 255.08602823130786 160.66875346191227 M257.01829337226275 159.78110849494485 C185.31748177426326 160.35205316406825, 112.30179045749395 161.48769430102058, 44.164944502078754 161.0457846434484 M256.7142018444317 160.67854536297725 C197.95751293163474 161.93857857715028, 138.19056472012943 161.07000885085895, 43.70428719757981 161.5595871750456 M44.77451613917947 159.6685543321073 C44.99584911007434 115.15492242164909, 43.17305979866534 69.46895393282173, 44.28161207213998 20.696334268897772 M43.95883257500827 161.807228224352 C43.45435916353017 120.20417211577296, 43.925527264364064 79.12396032176912, 44.8738627564162 19.229114966467023" stroke="rgb(0, 0, 0)" stroke-width="1" fill="none"/></g><text x="150" y="115" style="font-weight:bolder; font-size:22px; " class="value">"David is cool!"</text><g><path d="M49.97261889651418 24.88675363585353 C62.21760956197977 25.381302431896327, 74.42718228921294 24.905919269397852, 109.74083877280354 24.628401999920605 M50.10933900140226 24.902936688438057 C70.75096010752023 24.85255611076951, 91.70977138392627 25.057354892641307, 110.16362608931959 24.994957545772195 M109.65860744193196 24.839829497784375 C109.53322026971728 44.920006989315155, 109.80427794698625 65.0374456807971, 110.3871857471764 75.24320195242763 M110.06685875914991 25.13916292525828 C109.8791138568893 34.9410581625998, 110.08667984399943 45.17689238004387, 109.81720564626157 74.93375069238246 M110.2314375706017 74.72297051474452 C89.91955742835998 74.93003000937402, 69.30883161351085 75.18813836298882, 50.037488562613724 75.01040592715144 M110.16232369206845 74.92693983651698 C93.54520560242236 75.13958051741123, 76.69847592525184 74.94217211544515, 49.932790436968205 75.12718289233744 M50.154903227835895 74.73371086642146 C50.30157697107643 58.86070746146142, 49.93701910879463 42.75323674082755, 50.056322414427996 25.339266853779556 M49.99176651500166 75.1614456448704 C49.92446589600295 60.62922094166279, 50.018699516169725 46.201565101370214, 50.17477255128324 25.045822993293406" stroke="#000" stroke-width="4" fill="none"/></g><g><path d="M189.97261889651418 24.88675363585353 C202.21760956197977 25.381302431896327, 214.42718228921294 24.905919269397852, 249.74083877280356 24.628401999920605 M190.10933900140225 24.902936688438057 C210.75096010752023 24.85255611076951, 231.70977138392627 25.057354892641307, 250.1636260893196 24.994957545772195 M249.65860744193196 24.839829497784375 C249.53322026971728 44.920006989315155, 249.80427794698625 65.0374456807971, 250.3871857471764 75.24320195242763 M250.0668587591499 25.13916292525828 C249.8791138568893 34.9410581625998, 250.08667984399943 45.17689238004387, 249.81720564626158 74.93375069238246 M250.2314375706017 74.72297051474452 C229.91955742835998 74.93003000937402, 209.30883161351085 75.18813836298882, 190.03748856261373 75.01040592715144 M250.16232369206847 74.92693983651698 C233.54520560242236 75.13958051741123, 216.69847592525184 74.94217211544515, 189.93279043696822 75.12718289233744 M190.1549032278359 74.73371086642146 C190.30157697107643 58.86070746146142, 189.93701910879463 42.75323674082755, 190.056322414428 25.339266853779556 M189.99176651500164 75.1614456448704 C189.92446589600294 60.62922094166279, 190.01869951616973 46.201565101370214, 190.17477255128324 25.045822993293406" stroke="#000" stroke-width="4" fill="none"/></g><text x="80" y="55" style="font-weight:bolder; font-size:22px; " class="id">id19</text><text x="220" y="55" style="font-weight:bolder; font-size:22px; " class="type">str</text></svg>"
`;
exports[`memory-viz CLI output path should produce consistent svg when the output path is a file 1`] = `
"<svg width="1300" height="292" xmlns="http://www.w3.org/2000/svg"><style>
Expand Down
5 changes: 3 additions & 2 deletions memory-viz/src/tests/cli.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ describe.each([
}
);

// TODO: move to only using tmp
describe("memory-viz CLI output path", () => {
const tempDir = tmp.dirSync().name;

Expand Down Expand Up @@ -225,6 +224,7 @@ describe("memory-viz CLI output path", () => {
child.on("close", () => {
const fileContent = fs.readFileSync(outputPath, "utf8");
expect(fileContent).toMatchSnapshot();
fs.unlinkSync(outputPath);
done();
});
},
Expand All @@ -234,7 +234,7 @@ describe("memory-viz CLI output path", () => {
it(
"should overwrite existing svg when the output path is a file that exists",
(done) => {
const outputPath = tmp.fileSync({ postfix: ".json" });
const outputPath = tmp.fileSync({ postfix: ".svg" });
const child = runProgram(outputPath.name);
child.on("close", () => {
const fileContent = fs.readFileSync(outputPath.name, "utf8");
Expand All @@ -253,6 +253,7 @@ describe("memory-viz CLI output path", () => {
child.on("close", () => {
const fileContent = fs.readFileSync(outputPath, "utf8");
expect(fileContent).toMatchSnapshot();
fs.unlinkSync(outputPath);
done();
});
},
Expand Down

0 comments on commit 503d5ae

Please sign in to comment.