Skip to content

Commit bd3e5c3

Browse files
committed
add snapshot tests
1 parent f03b11e commit bd3e5c3

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
coverage/
22
node_modules/
3-
_*
3+
~*
44
*.js
55
*.js.map
66
*.d.ts

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<a href="https://g-harel.github.io/blobs">
2+
<a href="https://blobs.dev">
33
<img width="460" height="300" src="./logo/color.svg">
44
</a>
55
<br>
@@ -10,7 +10,7 @@
1010
<img src="https://img.shields.io/bundlephobia/minzip/blobs.svg">
1111
</a>
1212
<br>
13-
<a href="https://g-harel.github.io/blobs">
13+
<a href="https://blobs.dev">
1414
<img src="https://svgsaur.us/?c=0366d6&t=PLAYGROUND&o=b&s=23&w=170&y=38&h=46" />
1515
</a>
1616
</p>

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
"postpublish": "npm run clean",
1212
"build": "npm run clean && rollup -c rollup.config.ts",
1313
"clean": "trash '**/*.js' '**/*.js.map' '**/*.d.ts' '!**/node_modules/**/*'",
14-
"fmt": "prettier --list-different --write --ignore-path .gitignore '**/*.{js,ts}'"
14+
"fmt": "prettier --list-different --write --ignore-path .gitignore '**/*.{js,ts}'",
15+
"test": "jest"
1516
},
1617
"devDependencies": {
18+
"@types/jest": "^24.0.18",
19+
"jest": "^24.9.0",
1720
"prettier": "^1.14.2",
1821
"rollup": "^1.1.0",
1922
"rollup-plugin-typescript2": "^0.18.1",
2023
"rollup-plugin-uglify": "^6.0.1",
2124
"trash-cli": "^1.4.0",
25+
"ts-jest": "^24.0.2",
2226
"tslib": "^1.9.3",
2327
"typescript": "^3.1.3"
2428
},
@@ -40,5 +44,9 @@
4044
"trailingComma": "all",
4145
"bracketSpacing": false,
4246
"arrowParens": "always"
47+
},
48+
"jest": {
49+
"preset": "ts-jest",
50+
"testEnvironment": "node"
4351
}
4452
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`fill 1`] = `" <svg width=\\"109\\" height=\\"109\\" viewBox=\\"0 0 109 109\\" xmlns=\\"http://www.w3.org/2000/svg\\" > <g transform=\\"rotate(29.498919679317623,54.5,54.5)\\"> <path stroke=\\"none\\" stroke-width=\\"0\\" fill=\\"red\\" d=\\"M54.5,14.904644499132317C75.95401897738759,14.904644499132319,92.58177480526493,33.04598102261241,92.58177480526493,54.5C92.58177480526493,75.38985651686268,75.3898565168627,92.06532466605346,54.50000000000001,92.06532466605346C35.140079294728004,92.06532466605346,22.15119020592184,73.859920705272,22.151190205921843,54.50000000000001C22.151190205921846,34.532642771227444,34.53264277122744,14.904644499132315,54.5,14.904644499132317\\" /> </g> </svg> "`;
4+
5+
exports[`guides 1`] = `" <svg width=\\"781\\" height=\\"781\\" viewBox=\\"0 0 781 781\\" xmlns=\\"http://www.w3.org/2000/svg\\" > <g transform=\\"rotate(3.442489226513049,390.5,390.5)\\"> <path stroke=\\"black\\" stroke-width=\\"1\\" fill=\\"yellow\\" d=\\"M390.5,126.33058701145342C422.7599822291789,129.88940798210118,457.1517369455021,130.12745273744557,484.7560168794348,147.19717416039623C512.0337328801013,164.0649575005214,519.8607664658695,201.0400941880963,544.5059054044543,221.56356932561312C570.4261452389634,243.1488969282566,611.757767954232,243.34995278527023,632.3240995385551,270.08590621797185C652.5414957686334,296.36824840046773,656.0291303230811,332.78264002578373,655.5644381263628,365.9381626741163C655.1113638087595,398.264756287615,638.8841165811419,427.5606398067945,629.682628917669,458.5533253272285C620.5587046845699,489.28475972247725,615.7027870312935,520.9907034734381,601.0633639288317,549.5100713596294C585.2723467720306,580.2728838311288,570.3294797379046,615.2818420679224,540.3690947196874,632.546898788455C510.32201395764275,649.8619150450115,472.07720239655697,638.2572446489619,437.8101304629824,643.5868442009801C404.43907720753396,648.777084873582,373.1384278003209,665.5412734118242,339.4109718937594,663.8021610840965C304.5415447372653,662.0041644964896,267.47738691065865,655.0717599723661,240.107297036115,633.3925551389203C212.7182040424496,611.698298381502,203.52330653817336,574.7971987713082,187.7077458632539,543.6416016528067C173.6252529912097,515.9000322349515,160.14941679690548,488.38496713511927,151.34885888571606,458.54436627473683C142.50320157704354,428.5508440731261,137.36144901640372,398.0976221087323,135.5767806585398,366.8778849840634C133.63780162927577,332.95874515221107,121.30298105955632,294.07541490260616,140.33835333792805,265.93430105058394C160.16298030584304,236.62638542805396,209.3656668077185,244.31364742916213,234.98836978172776,219.91186788626783C261.3342517552231,194.82136886934262,256.6549760833187,144.2313918950815,287.8278664113615,125.4726726830595C317.404723276248,107.67438874903958,356.1890316796786,122.54550763000398,390.5,126.33058701145342\\" /> <line x1=\\"390.5\\" y1=\\"126.33058701145342\\" x2=\\"422.7599822291789\\" y2=\\"129.88940798210118\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"484.7560168794348\\" y1=\\"147.19717416039623\\" x2=\\"457.1517369455021\\" y2=\\"130.12745273744557\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"422.7599822291789\\" cy=\\"129.88940798210118\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"457.1517369455021\\" cy=\\"130.12745273744557\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"390.5\\" cy=\\"126.33058701145342\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"484.7560168794348\\" y1=\\"147.19717416039623\\" x2=\\"512.0337328801013\\" y2=\\"164.0649575005214\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"544.5059054044543\\" y1=\\"221.56356932561312\\" x2=\\"519.8607664658695\\" y2=\\"201.0400941880963\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"512.0337328801013\\" cy=\\"164.0649575005214\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"519.8607664658695\\" cy=\\"201.0400941880963\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"484.7560168794348\\" cy=\\"147.19717416039623\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"544.5059054044543\\" y1=\\"221.56356932561312\\" x2=\\"570.4261452389634\\" y2=\\"243.1488969282566\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"632.3240995385551\\" y1=\\"270.08590621797185\\" x2=\\"611.757767954232\\" y2=\\"243.34995278527023\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"570.4261452389634\\" cy=\\"243.1488969282566\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"611.757767954232\\" cy=\\"243.34995278527023\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"544.5059054044543\\" cy=\\"221.56356932561312\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"632.3240995385551\\" y1=\\"270.08590621797185\\" x2=\\"652.5414957686334\\" y2=\\"296.36824840046773\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"655.5644381263628\\" y1=\\"365.9381626741163\\" x2=\\"656.0291303230811\\" y2=\\"332.78264002578373\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"652.5414957686334\\" cy=\\"296.36824840046773\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"656.0291303230811\\" cy=\\"332.78264002578373\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"632.3240995385551\\" cy=\\"270.08590621797185\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"655.5644381263628\\" y1=\\"365.9381626741163\\" x2=\\"655.1113638087595\\" y2=\\"398.264756287615\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"629.682628917669\\" y1=\\"458.5533253272285\\" x2=\\"638.8841165811419\\" y2=\\"427.5606398067945\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"655.1113638087595\\" cy=\\"398.264756287615\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"638.8841165811419\\" cy=\\"427.5606398067945\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"655.5644381263628\\" cy=\\"365.9381626741163\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"629.682628917669\\" y1=\\"458.5533253272285\\" x2=\\"620.5587046845699\\" y2=\\"489.28475972247725\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"601.0633639288317\\" y1=\\"549.5100713596294\\" x2=\\"615.7027870312935\\" y2=\\"520.9907034734381\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"620.5587046845699\\" cy=\\"489.28475972247725\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"615.7027870312935\\" cy=\\"520.9907034734381\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"629.682628917669\\" cy=\\"458.5533253272285\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"601.0633639288317\\" y1=\\"549.5100713596294\\" x2=\\"585.2723467720306\\" y2=\\"580.2728838311288\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"540.3690947196874\\" y1=\\"632.546898788455\\" x2=\\"570.3294797379046\\" y2=\\"615.2818420679224\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"585.2723467720306\\" cy=\\"580.2728838311288\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"570.3294797379046\\" cy=\\"615.2818420679224\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"601.0633639288317\\" cy=\\"549.5100713596294\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"540.3690947196874\\" y1=\\"632.546898788455\\" x2=\\"510.32201395764275\\" y2=\\"649.8619150450115\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"437.8101304629824\\" y1=\\"643.5868442009801\\" x2=\\"472.07720239655697\\" y2=\\"638.2572446489619\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"510.32201395764275\\" cy=\\"649.8619150450115\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"472.07720239655697\\" cy=\\"638.2572446489619\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"540.3690947196874\\" cy=\\"632.546898788455\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"437.8101304629824\\" y1=\\"643.5868442009801\\" x2=\\"404.43907720753396\\" y2=\\"648.777084873582\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"339.4109718937594\\" y1=\\"663.8021610840965\\" x2=\\"373.1384278003209\\" y2=\\"665.5412734118242\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"404.43907720753396\\" cy=\\"648.777084873582\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"373.1384278003209\\" cy=\\"665.5412734118242\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"437.8101304629824\\" cy=\\"643.5868442009801\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"339.4109718937594\\" y1=\\"663.8021610840965\\" x2=\\"304.5415447372653\\" y2=\\"662.0041644964896\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"240.107297036115\\" y1=\\"633.3925551389203\\" x2=\\"267.47738691065865\\" y2=\\"655.0717599723661\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"304.5415447372653\\" cy=\\"662.0041644964896\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"267.47738691065865\\" cy=\\"655.0717599723661\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"339.4109718937594\\" cy=\\"663.8021610840965\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"240.107297036115\\" y1=\\"633.3925551389203\\" x2=\\"212.7182040424496\\" y2=\\"611.698298381502\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"187.7077458632539\\" y1=\\"543.6416016528067\\" x2=\\"203.52330653817336\\" y2=\\"574.7971987713082\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"212.7182040424496\\" cy=\\"611.698298381502\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"203.52330653817336\\" cy=\\"574.7971987713082\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"240.107297036115\\" cy=\\"633.3925551389203\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"187.7077458632539\\" y1=\\"543.6416016528067\\" x2=\\"173.6252529912097\\" y2=\\"515.9000322349515\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"151.34885888571606\\" y1=\\"458.54436627473683\\" x2=\\"160.14941679690548\\" y2=\\"488.38496713511927\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"173.6252529912097\\" cy=\\"515.9000322349515\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"160.14941679690548\\" cy=\\"488.38496713511927\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"187.7077458632539\\" cy=\\"543.6416016528067\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"151.34885888571606\\" y1=\\"458.54436627473683\\" x2=\\"142.50320157704354\\" y2=\\"428.5508440731261\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"135.5767806585398\\" y1=\\"366.8778849840634\\" x2=\\"137.36144901640372\\" y2=\\"398.0976221087323\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"142.50320157704354\\" cy=\\"428.5508440731261\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"137.36144901640372\\" cy=\\"398.0976221087323\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"151.34885888571606\\" cy=\\"458.54436627473683\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"135.5767806585398\\" y1=\\"366.8778849840634\\" x2=\\"133.63780162927577\\" y2=\\"332.95874515221107\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"140.33835333792805\\" y1=\\"265.93430105058394\\" x2=\\"121.30298105955632\\" y2=\\"294.07541490260616\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"133.63780162927577\\" cy=\\"332.95874515221107\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"121.30298105955632\\" cy=\\"294.07541490260616\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"135.5767806585398\\" cy=\\"366.8778849840634\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"140.33835333792805\\" y1=\\"265.93430105058394\\" x2=\\"160.16298030584304\\" y2=\\"236.62638542805396\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"234.98836978172776\\" y1=\\"219.91186788626783\\" x2=\\"209.3656668077185\\" y2=\\"244.31364742916213\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"160.16298030584304\\" cy=\\"236.62638542805396\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"209.3656668077185\\" cy=\\"244.31364742916213\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"140.33835333792805\\" cy=\\"265.93430105058394\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"234.98836978172776\\" y1=\\"219.91186788626783\\" x2=\\"261.3342517552231\\" y2=\\"194.82136886934262\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"287.8278664113615\\" y1=\\"125.4726726830595\\" x2=\\"256.6549760833187\\" y2=\\"144.2313918950815\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"261.3342517552231\\" cy=\\"194.82136886934262\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"256.6549760833187\\" cy=\\"144.2313918950815\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"234.98836978172776\\" cy=\\"219.91186788626783\\" r=\\"2\\" fill=\\"black\\" /> <line x1=\\"287.8278664113615\\" y1=\\"125.4726726830595\\" x2=\\"317.404723276248\\" y2=\\"107.67438874903958\\" stroke-width=\\"1\\" stroke=\\"black\\" /> <line x1=\\"390.5\\" y1=\\"126.33058701145342\\" x2=\\"356.1890316796786\\" y2=\\"122.54550763000398\\" stroke-width=\\"1\\" stroke=\\"black\\" stroke-dasharray=\\"2\\" /> <circle cx=\\"317.404723276248\\" cy=\\"107.67438874903958\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"356.1890316796786\\" cy=\\"122.54550763000398\\" r=\\"1\\" fill=\\"black\\" /> <circle cx=\\"287.8278664113615\\" cy=\\"125.4726726830595\\" r=\\"2\\" fill=\\"black\\" /> </g> </svg> "`;
6+
7+
exports[`stroke 1`] = `" <svg width=\\"226\\" height=\\"226\\" viewBox=\\"0 0 226 226\\" xmlns=\\"http://www.w3.org/2000/svg\\" > <g transform=\\"rotate(10.625043198466301,113,113)\\"> <path stroke=\\"#ff00bb\\" stroke-width=\\"3.8\\" fill=\\"none\\" d=\\"M113,42.187082298945086C122.79474494878556,40.93994738588088,128.08514500519405,54.842942154431036,137.1295411257755,58.80416329407413C146.24165581029771,62.79504348485256,157.51842254183052,60.017049555118255,165.90945623567902,65.36011162379504C174.7168767144728,70.96831151907477,181.0880692974371,79.95796015403899,185.33243631773502,89.49776676385551C189.73428003886482,99.39152421352728,196.20569839281566,111.82247482372702,190.74027198902974,121.17083183675265C184.275146635445,132.22912728784644,166.3394780066649,129.73602552824286,156.80578145715737,138.2912797163517C150.81862065087725,143.66397878400295,152.63580758814575,154.1776323719105,147.2749018411734,160.17535522011516C141.6462691280242,166.4726080764768,133.56901935954286,169.8105956876925,125.7589492466843,173.0261367912584C117.04502915031888,176.6138085839763,108.09560947846845,179.1793135116963,98.72369653099743,180.1647271523213C87.32619013379446,181.36312264914937,72.49281709265853,187.87055519411282,64.72599173408246,179.44347220588492C56.10054832930125,170.08478007279948,66.09720211216101,154.1178572037905,63.27873223580452,141.70658732810776C61.38932710333851,133.38649946758036,50.99025921153393,128.03545137040612,51.11446122271465,119.50443222719099C51.24127550690229,110.79398482176407,63.010835822466824,105.71867007151292,63.928797313315314,97.05579972925904C65.17258032291737,85.31812766621681,49.496028668882154,71.69698855511476,57.133958677847616,62.69799045462372C64.63143952592924,53.86446935255053,80.58301567512933,68.61242545584771,91.45947685068582,64.61919287750527C101.29841121040207,61.00688253251096,102.60284327876244,43.510920460270896,113,42.187082298945086\\" /> </g> </svg> "`;

testing/snapshots.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import blobs, {BlobOptions} from "..";
2+
3+
// Sanity checks to ensure the output remains consistent
4+
// across changes to the source.
5+
const testCases: Record<string, BlobOptions> = {
6+
"fill": {
7+
size: 109,
8+
complexity: 0.1,
9+
contrast: 0.331,
10+
color: "red",
11+
seed: "fill",
12+
},
13+
"stroke": {
14+
size: 226,
15+
complexity: 0.91,
16+
contrast: 0.6,
17+
stroke: {
18+
color: "#ff00bb",
19+
width: 3.8,
20+
},
21+
seed: "stroke",
22+
},
23+
"guides": {
24+
size: 781,
25+
complexity: 1,
26+
contrast: 0.331,
27+
color: "yellow",
28+
guides: true,
29+
seed: "guides",
30+
},
31+
32+
};
33+
34+
for (const testCase of Object.keys(testCases)) {
35+
test(testCase, () => {
36+
expect(blobs(testCases[testCase])).toMatchSnapshot();
37+
});
38+
}

0 commit comments

Comments
 (0)