Skip to content

Commit 876728b

Browse files
committed
test: fix vitests by running them in real browser to workaround Node.JS limitations
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 579679b commit 876728b

10 files changed

Lines changed: 224 additions & 159 deletions

File tree

.github/workflows/node-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ jobs:
5151
CYPRESS_INSTALL_BINARY: 0
5252
run: |
5353
npm ci
54+
# Install browsers for tests
55+
npm npx playwright install chromium
5456
npm run build --if-present
5557
5658
- name: Test

REUSE.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-PackageSupplier = "Nextcloud GmbH <https://nextcloud.com/impressum/>"
66
SPDX-PackageDownloadLocation = "https://github.com/nextcloud-libraries/nextcloud-auth"
77

88
[[annotations]]
9-
path = ["package.json", "package-lock.json", "tsconfig.json"]
9+
path = ["package.json", "package-lock.json", "tsconfig.json", "test/tsconfig.json"]
1010
precedence = "aggregate"
1111
SPDX-FileCopyrightText = "2019 Nextcloud GmbH and Nextcloud contributors"
1212
SPDX-License-Identifier = "GPL-3.0-or-later"

lib/guest.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ export function setGuestNickname(nickname: string): void {
7474
getGuestUser().displayName = nickname
7575
}
7676

77+
/**
78+
* Reset the guest user state.
79+
*
80+
* @internal
81+
*/
82+
export function resetGuestUser(): void {
83+
currentUser = undefined
84+
browserStorage.removeItem('guestUid')
85+
browserStorage.removeItem('guestNickname')
86+
}
87+
7788
/**
7889
* Generate a random UUID (version 4) if the crypto API is not available.
7990
* If the crypto API is available, it uses the less secure `randomUUID` method.

package-lock.json

Lines changed: 157 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
"@nextcloud/eslint-config": "^9.0.0-rc.9",
4444
"@nextcloud/typings": "^1.10.0",
4545
"@nextcloud/vite-config": "^2.5.2",
46+
"@vitest/browser-playwright": "^4.1.4",
4647
"@vitest/coverage-v8": "^4.1.4",
4748
"eslint": "^10.2.0",
48-
"happy-dom": "^20.8.9",
4949
"msw": "^2.13.2",
5050
"typedoc": "^0.28.18",
5151
"typescript": "^6.0.2",

test/csp-nonce.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: GPL-3.0-or-later
44
*/
5-
import { randomBytes } from 'crypto'
5+
66
import { beforeEach, describe, expect, test, vi } from 'vitest'
77

88
/**
99
* Mock `<meta>` element with nonce
1010
*/
1111
function mockNonce() {
12-
const nonce = randomBytes(16).toString('base64')
12+
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16))
13+
const nonce = bytes.toBase64()
1314
const el = document.createElement('meta')
1415
el.name = 'csp-nonce'
1516
el.nonce = nonce

0 commit comments

Comments
 (0)