-
Notifications
You must be signed in to change notification settings - Fork 1
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 #4 from monsat/vitest
vitest
- Loading branch information
Showing
9 changed files
with
430 additions
and
4 deletions.
There are no files selected for viewing
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,24 @@ | ||
import { fileURLToPath } from 'url' | ||
import { describe, test, expect } from 'vitest' | ||
import { setup, createPage } from '@nuxt/test-utils-edge' | ||
import BasicAuth from '../src/module' | ||
|
||
describe('Basic test: with module options { enabled: false }', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)), | ||
browser: true, | ||
nuxtConfig: { | ||
modules: [ | ||
[BasicAuth, { enabled: false }], | ||
], | ||
}, | ||
}) | ||
|
||
test('allow if enabled option is false', async () => { | ||
const page = await createPage('/') | ||
|
||
const selector = await page.locator('div', { hasText: 'Nuxt Basic Auth Module' }) | ||
const count = await selector.count() | ||
expect(count).not.toBe(0) | ||
}) | ||
}) |
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,36 @@ | ||
import { fileURLToPath } from 'url' | ||
import { describe, test, expect } from 'vitest' | ||
import { setup, createPage } from '@nuxt/test-utils-edge' | ||
import BasicAuth from '../src/module' | ||
|
||
describe('Basic test: with module options', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)), | ||
browser: true, | ||
nuxtConfig: { | ||
modules: [ | ||
[BasicAuth, { enabled: true }], | ||
], | ||
}, | ||
}) | ||
|
||
test('access denied without http credentials', async () => { | ||
const page = await createPage('/') | ||
|
||
const selector = await page.locator('div', { hasText: 'Nuxt Basic Auth Module' }) | ||
const count = await selector.count() | ||
expect(count).toBe(0) | ||
}) | ||
test('allow with http credentials', async () => { | ||
const page = await createPage('/', { | ||
httpCredentials: { | ||
username: 'admin', | ||
password: 'admin', | ||
}, | ||
}) | ||
|
||
const selector = await page.locator('div', { hasText: 'Nuxt Basic Auth Module' }) | ||
const count = await selector.count() | ||
expect(count).not.toBe(0) | ||
}) | ||
}) |
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,63 @@ | ||
import { fileURLToPath } from 'url' | ||
import { describe, test, expect } from 'vitest' | ||
import { setup, createPage } from '@nuxt/test-utils-edge' | ||
import BasicAuth from '../src/module' | ||
|
||
describe('RuntimeConfig test: pairs', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)), | ||
browser: true, | ||
nuxtConfig: { | ||
modules: [ | ||
[BasicAuth, { enabled: true }], | ||
], | ||
runtimeConfig: { | ||
basicAuth: { | ||
pairs: { | ||
foo: 'bar', | ||
baz: 'baz', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
test('allow with http credentials', async () => { | ||
const page = await createPage('/', { | ||
httpCredentials: { | ||
username: 'foo', | ||
password: 'bar', | ||
}, | ||
}) | ||
|
||
const selector = await page.locator('div', { hasText: 'Nuxt Basic Auth Module' }) | ||
const count = await selector.count() | ||
expect(count).not.toBe(0) | ||
}) | ||
|
||
test('allow with right pair', async () => { | ||
const page = await createPage('/', { | ||
httpCredentials: { | ||
username: 'baz', | ||
password: 'baz', | ||
}, | ||
}) | ||
|
||
const selector = await page.locator('div', { hasText: 'Nuxt Basic Auth Module' }) | ||
const count = await selector.count() | ||
expect(count).not.toBe(0) | ||
}) | ||
|
||
test('access denied with wrong pair', async () => { | ||
const page = await createPage('/', { | ||
httpCredentials: { | ||
username: 'wrong', | ||
password: 'pair', | ||
}, | ||
}) | ||
|
||
const selector = await page.locator('div', { hasText: 'Nuxt Basic Auth Module' }) | ||
const count = await selector.count() | ||
expect(count).toBe(0) | ||
}) | ||
}) |
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,36 @@ | ||
import { fileURLToPath } from 'url' | ||
import { describe, test, expect } from 'vitest' | ||
import { setup, createPage } from '@nuxt/test-utils-edge' | ||
import BasicAuth from '../src/module' | ||
|
||
describe('Basic test: without module options', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)), | ||
browser: true, | ||
nuxtConfig: { | ||
modules: [ | ||
BasicAuth, | ||
], | ||
}, | ||
}) | ||
|
||
test('access denied without http credentials', async () => { | ||
const page = await createPage('/') | ||
|
||
const selector = await page.locator('div', { hasText: 'Nuxt Basic Auth Module' }) | ||
const count = await selector.count() | ||
expect(count).toBe(0) | ||
}) | ||
test('allow with http credentials', async () => { | ||
const page = await createPage('/', { | ||
httpCredentials: { | ||
username: 'admin', | ||
password: 'admin', | ||
}, | ||
}) | ||
|
||
const selector = await page.locator('div', { hasText: 'Nuxt Basic Auth Module' }) | ||
const count = await selector.count() | ||
expect(count).not.toBe(0) | ||
}) | ||
}) |
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,8 @@ | ||
<template> | ||
<div> | ||
Nuxt Basic Auth Module playground! | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
</script> |
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,4 @@ | ||
import { defineNuxtConfig } from 'nuxt' | ||
|
||
export default defineNuxtConfig({ | ||
}) |
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,11 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
test: { | ||
testTimeout: 300000, | ||
deps: { | ||
inline: [/@nuxt\/test-utils-edge/] | ||
}, | ||
}, | ||
}) |
Oops, something went wrong.