Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #599 from zarathustra323/4.x_shared-website-test
Browse files Browse the repository at this point in the history
Create reusable website integration test
  • Loading branch information
zarathustra323 authored Feb 23, 2023
2 parents 9f8e792 + b88e3bb commit d40e543
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/marko-core/components/resolve.marko
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $ const { isArray } = Array;
<${input.onError} err=err />
</if>
<else>
<pre>An unexpected error occurred: ${err.message}</pre>
<pre data-marko-error="true">An unexpected error occurred: ${err.message}</pre>
<if(isDev)>
<pre>${err.stack}</pre>
$ console.error(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $ const error = input.error || {};
<@page for="error">
<marko-web-page-wrapper>
<@section>
<h3>${input.statusCode} ${input.statusMessage}</h3>
<h3 data-marko-error="true">${input.statusCode} ${input.statusMessage}</h3>
<h4>${error.message}</h4>
<if(isDev)>
<pre>${error.stack}</pre>
Expand Down
31 changes: 31 additions & 0 deletions packages/marko-web/integration/test-website-boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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);
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);
}
} catch (e) {
// noop
}
}, 100);
1 change: 1 addition & 0 deletions packages/marko-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit d40e543

Please sign in to comment.