feat(v2): pluginify pages (#1278)

* feat(v2): convert pages into a plugin

* fix: update tests
This commit is contained in:
Yangshun Tay 2019-03-13 13:08:12 -07:00 committed by GitHub
parent 2da59ed4af
commit 398d7c7ae4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 287 additions and 257 deletions

View file

@ -34,6 +34,11 @@ Object {
},
],
"organizationName": "endiliey",
"plugins": Array [
Object {
"name": "docusaurus-plugin-content-pages",
},
],
"projectName": "hello",
"tagline": "Hello World",
"title": "Hello",

View file

@ -1,123 +0,0 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import loadPages from '@lib/load/pages';
import path from 'path';
import loadSetup from '../loadSetup';
describe('loadPages', () => {
test('simple website', async () => {
const {pagesDir, env, siteConfig} = await loadSetup('simple');
const pagesMetadatas = await loadPages({pagesDir, env, siteConfig});
expect(pagesMetadatas).toEqual([
{
permalink: '/',
source: path.join(pagesDir, 'index.js'),
},
{
permalink: '/hello/world',
source: path.join(pagesDir, 'hello', 'world.js'),
},
]);
});
test('versioned website', async () => {
const {pagesDir, env, siteConfig} = await loadSetup('versioned');
const pagesMetadatas = await loadPages({pagesDir, env, siteConfig});
expect(pagesMetadatas).toEqual([
{
permalink: '/',
source: path.join(pagesDir, 'index.js'),
},
{
permalink: '/hello/world',
source: path.join(pagesDir, 'hello', 'world.js'),
},
]);
});
test('versioned & translated website', async () => {
const {pagesDir, env, siteConfig} = await loadSetup('transversioned');
const pagesMetadatas = await loadPages({pagesDir, env, siteConfig});
expect(pagesMetadatas).toEqual([
{
language: 'en',
permalink: '/',
source: path.join(pagesDir, 'index.js'),
},
{
language: 'en',
permalink: '/en/',
source: path.join(pagesDir, 'index.js'),
},
{
language: 'ko',
permalink: '/ko/',
source: path.join(pagesDir, 'index.js'),
},
{
language: 'en',
permalink: '/hello/world',
source: path.join(pagesDir, 'hello', 'world.js'),
},
{
language: 'en',
permalink: '/en/hello/world',
source: path.join(pagesDir, 'hello', 'world.js'),
},
{
language: 'ko',
permalink: '/ko/hello/world',
source: path.join(pagesDir, 'hello', 'world.js'),
},
]);
});
test('translated website', async () => {
const {pagesDir, env, siteConfig} = await loadSetup('translated');
const pagesMetadatas = await loadPages({pagesDir, env, siteConfig});
expect(pagesMetadatas).toEqual([
{
language: 'en',
permalink: '/',
source: path.join(pagesDir, 'index.js'),
},
{
language: 'en',
permalink: '/en/',
source: path.join(pagesDir, 'index.js'),
},
{
language: 'ko',
permalink: '/ko/',
source: path.join(pagesDir, 'index.js'),
},
{
language: 'en',
permalink: '/hello/world',
source: path.join(pagesDir, 'hello', 'world.js'),
},
{
language: 'en',
permalink: '/en/hello/world',
source: path.join(pagesDir, 'hello', 'world.js'),
},
{
language: 'ko',
permalink: '/ko/hello/world',
source: path.join(pagesDir, 'hello', 'world.js'),
},
]);
});
test('invalid pages', async () => {
const {env, siteConfig} = await loadSetup('simple');
const pagesDir = path.join(__dirname, '__fixtures__', 'nonExisting');
const pagesMetadatas = await loadPages({pagesDir, env, siteConfig});
expect(pagesMetadatas).toEqual([]);
});
});

View file

@ -5,13 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/
import loadRoutes from '@lib/load/routes';
import loadSetup from '../loadSetup';
describe('loadRoutes', () => {
test('simple website', async () => {
const props = await loadSetup('simple');
const {routesPaths} = await loadRoutes(props);
const {routesPaths} = await loadSetup('simple');
expect(routesPaths.length).toBeGreaterThan(0);
expect(routesPaths.sort()).toMatchInlineSnapshot(`
Array [
@ -26,8 +24,7 @@ Array [
});
test('versioned website', async () => {
const props = await loadSetup('versioned');
const {routesPaths} = await loadRoutes(props);
const {routesPaths} = await loadSetup('versioned');
expect(routesPaths.length).toBeGreaterThan(0);
expect(routesPaths.sort()).toMatchInlineSnapshot(`
Array [
@ -48,8 +45,7 @@ Array [
});
test('versioned & translated website', async () => {
const props = await loadSetup('transversioned');
const {routesPaths} = await loadRoutes(props);
const {routesPaths} = await loadSetup('transversioned');
expect(routesPaths.length).toBeGreaterThan(0);
expect(routesPaths.sort()).toMatchInlineSnapshot(`
Array [
@ -83,8 +79,7 @@ Array [
});
test('translated website', async () => {
const props = await loadSetup('translated');
const {routesPaths} = await loadRoutes(props);
const {routesPaths} = await loadSetup('translated');
expect(routesPaths.length).toBeGreaterThan(0);
expect(routesPaths.sort()).toMatchInlineSnapshot(`
Array [