Skip to content

Commit 63fe0e1

Browse files
committed
Merge remote-tracking branch 'upstream/main' into ling/add-init-script
2 parents cb9c567 + 3361e00 commit 63fe0e1

5 files changed

Lines changed: 88 additions & 2 deletions

File tree

.github/pull_request_template.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### Issue # (if available)
2+
3+
<!-- **Please post the link to the resolved issue** -->
4+
5+
### Description of changes
6+
7+
<!-- **Please explain what your changes does** -->
8+
9+
### Checklist
10+
11+
- [ ] Added change to the changelog
12+
- [ ] Created unit tests for my feature (if needed)
13+
- [ ] Created a least one integration test

.github/workflows/ci.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
on: [push, pull_request]
1+
on:
2+
push:
3+
branches:
4+
- main
5+
pull_request:
26

37
name: Continuous integration
48

@@ -52,7 +56,16 @@ jobs:
5256
steps:
5357
- uses: actions/checkout@v6
5458
- uses: dtolnay/rust-toolchain@stable
55-
- run: cargo test
59+
- run: cargo test --lib
60+
61+
test-integration:
62+
name: Test Integration
63+
needs: [fmt, clippy, msrv]
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v6
67+
- uses: dtolnay/rust-toolchain@stable
68+
- run: RUST_TEST_THREADS=1 cargo test --test '*'
5669

5770
test-fetcher:
5871
name: Test Fetcher

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "chromiumoxide"
33
version = "0.8.0"
44
rust-version = "1.85"
5+
autotests = false
56
authors = ["Matthias Seitz <[email protected]>"]
67
edition = "2021"
78
license = "MIT OR Apache-2.0"
@@ -88,6 +89,11 @@ required-features = ["async-std-runtime", "_fetcher-native-async-std"]
8889
name = "fetcher"
8990
required-features = ["_fetcher-native-tokio"]
9091

92+
[[test]]
93+
name = "chromiumoxide_tests"
94+
path = "tests/lib.rs"
95+
harness = true
96+
9197
[workspace]
9298
members = [
9399
"chromiumoxide_pdl",

tests/basic.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use crate::test;
2+
3+
#[tokio::test]
4+
async fn test_basic() {
5+
test(async |browser| {
6+
let page = browser.new_page("about:blank").await.unwrap();
7+
page.goto("https://www.google.com").await.unwrap();
8+
let title = page.get_title().await.unwrap().unwrap();
9+
assert!(title.contains("Google"));
10+
})
11+
.await;
12+
}

tests/lib.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::panic;
2+
3+
use chromiumoxide::{Browser, BrowserConfig};
4+
use futures::{FutureExt, StreamExt};
5+
6+
mod basic;
7+
8+
pub async fn test<T>(test: T)
9+
where
10+
T: for<'a> AsyncFnOnce(&'a mut Browser),
11+
{
12+
test_config(BrowserConfig::builder().build().unwrap(), test).await;
13+
}
14+
15+
pub async fn test_config<T>(config: BrowserConfig, test: T)
16+
where
17+
T: for<'a> AsyncFnOnce(&'a mut Browser),
18+
{
19+
let (mut browser, mut handler) = Browser::launch(config).await.unwrap();
20+
21+
let handle = tokio::spawn(async move {
22+
while let Some(h) = handler.next().await {
23+
match h {
24+
Ok(_) => continue,
25+
Err(_) => break,
26+
}
27+
}
28+
});
29+
30+
let browser_ref = &mut browser;
31+
let result = async move {
32+
panic::AssertUnwindSafe(test(browser_ref))
33+
.catch_unwind()
34+
.await
35+
}
36+
.await;
37+
38+
browser.close().await.unwrap();
39+
handle.await.unwrap();
40+
41+
assert!(result.is_ok())
42+
}

0 commit comments

Comments
 (0)