-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #631 from nextcloud-libraries/feat/vite
feat: Use vite for transpiling and vitest for testing
- Loading branch information
Showing
9 changed files
with
3,873 additions
and
8,406 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |