marp-dev-preview 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marp-dev-preview",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "A CLI tool to preview Marp markdown files.",
5
5
  "main": "src/marp-dev-preview.mjs",
6
6
  "type": "module",
@@ -168,7 +168,7 @@ if (themeSet) {
168
168
  }
169
169
 
170
170
  initializeMarp(themeSet, containers).then(() => {
171
- const app = createServer(markdownDir, renderMarp, reload, wss, __dirname);
171
+ const app = createServer(markdownDir, themeSet ?? [], renderMarp, reload, wss, __dirname);
172
172
  const server = http.createServer(app);
173
173
 
174
174
  server.on('upgrade', (request, socket, head) => {
@@ -13,7 +13,7 @@ export function getMarp() {
13
13
  }
14
14
 
15
15
 
16
- export async function initializeMarp(themeSet, containers) {
16
+ export async function initializeMarp(themeSet, containers = []) {
17
17
  const options = { html: true, linkify: true, };
18
18
  marp = new Marp(options)
19
19
  .use(markdownItFootnote)
package/src/server.mjs CHANGED
@@ -2,9 +2,12 @@ import express from 'express';
2
2
  import path from 'path';
3
3
  import { promises as fs } from 'fs';
4
4
 
5
- export function createServer(markdownDir, renderMarp, reload, wss, __dirname) {
5
+ export function createServer(markdownDir, themeDirs, renderMarp, reload, wss, __dirname) {
6
6
  const app = express();
7
7
 
8
+ for (const themeDir of themeDirs) {
9
+ app.use(express.static(themeDir));
10
+ }
8
11
  app.use(express.static(markdownDir));
9
12
  app.use(express.text({ type: 'text/markdown' }));
10
13
  app.use(express.json());
@@ -3,20 +3,41 @@
3
3
  // This is necessary because jest has issues with importing express, which is a CJS module,
4
4
  // in a project that uses ES modules ("type": "module" in package.json).
5
5
  import { createServer } from '../src/server.mjs';
6
+ import express from 'express';
6
7
 
7
8
  describe('Server', () => {
9
+ beforeEach(() => {
10
+ express.static.mockClear();
11
+ });
12
+
8
13
  it('should create a server', () => {
9
14
  const markdownDir = '.';
15
+ const themeDirs = [];
10
16
  const renderMarp = jest.fn();
11
17
  const reload = jest.fn();
12
18
  const wss = { clients: [] };
13
19
  const __dirname = '.';
14
20
 
15
- const app = createServer(markdownDir, renderMarp, reload, wss, __dirname);
21
+ const app = createServer(markdownDir, themeDirs, renderMarp, reload, wss, __dirname);
16
22
 
17
23
  expect(app).toBeDefined();
18
24
  expect(typeof app.use).toBe('function');
19
25
  expect(typeof app.get).toBe('function');
20
26
  expect(typeof app.post).toBe('function');
21
27
  });
28
+
29
+ it('should mount theme directories before the markdown directory', () => {
30
+ const markdownDir = '/slides';
31
+ const themeDirs = ['/themes/a', '/themes/b'];
32
+ const renderMarp = jest.fn();
33
+ const reload = jest.fn();
34
+ const wss = { clients: [] };
35
+ const __dirname = '.';
36
+
37
+ createServer(markdownDir, themeDirs, renderMarp, reload, wss, __dirname);
38
+
39
+ expect(express.static).toHaveBeenNthCalledWith(1, '/themes/a');
40
+ expect(express.static).toHaveBeenNthCalledWith(2, '/themes/b');
41
+ expect(express.static).toHaveBeenNthCalledWith(3, '/slides');
42
+ });
22
43
  });