From 05eb518e7b180d70790234bf7453d297ac3d40bf Mon Sep 17 00:00:00 2001 From: danstarns Date: Sun, 8 Sep 2024 14:31:42 -0500 Subject: [PATCH 1/2] fix: remove id reassign in data sources --- packages/core/package.json | 2 + packages/core/src/data_sources/index.ts | 1 - .../__snapshots__/jsonplaceholder.ts.snap | 76 +++++++ .../specs/data_sources/jsonplaceholder.ts | 103 ++++++++++ pnpm-lock.yaml | 187 ++++++++++++++++++ 5 files changed, 368 insertions(+), 1 deletion(-) create mode 100644 packages/core/test/specs/data_sources/__snapshots__/jsonplaceholder.ts.snap create mode 100644 packages/core/test/specs/data_sources/jsonplaceholder.ts diff --git a/packages/core/package.json b/packages/core/package.json index d34a87e023..85a8197ec7 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -41,11 +41,13 @@ }, "devDependencies": { "@types/markdown-it": "14.1.2", + "@types/pretty": "2.0.3", "grapesjs-cli": "4.1.3", "jest-environment-jsdom": "29.7.0", "jsdom": "24.1.1", "npm-run-all": "4.1.5", "postcss": "8", + "pretty": "2.0.0", "sass": "1.42.1", "whatwg-fetch": "3.6.20" }, diff --git a/packages/core/src/data_sources/index.ts b/packages/core/src/data_sources/index.ts index 37b3e93602..64d4b3636b 100644 --- a/packages/core/src/data_sources/index.ts +++ b/packages/core/src/data_sources/index.ts @@ -101,7 +101,6 @@ export default class DataSourceManager extends ItemManagerModule { const dataRecord = dr; - accR[i] = dataRecord.attributes; accR[dataRecord.id || i] = dataRecord.attributes; return accR; diff --git a/packages/core/test/specs/data_sources/__snapshots__/jsonplaceholder.ts.snap b/packages/core/test/specs/data_sources/__snapshots__/jsonplaceholder.ts.snap new file mode 100644 index 0000000000..3f0e5aa1d6 --- /dev/null +++ b/packages/core/test/specs/data_sources/__snapshots__/jsonplaceholder.ts.snap @@ -0,0 +1,76 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`JsonPlaceholder Usage should render a list of comments from jsonplaceholder api 1`] = ` +" +
+

+
id labore ex et quam laborum
+

+

+

1
+

+

+

laudantium enim quasi est quidem magnam voluptate ipsam eos + tempora quo necessitatibus + dolor quam autem quasi + reiciendis et nam sapiente accusantium
+

+
+
+

+
quo vero reiciendis velit similique earum
+

+

+

2
+

+

+

est natus enim nihil est dolore omnis voluptatem numquam + et omnis occaecati quod ullam at + voluptatem error expedita pariatur + nihil sint nostrum voluptatem reiciendis et
+

+
+
+

+
odio adipisci rerum aut animi
+

+

+

3
+

+

+

quia molestiae reprehenderit quasi aspernatur + aut expedita occaecati aliquam eveniet laudantium + omnis quibusdam delectus saepe quia accusamus maiores nam est + cum et ducimus et vero voluptates excepturi deleniti ratione
+

+
+
+

+
alias odio sit
+

+

+

4
+

+

+

non et atque + occaecati deserunt quas accusantium unde odit nobis qui voluptatem + quia voluptas consequuntur itaque dolor + et qui rerum deleniti ut occaecati
+

+
+
+

+
vero eaque aliquid doloribus et culpa
+

+

+

5
+

+

+

harum non quasi et ratione + tempore iure ex voluptates in ratione + harum architecto fugit inventore cupiditate + voluptates magni quo et
+

+
+" +`; diff --git a/packages/core/test/specs/data_sources/jsonplaceholder.ts b/packages/core/test/specs/data_sources/jsonplaceholder.ts new file mode 100644 index 0000000000..22551aed0a --- /dev/null +++ b/packages/core/test/specs/data_sources/jsonplaceholder.ts @@ -0,0 +1,103 @@ +import DataSourceManager from '../../../src/data_sources'; +import ComponentWrapper from '../../../src/dom_components/model/ComponentWrapper'; +import { DataVariableType } from '../../../src/data_sources/model/DataVariable'; +import { DataSourceProps } from '../../../src/data_sources/types'; +import { setupTestEditor } from '../../common'; +import EditorModel from '../../../src/editor/model/Editor'; +import htmlFormat from 'pretty'; + +async function getComments() { + const url = 'https://jsonplaceholder.typicode.com/posts/1/comments'; + const response = await fetch(url, { + method: 'GET', + }); + + if (!response.ok) { + throw new Error('Failed to fetch comments'); + } + + return response.json(); +} + +// Comment https://github.com/GrapesJS/grapesjs/discussions/5956#discussioncomment-10559499 +describe('JsonPlaceholder Usage', () => { + let em: EditorModel; + let dsm: DataSourceManager; + let cmpRoot: ComponentWrapper; + + beforeEach(() => { + ({ em, dsm, cmpRoot } = setupTestEditor()); + }); + + afterEach(() => { + em.destroy(); + }); + + test('should render a list of comments from jsonplaceholder api', async () => { + const comments = await getComments(); + const dataSource: DataSourceProps = { + id: 'comments', + records: comments, + }; + dsm.add(dataSource); + + dsm + .get('comments') + .getRecords() + .forEach((record) => { + cmpRoot.append({ + tagName: 'div', + components: [ + { + tagName: 'h4', + components: [ + { + type: DataVariableType, + defaultValue: 'default', + path: `comments.${record?.id}.name`, + }, + ], + }, + { + tagName: 'p', + components: [ + { + type: DataVariableType, + defaultValue: 'default', + path: `comments.${record?.id}.id`, + }, + ], + }, + { + tagName: 'p', + components: [ + { + type: DataVariableType, + defaultValue: 'default', + path: `comments.${record?.id}.body`, + }, + ], + }, + ], + }); + }); + + const html = cmpRoot.toHTML(); + expect(htmlFormat(html)).toMatchSnapshot(); + + const components = cmpRoot.components(); + expect(components.length).toBe(comments.length); + + components.forEach((cmp, i) => { + expect(cmp.get('components')?.length).toBe(3); + const record = comments[i]; + const title = cmp.get('components')?.at(0); + const id = cmp.get('components')?.at(1); + const body = cmp.get('components')?.at(2); + + expect(title?.getInnerHTML()).toContain(record.name); + expect(id?.getInnerHTML()).toContain(record.id.toString()); + expect(body?.getInnerHTML()).toContain(record.body); + }); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4508a47b0b..9046f6bede 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -160,6 +160,9 @@ importers: '@types/markdown-it': specifier: 14.1.2 version: 14.1.2 + '@types/pretty': + specifier: 2.0.3 + version: 2.0.3 grapesjs-cli: specifier: 4.1.3 version: 4.1.3(@types/node@22.4.1)(typescript@5.5.4) @@ -175,6 +178,9 @@ importers: postcss: specifier: '8' version: 8.4.44 + pretty: + specifier: 2.0.0 + version: 2.0.0 sass: specifier: 1.42.1 version: 1.42.1 @@ -867,6 +873,10 @@ packages: resolution: {integrity: sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==} deprecated: Use @eslint/object-schema instead + '@isaacs/cliui@8.0.2': + resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} + engines: {node: '>=12'} + '@istanbuljs/load-nyc-config@1.1.0': resolution: {integrity: sha512-VjeHSlIzpv/NyD3N0YuHfXOPDIixcA1q2ZV98wsMqcYlPmv2n3Yb2lYP9XMElnaFVXg5A7YLTeLu6V84uQDjmQ==} engines: {node: '>=8'} @@ -991,6 +1001,13 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@one-ini/wasm@0.1.1': + resolution: {integrity: sha512-XuySG1E38YScSJoMlqovLru4KTUNSjgVTIjyh7qMX6aNN5HY5Ct5LhRJdxO79JtTzKfzV/bnWpz+zquYrISsvw==} + + '@pkgjs/parseargs@0.11.0': + resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} + engines: {node: '>=14'} + '@pkgr/core@0.1.1': resolution: {integrity: sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==} engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} @@ -1166,6 +1183,9 @@ packages: '@types/parse5@6.0.3': resolution: {integrity: sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==} + '@types/pretty@2.0.3': + resolution: {integrity: sha512-xR96pShNlrxLd3gZqzCnbaAmbYhiRYjW51CDFjektZemqpBZBAAkMwxm4gBraJP/xSgKcsQhLXdlXOwDNWo4VQ==} + '@types/q@1.5.8': resolution: {integrity: sha512-hroOstUScF6zhIi+5+x0dzqrHA1EJi+Irri6b1fxolMTqqHIV/Cg77EtnQcZqZCu8hR3mX2BzIxN4/GzI68Kfw==} @@ -1647,6 +1667,10 @@ packages: abbrev@1.1.1: resolution: {integrity: sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==} + abbrev@2.0.0: + resolution: {integrity: sha512-6/mh1E2u2YgEsCHdY0Yx5oW+61gZU+1vXaoiHHrpKeuRNNgFvS+/jrwHiQhB5apAf5oB7UB7E19ol2R2LKH8hQ==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + accepts@1.3.8: resolution: {integrity: sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==} engines: {node: '>= 0.6'} @@ -1782,6 +1806,10 @@ packages: resolution: {integrity: sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==} engines: {node: '>=10'} + ansi-styles@6.2.1: + resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==} + engines: {node: '>=12'} + any-observable@0.3.0: resolution: {integrity: sha512-/FQM1EDkTsf63Ub2C6O7GuYFDsSXUwsaZDurV0np41ocwq0jthUAYCmhBX9f+KwlaCgIuWyr/4WlUQUBfKfZog==} engines: {node: '>=6'} @@ -2427,6 +2455,13 @@ packages: resolution: {integrity: sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==} engines: {'0': node >= 0.8} + condense-newlines@0.2.1: + resolution: {integrity: sha512-P7X+QL9Hb9B/c8HI5BFFKmjgBu2XpQuF98WZ9XkO+dBGgk5XgwiQz7o1SmpglNWId3581UcS0SFAWfoIhMHPfg==} + engines: {node: '>=0.10.0'} + + config-chain@1.1.13: + resolution: {integrity: sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==} + configstore@5.0.1: resolution: {integrity: sha512-aMKprgk5YhBNyH25hj8wGt2+D52Sw1DRRIzqBwLp2Ya9mFmY8KPvvtvmna8SxVR9JMZ4kzMD68N22vlaRpkeFA==} engines: {node: '>=8'} @@ -3110,6 +3145,11 @@ packages: ecc-jsbn@0.1.2: resolution: {integrity: sha512-eh9O+hwRHNbG4BLTjEl3nw044CkGm5X6LoaCf7LPp7UU8Qrt47JYNi6nPX8xjW97TKGKm1ouctg0QSpZe9qrnw==} + editorconfig@1.0.4: + resolution: {integrity: sha512-L9Qe08KWTlqYMVvMcTIvMAdl1cDUubzRNYL+WfA4bLDMHe4nemKkpmYzkznE1FwLKu0EEmy6obgQKzMJrg4x9Q==} + engines: {node: '>=14'} + hasBin: true + ee-first@1.1.1: resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==} @@ -3728,6 +3768,10 @@ packages: foreach@2.0.6: resolution: {integrity: sha512-k6GAGDyqLe9JaebCsFCoudPPWfihKu8pylYXRlqP1J7ms39iPoTtk2fviNglIeQEwdh0bQeKJ01ZPyuyQvKzwg==} + foreground-child@3.3.0: + resolution: {integrity: sha512-Ld2g8rrAyMYFXBhEqMz8ZAHBi4J4uS1i/CxGMDnjyFWddMXLVcDp051DZfu+t7+ab7Wv6SMqpWmyFIj5UbfFvg==} + engines: {node: '>=14'} + forever-agent@0.6.1: resolution: {integrity: sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw==} @@ -3863,6 +3907,10 @@ packages: glob-to-regexp@0.4.1: resolution: {integrity: sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==} + glob@10.4.5: + resolution: {integrity: sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==} + hasBin: true + glob@7.2.3: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} deprecated: Glob versions prior to v9 are no longer supported @@ -4601,6 +4649,10 @@ packages: is-weakref@1.0.2: resolution: {integrity: sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==} + is-whitespace@0.3.0: + resolution: {integrity: sha512-RydPhl4S6JwAyj0JJjshWJEFG6hNye3pZFBRZaTUfZFwGHxzppNaNOVgQuS/E/SlhrApuMXrpnK1EEIXfdo3Dg==} + engines: {node: '>=0.10.0'} + is-windows@1.0.2: resolution: {integrity: sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==} engines: {node: '>=0.10.0'} @@ -4660,6 +4712,9 @@ packages: resolution: {integrity: sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==} engines: {node: '>=8'} + jackspeak@3.4.3: + resolution: {integrity: sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==} + jake@10.9.2: resolution: {integrity: sha512-2P4SQ0HrLQ+fw6llpLnOaGAvN2Zu6778SJMrCUwns4fOoG9ayrTiZk3VV8sCPkVZF8ab0zksVpS8FDY5pRCNBA==} engines: {node: '>=10'} @@ -4813,6 +4868,15 @@ packages: node-notifier: optional: true + js-beautify@1.15.1: + resolution: {integrity: sha512-ESjNzSlt/sWE8sciZH8kBF8BPlwXPwhR6pWKAw8bw4Bwj+iZcnKW6ONWUutJ7eObuBZQpiIb8S7OYspWrKt7rA==} + engines: {node: '>=14'} + hasBin: true + + js-cookie@3.0.5: + resolution: {integrity: sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==} + engines: {node: '>=14'} + js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} @@ -5402,6 +5466,10 @@ packages: resolution: {integrity: sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA==} engines: {node: '>=16 || 14 >=14.17'} + minimatch@9.0.1: + resolution: {integrity: sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w==} + engines: {node: '>=16 || 14 >=14.17'} + minimatch@9.0.3: resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} engines: {node: '>=16 || 14 >=14.17'} @@ -5525,6 +5593,11 @@ packages: resolution: {integrity: sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==} hasBin: true + nopt@7.2.1: + resolution: {integrity: sha512-taM24ViiimT/XntxbPyJQzCG+p4EKOpgD3mxFwW38mGjVUrfERQOeY4EDHjdnptttfHuHQXFx+lTP08Q+mLa/w==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + hasBin: true + normalize-package-data@2.5.0: resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} @@ -5745,6 +5818,9 @@ packages: resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==} engines: {node: '>=6'} + package-json-from-dist@1.0.0: + resolution: {integrity: sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==} + package-json@6.5.0: resolution: {integrity: sha512-k3bdm2n25tkyxcjSKzB5x8kfVxlMdgsbPr0GkZcwHsLpba6cBjqCt1KlcChKEvxHIcTB1FVMuwoijZ26xex5MQ==} engines: {node: '>=8'} @@ -6153,6 +6229,10 @@ packages: resolution: {integrity: sha512-28iF6xPQrP8Oa6uxE6a1biz+lWeTOAPKggvjB8HAs6nVMKZwf5bG++632Dx614hIWgUPkgivRfG+a8uAXGTIbA==} engines: {node: '>=4'} + pretty@2.0.0: + resolution: {integrity: sha512-G9xUchgTEiNpormdYBl+Pha50gOUovT18IvAe7EYMZ1/f9W/WWMPRn+xI68yXNMUk3QXHDwo/1wV/4NejVNe1w==} + engines: {node: '>=0.10.0'} + prismjs@1.29.0: resolution: {integrity: sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==} engines: {node: '>=6'} @@ -6182,6 +6262,9 @@ packages: property-information@6.5.0: resolution: {integrity: sha512-PgTgs/BlvHxOu8QuEN7wi5A0OmXaBcHpmCSTehcs6Uuu9IkDIEo13Hy7n898RHfrQ49vKCoGeWZSaAK01nwVig==} + proto-list@1.2.4: + resolution: {integrity: sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==} + protocols@2.0.1: resolution: {integrity: sha512-/XJ368cyBJ7fzLMwLKv1e4vLxOju2MNAIokcr7meSaNcVbWz/CPcW22cP04mwxOErdA5mwjA8Q6w/cdAQxVn7Q==} @@ -6680,6 +6763,10 @@ packages: signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} + signal-exit@4.1.0: + resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==} + engines: {node: '>=14'} + simple-swizzle@0.2.2: resolution: {integrity: sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==} @@ -7783,6 +7870,10 @@ packages: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} + wrap-ansi@8.1.0: + resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} + engines: {node: '>=12'} + wrappy@1.0.2: resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} @@ -8783,6 +8874,15 @@ snapshots: '@humanwhocodes/object-schema@2.0.3': {} + '@isaacs/cliui@8.0.2': + dependencies: + string-width: 5.1.2 + string-width-cjs: string-width@4.2.3 + strip-ansi: 7.1.0 + strip-ansi-cjs: strip-ansi@6.0.1 + wrap-ansi: 8.1.0 + wrap-ansi-cjs: wrap-ansi@7.0.0 + '@istanbuljs/load-nyc-config@1.1.0': dependencies: camelcase: 5.3.1 @@ -9006,6 +9106,11 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 + '@one-ini/wasm@0.1.1': {} + + '@pkgjs/parseargs@0.11.0': + optional: true + '@pkgr/core@0.1.1': {} '@samverschueren/stream-to-observable@0.3.1(rxjs@6.6.7)': @@ -9202,6 +9307,8 @@ snapshots: '@types/parse5@6.0.3': {} + '@types/pretty@2.0.3': {} + '@types/q@1.5.8': {} '@types/qs@6.9.15': {} @@ -10099,6 +10206,8 @@ snapshots: abbrev@1.1.1: {} + abbrev@2.0.0: {} + accepts@1.3.8: dependencies: mime-types: 2.1.35 @@ -10228,6 +10337,8 @@ snapshots: ansi-styles@5.2.0: {} + ansi-styles@6.2.1: {} + any-observable@0.3.0(rxjs@6.6.7): optionalDependencies: rxjs: 6.6.7 @@ -11038,6 +11149,17 @@ snapshots: readable-stream: 2.3.8 typedarray: 0.0.6 + condense-newlines@0.2.1: + dependencies: + extend-shallow: 2.0.1 + is-whitespace: 0.3.0 + kind-of: 3.2.2 + + config-chain@1.1.13: + dependencies: + ini: 1.3.8 + proto-list: 1.2.4 + configstore@5.0.1: dependencies: dot-prop: 5.3.0 @@ -11685,6 +11807,13 @@ snapshots: jsbn: 0.1.1 safer-buffer: 2.1.2 + editorconfig@1.0.4: + dependencies: + '@one-ini/wasm': 0.1.1 + commander: 10.0.1 + minimatch: 9.0.1 + semver: 7.6.3 + ee-first@1.1.1: {} ejs@3.1.10: @@ -12422,6 +12551,11 @@ snapshots: foreach@2.0.6: {} + foreground-child@3.3.0: + dependencies: + cross-spawn: 7.0.3 + signal-exit: 4.1.0 + forever-agent@0.6.1: {} form-data@2.3.3: @@ -12558,6 +12692,15 @@ snapshots: glob-to-regexp@0.4.1: {} + glob@10.4.5: + dependencies: + foreground-child: 3.3.0 + jackspeak: 3.4.3 + minimatch: 9.0.5 + minipass: 7.1.2 + package-json-from-dist: 1.0.0 + path-scurry: 1.11.1 + glob@7.2.3: dependencies: fs.realpath: 1.0.0 @@ -13392,6 +13535,8 @@ snapshots: dependencies: call-bind: 1.0.7 + is-whitespace@0.3.0: {} + is-windows@1.0.2: {} is-wsl@1.1.0: {} @@ -13457,6 +13602,12 @@ snapshots: html-escaper: 2.0.2 istanbul-lib-report: 3.0.1 + jackspeak@3.4.3: + dependencies: + '@isaacs/cliui': 8.0.2 + optionalDependencies: + '@pkgjs/parseargs': 0.11.0 + jake@10.9.2: dependencies: async: 3.2.6 @@ -13798,6 +13949,16 @@ snapshots: - supports-color - ts-node + js-beautify@1.15.1: + dependencies: + config-chain: 1.1.13 + editorconfig: 1.0.4 + glob: 10.4.5 + js-cookie: 3.0.5 + nopt: 7.2.1 + + js-cookie@3.0.5: {} + js-tokens@4.0.0: {} js-yaml@3.14.1: @@ -14607,6 +14768,10 @@ snapshots: dependencies: brace-expansion: 2.0.1 + minimatch@9.0.1: + dependencies: + brace-expansion: 2.0.1 + minimatch@9.0.3: dependencies: brace-expansion: 2.0.1 @@ -14754,6 +14919,10 @@ snapshots: dependencies: abbrev: 1.1.1 + nopt@7.2.1: + dependencies: + abbrev: 2.0.0 + normalize-package-data@2.5.0: dependencies: hosted-git-info: 2.8.9 @@ -14993,6 +15162,8 @@ snapshots: p-try@2.2.0: {} + package-json-from-dist@1.0.0: {} + package-json@6.5.0: dependencies: got: 9.6.0 @@ -15447,6 +15618,12 @@ snapshots: pretty-time@1.1.0: {} + pretty@2.0.0: + dependencies: + condense-newlines: 0.2.1 + extend-shallow: 2.0.1 + js-beautify: 1.15.1 + prismjs@1.29.0: {} process-nextick-args@2.0.1: {} @@ -15466,6 +15643,8 @@ snapshots: property-information@6.5.0: {} + proto-list@1.2.4: {} + protocols@2.0.1: {} proxy-addr@2.0.7: @@ -16061,6 +16240,8 @@ snapshots: signal-exit@3.0.7: {} + signal-exit@4.1.0: {} + simple-swizzle@0.2.2: dependencies: is-arrayish: 0.3.2 @@ -17570,6 +17751,12 @@ snapshots: string-width: 4.2.3 strip-ansi: 6.0.1 + wrap-ansi@8.1.0: + dependencies: + ansi-styles: 6.2.1 + string-width: 5.1.2 + strip-ansi: 7.1.0 + wrappy@1.0.2: {} write-file-atomic@3.0.3: From a6aa3c1241c5bde0763a15222d98d0472c422b66 Mon Sep 17 00:00:00 2001 From: danstarns Date: Wed, 9 Oct 2024 08:15:03 -0700 Subject: [PATCH 2/2] refactor: remove external deps in test --- packages/core/package.json | 1 + .../specs/data_sources/jsonplaceholder.ts | 53 ++++++++++++++----- pnpm-lock.yaml | 8 +++ 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index e61e549920..df39cd0f94 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -41,6 +41,7 @@ }, "devDependencies": { "@types/markdown-it": "14.1.2", + "@types/pretty": "^2.0.3", "grapesjs-cli": "workspace:^", "jest-environment-jsdom": "29.7.0", "jsdom": "24.1.1", diff --git a/packages/core/test/specs/data_sources/jsonplaceholder.ts b/packages/core/test/specs/data_sources/jsonplaceholder.ts index 22551aed0a..ab20abe435 100644 --- a/packages/core/test/specs/data_sources/jsonplaceholder.ts +++ b/packages/core/test/specs/data_sources/jsonplaceholder.ts @@ -6,17 +6,46 @@ import { setupTestEditor } from '../../common'; import EditorModel from '../../../src/editor/model/Editor'; import htmlFormat from 'pretty'; -async function getComments() { - const url = 'https://jsonplaceholder.typicode.com/posts/1/comments'; - const response = await fetch(url, { - method: 'GET', - }); - - if (!response.ok) { - throw new Error('Failed to fetch comments'); - } +function getComments() { + const json = [ + { + postId: 1, + id: 1, + name: 'id labore ex et quam laborum', + email: 'Eliseo@gardner.biz', + body: 'laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium', + }, + { + postId: 1, + id: 2, + name: 'quo vero reiciendis velit similique earum', + email: 'Jayne_Kuhic@sydney.com', + body: 'est natus enim nihil est dolore omnis voluptatem numquam\net omnis occaecati quod ullam at\nvoluptatem error expedita pariatur\nnihil sint nostrum voluptatem reiciendis et', + }, + { + postId: 1, + id: 3, + name: 'odio adipisci rerum aut animi', + email: 'Nikita@garfield.biz', + body: 'quia molestiae reprehenderit quasi aspernatur\naut expedita occaecati aliquam eveniet laudantium\nomnis quibusdam delectus saepe quia accusamus maiores nam est\ncum et ducimus et vero voluptates excepturi deleniti ratione', + }, + { + postId: 1, + id: 4, + name: 'alias odio sit', + email: 'Lew@alysha.tv', + body: 'non et atque\noccaecati deserunt quas accusantium unde odit nobis qui voluptatem\nquia voluptas consequuntur itaque dolor\net qui rerum deleniti ut occaecati', + }, + { + postId: 1, + id: 5, + name: 'vero eaque aliquid doloribus et culpa', + email: 'Hayden@althea.biz', + body: 'harum non quasi et ratione\ntempore iure ex voluptates in ratione\nharum architecto fugit inventore cupiditate\nvoluptates magni quo et', + }, + ]; - return response.json(); + return json; } // Comment https://github.com/GrapesJS/grapesjs/discussions/5956#discussioncomment-10559499 @@ -34,10 +63,10 @@ describe('JsonPlaceholder Usage', () => { }); test('should render a list of comments from jsonplaceholder api', async () => { - const comments = await getComments(); + const comments = getComments(); const dataSource: DataSourceProps = { id: 'comments', - records: comments, + records: comments as any, }; dsm.add(dataSource); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 54d589095f..c24154b7bd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -239,6 +239,9 @@ importers: '@types/markdown-it': specifier: 14.1.2 version: 14.1.2 + '@types/pretty': + specifier: ^2.0.3 + version: 2.0.3 grapesjs-cli: specifier: workspace:^ version: link:../cli @@ -1276,6 +1279,9 @@ packages: '@types/parse5@6.0.3': resolution: {integrity: sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==} + '@types/pretty@2.0.3': + resolution: {integrity: sha512-xR96pShNlrxLd3gZqzCnbaAmbYhiRYjW51CDFjektZemqpBZBAAkMwxm4gBraJP/xSgKcsQhLXdlXOwDNWo4VQ==} + '@types/q@1.5.8': resolution: {integrity: sha512-hroOstUScF6zhIi+5+x0dzqrHA1EJi+Irri6b1fxolMTqqHIV/Cg77EtnQcZqZCu8hR3mX2BzIxN4/GzI68Kfw==} @@ -9494,6 +9500,8 @@ snapshots: '@types/parse5@6.0.3': {} + '@types/pretty@2.0.3': {} + '@types/q@1.5.8': {} '@types/qs@6.9.15': {}