-
Notifications
You must be signed in to change notification settings - Fork 717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML diff results page #2535
Merged
HTML diff results page #2535
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
c3ae1b1
HTML diff results page
db846a8
whitespace
fa10419
Vendors JS versions, added to the nav, verbiage
f24398d
Anchor-able line numbers
e5928fd
CSS tweaks, scrollable long lines
acb0c79
Avoid extra new lines in the output
f73416a
Merge branch 'master' into htmldiff
tkadlec 68c51f3
Merge branch 'master' into htmldiff
stoyan 17325c2
use the new generated-html metric
39e89c7
fit and finish and prettier error handling
scottjehl 2320ead
hide html diff from the results menu
bf9824f
spacing
scottjehl 45658f2
HTML diff results page
e9b6e6c
whitespace
2dc48fe
Vendors JS versions, added to the nav, verbiage
f772b74
Anchor-able line numbers
e1f3ea0
CSS tweaks, scrollable long lines
92fa774
Avoid extra new lines in the output
0305a7c
use the new generated-html metric
ceb3e50
fit and finish and prettier error handling
scottjehl 3999d61
hide html diff from the results menu
fed8570
spacing
scottjehl b867f9d
menu item
scottjehl bd88a88
move the diff to an inline worker and minor tweaks
scottjehl 0a6dd5d
typo and docs
scottjehl a2acd7f
social meta
scottjehl e4d5c33
no generated screenshots
scottjehl c9a8a1b
one more time, with feeling
scottjehl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/common.inc'; | ||
|
||
// this output buffer hack avoids a bit of circularity | ||
// on one hand we want the contents of header.inc | ||
// on the other we want to get access to TestRunResults prior to that | ||
ob_start(); | ||
define('NOBANNER', true); // otherwise Twitch banner shows 2x | ||
$tab = 'Test Result'; | ||
$subtab = 'HTML diff'; | ||
include_once INCLUDES_PATH . '/header.inc'; | ||
$results_header = ob_get_contents(); | ||
ob_end_clean(); | ||
|
||
// all prerequisite libs were already required in header.inc | ||
$fileHandler = new FileHandler(); | ||
$testInfo = TestInfo::fromFiles($testPath); | ||
$testRunResults = TestRunResults::fromFiles($testInfo, $run, $cached, $fileHandler); | ||
$pageData = loadAllPageData($testPath); | ||
|
||
$error_message = null; | ||
$delivered_html = null; | ||
$rendered_html = @$pageData[$run][$cached]['rendered-html']; | ||
|
||
if (!$rendered_html) { | ||
$error_message = 'Rendered HTML not available, please run the test again'; | ||
} | ||
|
||
$body_id = @$pageData[$run][$cached]['final_base_page_request_id']; | ||
if (!$body_id) { | ||
$error_message = 'Could not figure out the request ID of the final base page, please run the test again'; | ||
} else { | ||
// TODO: move this to a utility and share with response_body.php | ||
$cachedStr = $cached ? '_Cached' : ''; | ||
$bodies_file = $testPath . '/' . $run . $cachedStr . '_bodies.zip'; | ||
if (is_file($bodies_file)) { | ||
$zip = new ZipArchive(); | ||
if ($zip->open($bodies_file) === true) { | ||
for ($i = 0; $i < $zip->numFiles; $i++) { | ||
$name = $zip->getNameIndex($i); | ||
$parts = explode('-', $name); | ||
$id = trim($parts[1]); | ||
if (!strcmp($id, $body_id)) { | ||
$delivered_html = $zip->getFromIndex($i); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (!$delivered_html) { | ||
$error_message = 'Response body is not available, please turn on the "Save Response Bodies" option in the advanced settings to capture text resources.'; | ||
} | ||
|
||
// template | ||
echo view('pages.htmldiff', [ | ||
'test_results_view' => true, | ||
'body_class' => 'result', | ||
'results_header' => $results_header, | ||
'rendered_html' => $rendered_html, | ||
'delivered_html' => $delivered_html, | ||
'error_message' => $error_message, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
@extends('default') | ||
|
||
@section('style') | ||
<style> | ||
del { | ||
text-decoration: none; | ||
color: #b30000; | ||
background: #fadad7; | ||
} | ||
ins { | ||
background: #eaf2c2; | ||
color: #406619; | ||
text-decoration: none; | ||
} | ||
#delivered, #rendered { | ||
display: none; | ||
} | ||
#diff-result { | ||
white-space: pre-wrap; | ||
font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace; | ||
} | ||
</style> | ||
@endsection | ||
|
||
@section('content') | ||
<div class="results_main_contain"> | ||
<div class="results_main"> | ||
<div class="results_and_command"> | ||
<div class="results_header"> | ||
<h2>HTML Diff</h2> | ||
</div> | ||
</div> | ||
@if ($error_message) | ||
<div id="result" class="results_body error-banner"> | ||
<div>{{ $error_message }}</div> | ||
</div> | ||
@else | ||
<label> | ||
<input type="checkbox" id="prettier"> | ||
Run Prettier before the diff | ||
</label> | ||
<div id="result" class="results_body @if ($error_message) error-banner @endif"> | ||
<div class="overflow-container"> | ||
<pre id="diff-result"></pre> | ||
</div> | ||
<pre id="delivered">{{$delivered_html}}</pre> | ||
<pre id="rendered">{{$rendered_html}}</pre> | ||
</div> | ||
<script src="/assets/js/vendor/diff.min.js"></script> | ||
<script type="module"> | ||
async function diff() { | ||
let before = document.getElementById('delivered').innerText; | ||
let after = document.getElementById('rendered').innerText; | ||
if (document.getElementById('prettier').checked) { | ||
await import("/assets/js/vendor/prettier-standalone.min.js"); | ||
await import("/assets/js/vendor/prettier-parser-html.min.js"); | ||
await import("/assets/js/vendor/prettier-parser-babel.min.js"); | ||
await import("/assets/js/vendor/prettier-parser-postcss.min.js"); | ||
const opts = { | ||
parser: "html", | ||
plugins: prettierPlugins, | ||
}; | ||
before = prettier.format(before, opts); | ||
after = prettier.format(after, opts); | ||
} | ||
|
||
const diff = Diff.diffLines(before, after); | ||
const fragment = document.createDocumentFragment(); | ||
for (let i = 0; i < diff.length; i++) { | ||
|
||
if (diff[i].added && diff[i + 1] && diff[i + 1].removed) { | ||
let swap = diff[i]; | ||
diff[i] = diff[i + 1]; | ||
diff[i + 1] = swap; | ||
} | ||
|
||
let node; | ||
if (diff[i].removed) { | ||
node = document.createElement('del'); | ||
node.appendChild(document.createTextNode(diff[i].value)); | ||
} else if (diff[i].added) { | ||
node = document.createElement('ins'); | ||
node.appendChild(document.createTextNode(diff[i].value)); | ||
} else { | ||
node = document.createTextNode(diff[i].value); | ||
} | ||
fragment.appendChild(node); | ||
} | ||
document.getElementById('diff-result').innerHTML = ''; | ||
document.getElementById('diff-result').appendChild(fragment); | ||
} | ||
diff(); | ||
document.getElementById('prettier').addEventListener('change', diff); | ||
</script> | ||
@endif | ||
|
||
</div> | ||
</div> | ||
|
||
@endsection |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the diff rendering