Skip to content

Commit

Permalink
Merge pull request #631 from nextcloud-libraries/feat/vite
Browse files Browse the repository at this point in the history
feat: Use vite for transpiling and vitest for testing
  • Loading branch information
susnux authored Apr 22, 2024
2 parents ee2db24 + 73a8737 commit 58d5a93
Show file tree
Hide file tree
Showing 9 changed files with 3,873 additions and 8,406 deletions.
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

12,105 changes: 3,790 additions & 8,315 deletions package-lock.json

Large diffs are not rendered by default.

33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
"name": "@nextcloud/auth",
"version": "2.2.1",
"description": "Nextcloud helpers related to authentication and the current user",
"main": "dist/index.js",
"type": "module",
"main": "dist/index.cjs",
"types": "dist/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.es.mjs",
"require": "./dist/index.js"
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"files": [
"dist/"
],
"scripts": {
"build": "rollup --config rollup.config.mjs",
"build": "vite --mode production build",
"build:doc": "typedoc --out dist/doc lib/index.ts && touch dist/doc/.nojekyll",
"check-types": "tsc --noEmit",
"dev": "rollup --config rollup.config.mjs --watch",
"lint": "eslint lib *js",
"lint:fix": "eslint --fix lib",
"test": "jest",
"test:watch": "jest --watchAll"
"dev": "vite --mode development run --watch",
"lint": "eslint lib test *.ts",
"lint:fix": "eslint --fix lib test",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:watch": "vitest watch"
},
"keywords": [
"nextcloud"
Expand All @@ -38,14 +39,14 @@
"devDependencies": {
"@nextcloud/eslint-config": "^8.3.0",
"@nextcloud/typings": "^1.8.0",
"@rollup/plugin-typescript": "^11.1.6",
"@nextcloud/vite-config": "^1.2.2",
"@vitest/coverage-v8": "^1.5.0",
"eslint": "^8.57.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"rollup": "^4.16.0",
"tslib": "^2.6.2",
"happy-dom": "^14.7.1",
"typedoc": "^0.25.13",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"vite": "^5.2.10",
"vitest": "^1.5.0"
},
"engines": {
"node": "^20.0.0",
Expand Down
35 changes: 0 additions & 35 deletions rollup.config.mjs

This file was deleted.

36 changes: 0 additions & 36 deletions test/request-token.test.js

This file was deleted.

35 changes: 35 additions & 0 deletions test/request-token.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { emit } from '@nextcloud/event-bus'
import { beforeEach, describe, expect, test, vi } from 'vitest'

import { getRequestToken, onRequestTokenUpdate } from '../lib/index'

describe('request token', () => {
beforeEach(() => {
emit('csrf-token-update', {
token: undefined,
})
})

test('updates token via event', () => {
expect(getRequestToken()).toBe(null)
})

test('find correct value', () => {
emit('csrf-token-update', {
token: 'token123',
})

expect(getRequestToken()).toBe('token123')
})

test('request token observer is called', () => {
const observer = vi.fn(() => { })

onRequestTokenUpdate(observer)
emit('csrf-token-update', {
token: 'token123',
})

expect(observer.mock.calls.length).toBe(1)
})
})
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"include": ["./lib/**/*.ts"],
"include": ["./lib/**.ts"],
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"moduleResolution": "Bundler",
"target": "ESNext",
"module": "esnext",
"module": "ESNext",
"declaration": true,
"strict": true,
"noImplicitAny": false,
Expand Down
10 changes: 10 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createLibConfig } from '@nextcloud/vite-config'

export default createLibConfig(
{
index: `${__dirname}/lib/index.ts`,
},
{
libraryFormats: ['cjs', 'es'],
},
)
18 changes: 18 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { UserConfig } from 'vite'
import viteConfig from './vite.config'

export default async (env) => {
const config = typeof viteConfig === 'function' ? await viteConfig(env) : viteConfig
// node-externals conflicts with vitest
config.plugins = config.plugins!.filter((plugin) => plugin && (!('name' in plugin) || plugin?.name !== 'node-externals'))

return {
...config,
test: {
environment: 'happy-dom',
coverage: {
reporter: ['text', 'lcov'],
},
},
} as UserConfig
}

0 comments on commit 58d5a93

Please sign in to comment.