Skip to content

Commit

Permalink
Add notFoundPage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhildenbiddle committed Nov 16, 2023
1 parent cad4a95 commit 135bbee
Showing 1 changed file with 131 additions and 49 deletions.
180 changes: 131 additions & 49 deletions test/e2e/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,146 @@ import docsifyInit from '../helpers/docsify-init.js';
import { test, expect } from './fixtures/docsify-init-fixture.js';

test.describe('Configuration options', () => {
test('catchPluginErrors:true (handles uncaught errors)', async ({ page }) => {
let consoleMsg, errorMsg;

page.on('console', msg => (consoleMsg = msg.text()));
page.on('pageerror', err => (errorMsg = err.message));

await docsifyInit({
config: {
catchPluginErrors: true,
plugins: [
function (hook, vm) {
hook.init(function () {
fail();
});
hook.beforeEach(markdown => {
return `${markdown}\n\nbeforeEach`;
});
},
],
},
markdown: {
homepage: '# Hello World',
},
// _logHTML: true,
test.describe('catchPluginErrors', () => {
test('true (handles uncaught errors)', async ({ page }) => {
let consoleMsg, errorMsg;

page.on('console', msg => (consoleMsg = msg.text()));
page.on('pageerror', err => (errorMsg = err.message));

await docsifyInit({
config: {
catchPluginErrors: true,
plugins: [
function (hook, vm) {
hook.init(function () {
fail();
});
hook.beforeEach(markdown => {
return `${markdown}\n\nbeforeEach`;
});
},
],
},
markdown: {
homepage: '# Hello World',
},
// _logHTML: true,
});

const mainElm = page.locator('#main');

expect(errorMsg).toBeUndefined();
expect(consoleMsg).toContain('Docsify plugin error');
await expect(mainElm).toContainText('Hello World');
await expect(mainElm).toContainText('beforeEach');
});

const mainElm = page.locator('#main');
test('false (throws uncaught errors)', async ({ page }) => {
let consoleMsg, errorMsg;

page.on('console', msg => (consoleMsg = msg.text()));
page.on('pageerror', err => (errorMsg = err.message));

expect(errorMsg).toBeUndefined();
expect(consoleMsg).toContain('Docsify plugin error');
await expect(mainElm).toContainText('Hello World');
await expect(mainElm).toContainText('beforeEach');
await docsifyInit({
config: {
catchPluginErrors: false,
plugins: [
function (hook, vm) {
hook.ready(function () {
fail();
});
},
],
},
markdown: {
homepage: '# Hello World',
},
// _logHTML: true,
});

expect(consoleMsg).toBeUndefined();
expect(errorMsg).toContain('fail');
});
});

test('catchPluginErrors:false (throws uncaught errors)', async ({ page }) => {
let consoleMsg, errorMsg;
test.describe('notFoundPage', () => {
test.describe('renders default error content', () => {
test.beforeEach(async ({ page }) => {
await page.route('README.md', async route => {
await route.fulfill({
status: 500,
});
});
});

test('false', async ({ page }) => {
await docsifyInit({
config: {
notFoundPage: false,
},
});

page.on('console', msg => (consoleMsg = msg.text()));
page.on('pageerror', err => (errorMsg = err.message));
await expect(page.locator('#main')).toContainText('500');
});

await docsifyInit({
config: {
catchPluginErrors: false,
plugins: [
function (hook, vm) {
hook.ready(function () {
fail();
});
test('true with non-404 error', async ({ page }) => {
await docsifyInit({
config: {
notFoundPage: true,
},
routes: {
'_404.md': '',
},
],
},
markdown: {
homepage: '# Hello World',
},
// _logHTML: true,
});

await expect(page.locator('#main')).toContainText('500');
});

test('string with non-404 error', async ({ page }) => {
await docsifyInit({
config: {
notFoundPage: '404.md',
},
routes: {
'404.md': '',
},
});

await expect(page.locator('#main')).toContainText('500');
});
});

expect(consoleMsg).toBeUndefined();
expect(errorMsg).toContain('fail');
test('true: renders _404.md page', async ({ page }) => {
const expectText = 'Pass';

await docsifyInit({
config: {
notFoundPage: true,
},
routes: {
'_404.md': expectText,
},
});

await page.evaluate(() => (window.location.hash = '#/fail'));
await expect(page.locator('#main')).toContainText(expectText);
});

test('string: renders specified 404 page', async ({ page }) => {
const expectText = 'Pass';

await docsifyInit({
config: {
notFoundPage: '404.md',
},
routes: {
'404.md': expectText,
},
});

await page.evaluate(() => (window.location.hash = '#/fail'));
await expect(page.locator('#main')).toContainText(expectText);
});
});
});

0 comments on commit 135bbee

Please sign in to comment.