Skip to content

Commit

Permalink
update happy-dom. unregister fake window after using.
Browse files Browse the repository at this point in the history
Also fix js platformBeforeEach to only launch MainScope collectors the first time
  • Loading branch information
luca992 committed Oct 10, 2022
1 parent fbe89ef commit 68ad456
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
18 changes: 9 additions & 9 deletions kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,12 @@
"@ethersproject/properties" "^5.7.0"
"@ethersproject/strings" "^5.7.0"

"@happy-dom/global-registrator@^7.5.1":
version "7.5.1"
resolved "https://registry.yarnpkg.com/@happy-dom/global-registrator/-/global-registrator-7.5.1.tgz#a453921d38e23d7af87e64b49328b5aaaf287e7c"
integrity sha512-YUlNpUzSqlnOeDc79iF9errV7wxDkqHkzmywPs7RUvglsYnc8xRQykb3RYchLyDzAqDOAONIilgBXwZ7Hde5EA==
"@happy-dom/global-registrator@^7.5.2":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@happy-dom/global-registrator/-/global-registrator-7.5.5.tgz#0a34b13c563944ea23fc71bdc3fe4b5a9c1b66e7"
integrity sha512-+kkR8wrL3HcU+1Z+M13dMo+a/L701n2DLHHGGlf99GRBcud0Eet4C+t16cZ91a4qbwtt7LAoL4e+3HfVQtU+HQ==
dependencies:
happy-dom "^7.5.1"
happy-dom "^7.5.5"

"@improbable-eng/[email protected]":
version "0.15.0"
Expand Down Expand Up @@ -3473,10 +3473,10 @@ handle-thing@^2.0.0:
resolved "https://registry.yarnpkg.com/handle-thing/-/handle-thing-2.0.1.tgz#857f79ce359580c340d43081cc648970d0bb234e"
integrity sha512-9Qn4yBxelxoh2Ow62nP+Ka/kMnOXRi8BXnRaUwezLNhqelnN49xKz4F/dPP8OYLxLxq6JDtZb2i9XznUQbNPTg==

happy-dom@^7.5.1:
version "7.5.1"
resolved "https://registry.yarnpkg.com/happy-dom/-/happy-dom-7.5.1.tgz#0e1cd3c48bd4a1a876fb836cfe7457b46160d688"
integrity sha512-Y+wwUjRJY/9+uEMKiGwxomO7K4LeCxr/ZpD2PS2LCgRIO1MeyrcQxE5h3TmvESAHnvgpUSJ/1r75tX7Wv7FIyw==
happy-dom@^7.5.5:
version "7.5.5"
resolved "https://registry.yarnpkg.com/happy-dom/-/happy-dom-7.5.5.tgz#ec0aa205610cc316190bc2d04b3d338149859289"
integrity sha512-VOIZRL7RmNUfz0xbY9XZIjKpmfnQ5evfZ/5YQ3O3KsyndLo2ighZgxqkW72vJU2qhtX1K3J3+2A36REPHW5amA==
dependencies:
css.escape "^1.5.1"
he "^1.2.0"
Expand Down
2 changes: 1 addition & 1 deletion secretk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ kotlin {
dependencies {
implementation(libs.com.squareup.okio.nodefilesystem)
implementation(devNpm("@peculiar/webcrypto", "^1.4.0"))
implementation(devNpm("@happy-dom/global-registrator", "^7.5.1"))
implementation(devNpm("@happy-dom/global-registrator", "^7.5.2"))
}
}
val nativeMain by creating {
Expand Down
16 changes: 6 additions & 10 deletions secretk/src/jsMain/kotlin/io/eqoty/secretk/crypto/AesSIV.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ actual class AesSIV {
*/
suspend fun awaitFakeWindow() {
windowIsSetup.onSubscription {
println("onSubscription")
createWindowBroadcaster.emit(Unit)
}.filter { it }.take(1).first()
}

suspend fun awaitDestroyFakeWindow() {
windowIsSetup.onSubscription {
println("onSubscription")
destroyWindowBroadcaster.emit(Unit)
}.filter { !it }.take(1).first()
}
Expand All @@ -52,10 +50,9 @@ actual class AesSIV {
val key = SIV.importKey(txEncryptionKey.toUInt8Array(), "AES-SIV").await()
val ciphertext =
key.seal(plaintext.toUInt8Array(), arrayOf(associatedData.toUInt8Array())).await().toUByteArray()
// TODO: unregister https://github.com/capricorn86/happy-dom/pull/604
// if (initiallyHadNoWindow) {
// awaitDestroyFakeWindow()
// }
if (initiallyHadNoWindow) {
awaitDestroyFakeWindow()
}
return ciphertext
}

Expand All @@ -70,10 +67,9 @@ actual class AesSIV {
val key = SIV.importKey(txEncryptionKey.toUInt8Array(), "AES-SIV").await()
val plaintext =
key.open(ciphertext.toUInt8Array(), arrayOf(associatedData.toUInt8Array())).await().toUByteArray()
// TODO: unregister https://github.com/capricorn86/happy-dom/pull/604
// if (initiallyHadNoWindow) {
// awaitDestroyFakeWindow()
// }
if (initiallyHadNoWindow) {
awaitDestroyFakeWindow()
}
return plaintext
}
}
5 changes: 4 additions & 1 deletion secretk/src/jsTest/kotlin/io/eqoty/platformTestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ fun destroyFakeWindow() {
}


var isFirstRunAndNoWindow = !windowIsSetup.value

actual suspend fun platformBeforeEach() {
if (!windowIsSetup.value) {
if (isFirstRunAndNoWindow) {
isFirstRunAndNoWindow = false
MainScope().launch {
createWindowBroadcaster.collect {
setupFakeWindow()
Expand Down

0 comments on commit 68ad456

Please sign in to comment.