From e25f74e001ab0ce6c38429f9c8956f7d22b80d64 Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 23 Feb 2023 12:37:07 -0600 Subject: [PATCH 1/4] Create reusable website integration test --- .../integration/test-website-boot.js | 23 +++++++++++++++++++ packages/marko-web/package.json | 1 + 2 files changed, 24 insertions(+) create mode 100644 packages/marko-web/integration/test-website-boot.js diff --git a/packages/marko-web/integration/test-website-boot.js b/packages/marko-web/integration/test-website-boot.js new file mode 100644 index 000000000..1ac0154b4 --- /dev/null +++ b/packages/marko-web/integration/test-website-boot.js @@ -0,0 +1,23 @@ +const fetch = require('node-fetch'); +const { error, log } = console; + +setInterval(async () => { + try { + const res = await fetch('http://localhost:80', { method: 'get' }); + if (!res.ok) { + error('Response not ok!', res.status, res.statusText); + process.exit(1); + } else { + const html = await res.text(); + const found = /.*<\/head>.*<\/body>.*<\/html>.*/is.test(html); + if (!found) { + error('Unable to find closing HTML tags!'); + process.exit(1); + } + log('Integration tests passed!'); + process.exit(0); + } + } catch (e) { + // noop + } +}, 100); diff --git a/packages/marko-web/package.json b/packages/marko-web/package.json index 338ba9c47..7521da55f 100644 --- a/packages/marko-web/package.json +++ b/packages/marko-web/package.json @@ -47,6 +47,7 @@ "http-errors": "^1.8.1", "jquery": "^3.6.3", "marko": "~4.20.0", + "node-fetch": "^2.6.9", "vue": "^2.7.14", "vue-server-renderer": "^2.7.14" }, From 2096c9b65669b6c7b6c8d602f57342a91269ea13 Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 23 Feb 2023 13:19:23 -0600 Subject: [PATCH 2/4] Add `data-marko-error` attribute to errors --- packages/marko-core/components/resolve.marko | 2 +- packages/marko-web/components/document/components/error.marko | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/marko-core/components/resolve.marko b/packages/marko-core/components/resolve.marko index 1fb9d93e4..56e4d9d24 100644 --- a/packages/marko-core/components/resolve.marko +++ b/packages/marko-core/components/resolve.marko @@ -13,7 +13,7 @@ $ const { isArray } = Array; <${input.onError} err=err /> -
An unexpected error occurred: ${err.message}
+
An unexpected error occurred: ${err.message}
${err.stack}
$ console.error(err); diff --git a/packages/marko-web/components/document/components/error.marko b/packages/marko-web/components/document/components/error.marko index 8fe754838..bcbc35214 100644 --- a/packages/marko-web/components/document/components/error.marko +++ b/packages/marko-web/components/document/components/error.marko @@ -14,7 +14,7 @@ $ const error = input.error || {}; <@page for="error"> <@section> -

${input.statusCode} ${input.statusMessage}

+

${input.statusCode} ${input.statusMessage}

${error.message}

${error.stack}
From b3bf8677944f38136ddfc31d5063e9dea4628772 Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 23 Feb 2023 13:19:36 -0600 Subject: [PATCH 3/4] =?UTF-8?q?Test=20for=20presence=20of=20`data-marko-er?= =?UTF-8?q?ror=3D"true=E2=80=9D`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/marko-web/integration/test-website-boot.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/marko-web/integration/test-website-boot.js b/packages/marko-web/integration/test-website-boot.js index 1ac0154b4..9fc48e60d 100644 --- a/packages/marko-web/integration/test-website-boot.js +++ b/packages/marko-web/integration/test-website-boot.js @@ -13,6 +13,13 @@ setInterval(async () => { if (!found) { error('Unable to find closing HTML tags!'); process.exit(1); + return; + } + // now check for any server errors + if (/data-marko-error="true"/g.test(html)) { + error('An in-page server-side Marko error was encountered!'); + process.exit(1); + return; } log('Integration tests passed!'); process.exit(0); From b88e3bb225d2c686109e706639bff81d2fec29b7 Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 23 Feb 2023 13:38:21 -0600 Subject: [PATCH 4/4] Fix lint error --- packages/marko-web/integration/test-website-boot.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/marko-web/integration/test-website-boot.js b/packages/marko-web/integration/test-website-boot.js index 9fc48e60d..d31437701 100644 --- a/packages/marko-web/integration/test-website-boot.js +++ b/packages/marko-web/integration/test-website-boot.js @@ -1,4 +1,5 @@ const fetch = require('node-fetch'); + const { error, log } = console; setInterval(async () => {