|
3 | 3 | import test from "ava";
|
4 | 4 | import webpack from "webpack";
|
5 | 5 | import path from "path";
|
6 |
| -import fs from "fs"; |
7 |
| -import marked from "marked"; |
8 | 6 | import markdownOptions from "./markdown-options";
|
9 | 7 |
|
10 |
| -test.cb(t => { |
11 |
| - webpack({ |
12 |
| - entry: path.resolve(__dirname, "./assets/markdown.md"), |
13 |
| - mode: "development", |
14 |
| - module: { |
15 |
| - rules: [{ |
16 |
| - test: /\.md$/, |
17 |
| - use: [ |
18 |
| - { |
19 |
| - loader: "html-loader" |
20 |
| - }, |
21 |
| - { |
22 |
| - loader: require.resolve("../index.js"), |
23 |
| - options: markdownOptions |
24 |
| - } |
25 |
| - ] |
26 |
| - }] |
27 |
| - }, |
28 |
| - output: { |
29 |
| - libraryTarget: "commonjs2", |
30 |
| - path: __dirname + "/output", |
31 |
| - filename: "bundle.js" |
32 |
| - } |
33 |
| - }, function onCompilationFinished(err, stats) { |
34 |
| - if (err) { |
35 |
| - return t.end(err); |
36 |
| - } |
37 |
| - if (stats.hasErrors()) { |
38 |
| - return t.end(stats.compilation.errors[0]); |
39 |
| - } |
40 |
| - if (stats.hasWarnings()) { |
41 |
| - return t.end(stats.compilation.warnings[0]); |
42 |
| - } |
| 8 | +function createBundle(markdownFile, bundleName) { |
| 9 | + return new Promise((resolve, reject) => { |
| 10 | + webpack({ |
| 11 | + entry: path.resolve(__dirname, markdownFile), |
| 12 | + mode: "development", |
| 13 | + module: { |
| 14 | + rules: [{ |
| 15 | + test: /\.md$/, |
| 16 | + use: [ |
| 17 | + { |
| 18 | + loader: "html-loader" |
| 19 | + }, |
| 20 | + { |
| 21 | + loader: require.resolve("../index.js"), |
| 22 | + options: markdownOptions |
| 23 | + } |
| 24 | + ] |
| 25 | + }] |
| 26 | + }, |
| 27 | + output: { |
| 28 | + libraryTarget: "commonjs2", |
| 29 | + path: __dirname + "/output", |
| 30 | + filename: bundleName |
| 31 | + } |
| 32 | + }, function onCompilationFinished(err, stats) { |
| 33 | + if (err) { |
| 34 | + return reject(err); |
| 35 | + } |
| 36 | + if (stats.hasErrors()) { |
| 37 | + return reject(stats.compilation.errors[0]); |
| 38 | + } |
| 39 | + if (stats.hasWarnings()) { |
| 40 | + return reject(stats.compilation.warnings[0]); |
| 41 | + } |
| 42 | + |
| 43 | + resolve(require(`./output/${bundleName}`)); |
| 44 | + }); |
| 45 | + }); |
| 46 | +} |
43 | 47 |
|
44 |
| - const bundle = require("./output/bundle"); |
45 |
| - t.is(bundle, '<h1 id=\"heading-1\">heading 1</h1>\n<ul>\n<li>buy pineapple</li>\n</ul>\n<h2 id=\"heading-2\">heading 2</h2>\n<p><em>italic</em> is the new <strong>bold</strong></p>\n<pre><code class=\"language-javascript\"><span class=\"hljs-attribute\">const i</span> = 100;</code></pre>\n<table>\n<thead>\n<tr>\n<th>name</th>\n<th>type</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>key</td>\n<td><code>string|number</code></td>\n</tr>\n</tbody></table>\n'); |
| 48 | +test("plain markdown", async (t) => { |
| 49 | + t.plan(1); |
| 50 | + const bundle = await createBundle("./assets/simple-markdown.md", "simpleMarkdown.js"); |
| 51 | + t.snapshot(bundle); |
| 52 | +}); |
46 | 53 |
|
47 |
| - t.end(); |
48 |
| - }); |
| 54 | +test("with code", async (t) => { |
| 55 | + t.plan(1); |
| 56 | + const bundle = await createBundle("./assets/with-code.md", "withCode.js"); |
| 57 | + t.snapshot(bundle); |
49 | 58 | });
|
50 | 59 |
|
51 | 60 |
|
0 commit comments