Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a8ca0e2
Moved to multiplatform builds mostly equivalent to the old build
McDjuady Jun 29, 2022
78c10b9
Stated work to implement parsers and fetchers in js aswell
McDjuady Sep 19, 2022
3c73e8c
Added support for jsExecution on the JS-Platform
McDjuady Sep 24, 2022
c263ea6
Added pretty printing to match output to JSoup.
McDjuady Sep 26, 2022
705b592
Fixed up builds to provide common configurations for karma and webpack
McDjuady Sep 26, 2022
cf94383
Merge branch 'master' into multiplatform
McDjuady Sep 27, 2022
6175925
Fixed up buildscripts and added multiplatform covention plugins
McDjuady Sep 30, 2022
450dd60
Opt into kotlinx.coroutines.ExperimentalCoroutinesApi on all test sou…
McDjuady Oct 2, 2022
6c116c2
Started work on porting test-utils to JS
McDjuady Oct 16, 2022
b6e3693
Improved testcontainer support in JS
McDjuady Oct 19, 2022
ad8f356
Merge branch 'master' of https://github.com/skrapeit/skrape.it into m…
McDjuady Oct 19, 2022
d607039
Implemented Assertions in JS
McDjuady Oct 21, 2022
4948848
Removed BrowserFetcher dependency and use HtmlUnit directly
McDjuady Oct 21, 2022
53ccb08
Fixed https wiremock under JS
McDjuady Oct 22, 2022
65e8ea5
Fixed Kover coverage
McDjuady Oct 28, 2022
829abf0
Started work on using a single fetcher with a KtorClient to enable be…
McDjuady Oct 31, 2022
cc1f349
Partially added Request.sslRelaxed
McDjuady Nov 2, 2022
c17a783
Added timeout field to KtorRequestBuilder
McDjuady Nov 2, 2022
da5fd4f
Added KtorScraper extension methods
McDjuady Nov 2, 2022
a8d61be
Started removal of fetchers
McDjuady Nov 4, 2022
22007b0
Started removal of fetchers
McDjuady Nov 4, 2022
fa01699
Mostly implemented the new Scraper
McDjuady Nov 5, 2022
f7e381b
Removed different fetchers replacing them with a single implementation
McDjuady Dec 6, 2022
9cbd11a
Fixed up JS mocks to work with the IR backend
McDjuady Dec 7, 2022
9ed83f9
Fixed issue in timeout test
McDjuady Dec 7, 2022
0942056
WIP
McDjuady Dec 10, 2022
16f2e62
Multiplatform integrationtests
McDjuady Dec 10, 2022
2b18278
Use builtin Ktor types in fetcher
McDjuady Jan 16, 2023
90ae18d
Changed legacy api to only be available on JVM with corresponding dep…
McDjuady Jan 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions assertions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
plugins {
buildsrc.convention.`kotlin-jvm`
buildsrc.convention.`publish-jvm`
buildsrc.convention.`kotlin-multiplatform`
buildsrc.convention.`kotlin-multiplatform-jvm`
buildsrc.convention.`kotlin-multiplatform-js-web`
buildsrc.convention.`kotlin-multiplatform-js-node`
buildsrc.convention.`publish-multiplatform`
}

dependencies {
api(projects.htmlParser)
api(projects.dsl)
api(projects.fetcher.baseFetcher)
}
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
api(projects.htmlParser)
api(projects.dsl)
api(projects.fetcher)
}
}
val commonTest by getting {
dependencies {
implementation(Deps.Kotest.datatest)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package it.skrape.matchers

import it.skrape.fetcher.Result
import io.ktor.http.*

public fun Result.Status.statusAssertion(value: Boolean, status: Result.Status): Result.Status {
public fun HttpStatusCode.statusAssertion(value: Boolean, status: HttpStatusCode): HttpStatusCode {
return this.also { generalAssertion(value, status) }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package it.skrape.matchers

import io.ktor.http.*

infix fun ContentType?.toMatch(expected: ContentType?): ContentType? =
this.apply {
generalAssertion(
this == expected
|| (this != null && expected?.match(this.withWildcardParameter()) == true)
|| (expected != null && this?.match(expected.withWildcardParameter()) == true)
, expected)
}

infix fun ContentType?.toMatch(expected: String): ContentType? = toMatch(ContentType.parse(expected))

infix fun ContentType?.toBeExactly(expected: ContentType?): ContentType? =
this.apply { generalAssertion(this == expected, expected) }

infix fun ContentType?.toBeExactly(expected: String): ContentType? = toBeExactly(ContentType.parse(expected))

infix fun ContentType?.notToMatch(expected: ContentType?): ContentType? =
this.apply {
generalAssertion(
(this != expected
&& (this != null && expected?.match(this.withWildcardParameter()) == false)) && !this.match(expected.withWildcardParameter())
, expected)
}

infix fun ContentType?.notToMatch(expected: String): ContentType? = notToMatch(ContentType.parse(expected))

infix fun ContentType?.notToBe(expected: ContentType?): ContentType? =
this.apply { generalAssertion(this != expected, expected) }

infix fun ContentType?.notToBe(expected: String): ContentType? = notToBe(ContentType.parse(expected))

fun ContentType.withWildcardParameter(ifEmpty: Boolean = true) =
if (!ifEmpty || parameters.isEmpty()) {
withParameter("*","*")
} else {
this
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@file:Suppress("FunctionName", "EnumEntryName")

package it.skrape.matchers

import io.ktor.http.*
import kotlin.js.JsName


private val informationalResponse = HttpStatusCode(1, "Informational Response")
private val successful = HttpStatusCode(2, "Successful")
private val redirection = HttpStatusCode(3, "Redirection")
private val clientError = HttpStatusCode(4, "Client Error")
private val serverError = HttpStatusCode(5, "Server Error")
private val groupStatusCodes = listOf(informationalResponse, successful, redirection, clientError, serverError)

val HttpStatusCode.Companion.InformationalResponse
get() = informationalResponse
val HttpStatusCode.Companion.Successful
get() = successful
val HttpStatusCode.Companion.Redirection
get() = redirection
val HttpStatusCode.Companion.ClientError
get() = clientError
val HttpStatusCode.Companion.ServerError
get() = serverError

val HttpStatusCode.Companion.allGroupStatusCodes
get() = groupStatusCodes

public infix fun HttpStatusCode.toBe(expected: HttpStatusCode): HttpStatusCode {
@Suppress("MagicNumber")
if (expected.value <= 5) {
return statusAssertion(this.value / 100 == expected.value, expected)
}
return statusAssertion(this == expected && this.description == expected.description, expected)
}

public infix fun HttpStatusCode.toBeExactly(expected: HttpStatusCode): HttpStatusCode {
if (expected.value > 5) statusAssertion(description == expected.description, expected)
return toBe(expected)
}

public infix fun HttpStatusCode.notToBe(expected: HttpStatusCode): HttpStatusCode {
@Suppress("MagicNumber")
if (expected.value <= 5) {
return statusAssertion(this.value / 100 != expected.value, expected)
}
return statusAssertion(this != expected, expected)
}

public infix fun HttpStatusCode.notToBeExactly(expected: HttpStatusCode): HttpStatusCode {
@Suppress("MagicNumber")
if (expected.value <= 5) {
return statusAssertion(this.value / 100 != expected.value || this.description != expected.description, expected)
}
return statusAssertion(this.value != expected.value || this.description != expected.description, expected)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package it.skrape.matchers

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.datatest.withData
import io.kotest.matchers.shouldBe
import io.ktor.http.*

class ContentTypeHeaderMatchersKtTest : FunSpec({

val contentTypeWildcards = mapOf(
ContentType.Application.Any to listOf(ContentType.Application.Json, ContentType.Application.GZip),
ContentType.Audio.Any to listOf(ContentType.Audio.MP4, ContentType.Audio.OGG)
).flatMap { entry -> entry.value.map { entry.key to it } }

withData(
nameFn = { "can match partial wildcard type ${it.first} to ${it.second} " },
contentTypeWildcards
) { contentType ->
contentType.first toMatch contentType.second
ContentType.Any toMatch contentType.second
}

test("does not match on null") {
null notToBe ContentType.Any
ContentType.Any notToBe null
}

test("will not match nulls") {
shouldThrow<AssertionError> {
null toBeExactly ContentType.Any
}
shouldThrow<AssertionError> {
null toMatch ContentType.Any
}
shouldThrow<AssertionError> {
ContentType.Any toBeExactly null
}
shouldThrow<AssertionError> {
ContentType.Any toMatch null
}
}

})
Loading