Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- main
- staging
pull_request:
branches:
- main
- staging
workflow_dispatch:

jobs:
Expand All @@ -22,6 +24,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: scripts/setup-ci.sh
- run: npm test
- run: npm run build
- run: npm run doc
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"lint-fix": "eslint --fix",
"typecheck": "tsc --noEmit",
"typecheck-test": "tsc --noEmit -p tsconfig.test.json",
"test": "vitest run",
"test": "npm run typecheck-test && vitest run",
"test-coverage": "vitest run --coverage",
"test-debug": "vitest --inspect-brk --no-file-parallelism",
"doc": "typedoc --out ./docs/api/ ./src/ --excludeInternal",
Expand Down
28 changes: 28 additions & 0 deletions scripts/setup-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail

# Clone, build, and link solid-logic for CI (peer dependency of solid-ui).
# Run after `npm ci` so the local install is not removed.

ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
SOLID_LOGIC_DIR="${ROOT_DIR}/.ci-deps/solid-logic"
SOLID_LOGIC_REPO="https://github.com/SolidOS/solid-logic.git"
SOLID_LOGIC_REF="${GITHUB_BASE_REF:-${GITHUB_REF_NAME:-main}}"

echo ">>>>> Setting up solid-logic from ${SOLID_LOGIC_REPO} (${SOLID_LOGIC_REF})"

rm -rf "$SOLID_LOGIC_DIR"
mkdir -p "$(dirname "$SOLID_LOGIC_DIR")"
git clone --depth 1 --branch "$SOLID_LOGIC_REF" "$SOLID_LOGIC_REPO" "$SOLID_LOGIC_DIR"

echo ">>>>> Installing solid-logic dependencies"
(cd "$SOLID_LOGIC_DIR" && npm ci)

echo ">>>>> Building solid-logic"
(cd "$SOLID_LOGIC_DIR" && npm run build)

echo ">>>>> Installing solid-logic as a local dependency in solid-ui"
cd "$ROOT_DIR"
npm install --no-save "solid-logic@file:${SOLID_LOGIC_DIR}"

echo ">>>>> solid-logic setup complete"
28 changes: 14 additions & 14 deletions test/unit/login/login.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { afterAll, afterEach, describe, expect, it, vi } from 'vitest'
import { authn, authSession, solidLogicSingleton } from 'solid-logic'
import * as testLogin from '../../../src/login/login'

describe('ensureLoggedIn', () => {
Expand All @@ -20,24 +19,25 @@ describe('getUserRoles', () => {
})

it('returns [] and does not load preferences when current user is missing', async () => {
vi.spyOn(authSession, 'info', 'get').mockReturnValue({
vi.resetModules()

const { authn, authSession, solidLogicSingleton } = await import('solid-logic')

authSession.info = {
isLoggedIn: true,
webId: 'https://alice.example.com/profile/card#me',
sessionId: 'test-session'
})
webId: 'https://alice.example.com/profile/card#me'
}

const currentUserSpy = vi
.spyOn(authn, 'currentUser')
.mockReturnValue(null)
const loadPreferencesSpy = vi.spyOn(
solidLogicSingleton.profile,
'loadPreferences'
)
vi.spyOn(authn, 'checkUser').mockResolvedValue(null)

const roles = await testLogin.getUserRoles()
const currentUserSpy = vi.spyOn(authn, 'currentUser').mockReturnValue(null)
const loadPreferencesSpy = vi.spyOn(solidLogicSingleton.profile, 'loadPreferences')

const { getUserRoles } = await import('../../../src/login/login')
const roles = await getUserRoles()

expect(currentUserSpy).toHaveBeenCalled()
expect(roles).toEqual([])
expect(currentUserSpy).toHaveBeenCalled()
expect(loadPreferencesSpy).not.toHaveBeenCalled()
})
})
4 changes: 4 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function defaultConfig(): UserConfig {
test: {
environment: 'jsdom',
setupFiles: ['test/helpers/setup.ts'],
include: [
'src/**/*.test.ts',
'test/**/*.test.ts',
],
coverage: {
include: ['src/**/*.[jt]s'],
},
Expand Down
Loading