1
0
Fork 0
mirror of https://gitlab.com/news-flash/article_scraper.git synced 2025-07-07 16:15:32 +02:00

always use fakehost url for tests

This commit is contained in:
Jan Lukas Gernert 2023-03-01 00:46:35 +01:00
parent 80de6d177c
commit cea23f1638
2 changed files with 15 additions and 19 deletions

View file

@ -1,4 +1,4 @@
<article><section id="readability-page-1"><p><strong>So finally you're <a href="/code/2013/testing-frontend-javascript-code-using-mocha-chai-and-sinon/" target="_blank">testing your frontend JavaScript code</a>? Great! The more you <article><section id="readability-page-1"><p><strong>So finally you're <a href="http://fakehost/code/2013/testing-frontend-javascript-code-using-mocha-chai-and-sinon/" target="_blank">testing your frontend JavaScript code</a>? Great! The more you
write tests, the more confident you are with your code… but how much precisely? write tests, the more confident you are with your code… but how much precisely?
That's where <a href="http://en.wikipedia.org/wiki/Code_coverage" target="_blank">code coverage</a> might That's where <a href="http://en.wikipedia.org/wiki/Code_coverage" target="_blank">code coverage</a> might
help.</strong></p> help.</strong></p>
@ -30,7 +30,7 @@ with nodejs.</em></p>
<p>Source files: <a href="https://raw.github.com/alex-seville/blanket/master/dist/qunit/blanket.min.js" target="_blank">blanket.js</a>, <p>Source files: <a href="https://raw.github.com/alex-seville/blanket/master/dist/qunit/blanket.min.js" target="_blank">blanket.js</a>,
<a href="https://raw.github.com/alex-seville/blanket/master/src/adapters/mocha-blanket.js" target="_blank">mocha-blanket.js</a></p> <a href="https://raw.github.com/alex-seville/blanket/master/src/adapters/mocha-blanket.js" target="_blank">mocha-blanket.js</a></p>
<p>As an example, let's reuse the silly <code>Cow</code> example we used <p>As an example, let's reuse the silly <code>Cow</code> example we used
<a href="/code/2013/testing-frontend-javascript-code-using-mocha-chai-and-sinon/" target="_blank">in a previous episode</a>:</p> <a href="http://fakehost/code/2013/testing-frontend-javascript-code-using-mocha-chai-and-sinon/" target="_blank">in a previous episode</a>:</p>
<pre><code>// cow.js <pre><code>// cow.js
(function(exports) { (function(exports) {
"use strict"; "use strict";
@ -105,7 +105,7 @@ describe("Cow", function() {
be loaded.</li> be loaded.</li>
</ul> </ul>
<p>Running the tests now gives us something like this:</p> <p>Running the tests now gives us something like this:</p>
<p><img alt="screenshot" src="/static/code/2013/blanket-coverage.png"></p> <p><img alt="screenshot" src="http://fakehost/static/code/2013/blanket-coverage.png"></p>
<p>As you can see, the report at the bottom highlights that we haven't actually <p>As you can see, the report at the bottom highlights that we haven't actually
tested the case where an error is raised in case a target name is missing. tested the case where an error is raised in case a target name is missing.
We've been informed of that, nothing more, nothing less. We simply know We've been informed of that, nothing more, nothing less. We simply know

View file

@ -6,13 +6,13 @@ use crate::{
full_text_parser::{config::ConfigEntry, metadata}, full_text_parser::{config::ConfigEntry, metadata},
}; };
async fn run_test(name: &str, url: Option<Url>) { async fn run_test(name: &str) {
libxml::tree::node::set_node_rc_guard(10); libxml::tree::node::set_node_rc_guard(10);
let _ = env_logger::builder().is_test(true).try_init(); let _ = env_logger::builder().is_test(true).try_init();
let empty_config = ConfigEntry::default(); let empty_config = ConfigEntry::default();
let url = url.unwrap_or_else(|| Url::parse("http://google.com").unwrap()); let url = Url::parse("http://fakehost/test/base/").unwrap();
let html = std::fs::read_to_string(format!("./resources/tests/readability/{name}/source.html")) let html = std::fs::read_to_string(format!("./resources/tests/readability/{name}/source.html"))
.expect("Failed to read source HTML"); .expect("Failed to read source HTML");
let document = crate::FullTextParser::parse_html(&html, None, &empty_config).unwrap(); let document = crate::FullTextParser::parse_html(&html, None, &empty_config).unwrap();
@ -41,7 +41,7 @@ async fn run_test(name: &str, url: Option<Url>) {
article.document = Some(article_document); article.document = Some(article_document);
let html = article.get_content().unwrap(); let html = article.get_content().unwrap();
//std::fs::write("expected.html", &html).unwrap(); std::fs::write("expected.html", &html).unwrap();
let expected = std::fs::read_to_string(format!( let expected = std::fs::read_to_string(format!(
"./resources/tests/readability/{name}/expected.html" "./resources/tests/readability/{name}/expected.html"
@ -53,49 +53,45 @@ async fn run_test(name: &str, url: Option<Url>) {
#[tokio::test] #[tokio::test]
async fn test_001() { async fn test_001() {
run_test("001", None).await run_test("001").await
} }
#[tokio::test] #[tokio::test]
async fn test_002() { async fn test_002() {
run_test("002", None).await run_test("002").await
} }
#[tokio::test] #[tokio::test]
async fn test_003() { async fn test_003() {
run_test("003", None).await run_test("003").await
} }
#[tokio::test] #[tokio::test]
async fn aclu() { async fn aclu() {
run_test("aclu", None).await run_test("aclu").await
} }
#[tokio::test] #[tokio::test]
async fn aktualne() { async fn aktualne() {
run_test("aktualne", None).await run_test("aktualne").await
} }
#[tokio::test] #[tokio::test]
async fn archive_of_our_own() { async fn archive_of_our_own() {
run_test("archive-of-our-own", None).await run_test("archive-of-our-own").await
} }
#[tokio::test] #[tokio::test]
async fn ars_1() { async fn ars_1() {
run_test("ars-1", None).await run_test("ars-1").await
} }
#[tokio::test] #[tokio::test]
async fn base_url_base_element_relative() { async fn base_url_base_element_relative() {
run_test( run_test("base-url-base-element-relative").await
"base-url-base-element-relative",
Some(Url::parse("http://fakehost/test/base/").unwrap()),
)
.await
} }
#[tokio::test] #[tokio::test]
async fn webmd_1() { async fn webmd_1() {
run_test("webmd-1", None).await run_test("webmd-1").await
} }