'
41 | ) > -1
42 | );
43 | t.truthy(
44 | componentsHtmlTmp.indexOf(
45 | '
'
46 | ) > -1
47 | );
48 | t.end();
49 | }, 1000);
50 | }
51 | })
52 | );
53 | });
54 |
--------------------------------------------------------------------------------
/test/component-html-options/page.md:
--------------------------------------------------------------------------------
1 | this is a page
2 |
--------------------------------------------------------------------------------
/test/component-html-options/test.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const fs = require("fs");
3 | const rimraf = require("rimraf");
4 |
5 | const DM = require("../../lib/index");
6 |
7 | const config = {
8 | output: __dirname + "/tmp/",
9 | pages: __dirname + "/",
10 | components: "./test/components.json",
11 | meta: {
12 | domain: "website.com",
13 | title: "Design Manual"
14 | },
15 | renderComponents: true,
16 | renderCSS: false
17 | };
18 |
19 | test.cb("add head html", t => {
20 | t.plan(1);
21 | rimraf.sync(__dirname + "/tmp/head/");
22 |
23 | DM.build(
24 | Object.assign({}, config, {
25 | output: config.output + "head/",
26 | componentHeadHtml: `
27 |
28 | `,
29 | onLog: () => {},
30 | onComplete: () => {
31 | setTimeout(() => {
32 | const componentsHtmlTmp = fs.readFileSync(
33 | config.output + "head/lib/component1.html",
34 | "utf8"
35 | );
36 | t.truthy(
37 | componentsHtmlTmp.indexOf("") > -1
38 | );
39 | t.end();
40 | }, 1000);
41 | }
42 | })
43 | );
44 | });
45 |
46 | test.cb("add body html", t => {
47 | t.plan(1);
48 | rimraf.sync(__dirname + "/tmp/body/");
49 |
50 | DM.build(
51 | Object.assign({}, config, {
52 | output: config.output + "body/",
53 | componentBodyHtml: `
54 |
55 | `,
56 | onLog: () => {},
57 | onComplete: () => {
58 | setTimeout(() => {
59 | const componentsHtmlTmp = fs.readFileSync(
60 | config.output + "body/lib/component1.html",
61 | "utf8"
62 | );
63 | t.truthy(
64 | componentsHtmlTmp.indexOf("") > -1
65 | );
66 | t.end();
67 | }, 1000);
68 | }
69 | })
70 | );
71 | });
72 |
--------------------------------------------------------------------------------
/test/components.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "meta": {
4 | "name": "component1",
5 | "description": "
this is component 1
"
6 | },
7 | "file": "path/to/component1.html",
8 | "output": "
this is component 1
"
9 | },
10 | {
11 | "meta": {
12 | "name": "component2",
13 | "description": "
this is component 2
"
14 | },
15 | "file": "path/to/component2.html",
16 | "output": "
this is component 2
"
17 | },
18 | {
19 | "meta": {
20 | "name": "component3",
21 | "description": "
this is component 3
"
22 | },
23 | "file": "path/to/component3.html",
24 | "output": "
this is component 3
"
25 | }
26 | ]
27 |
--------------------------------------------------------------------------------
/test/components2.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "meta": {
4 | "name": "component1",
5 | "description": "
this is component 1 changed
"
6 | },
7 | "file": "path/to/component1.html",
8 | "output": "
this is component 1
"
9 | },
10 | {
11 | "meta": {
12 | "name": "component2",
13 | "description": "
this is component 2
"
14 | },
15 | "file": "path/to/component2.html",
16 | "output": "
this is component 2
"
17 | },
18 | {
19 | "meta": {
20 | "name": "component3",
21 | "description": "
this is component 3
"
22 | },
23 | "file": "path/to/component3.html",
24 | "output": "
this is component 3
"
25 | }
26 | ]
27 |
--------------------------------------------------------------------------------
/test/config/page.md:
--------------------------------------------------------------------------------
1 | !{component1}
2 |
--------------------------------------------------------------------------------
/test/config/page2.md:
--------------------------------------------------------------------------------
1 | foo
2 |
--------------------------------------------------------------------------------
/test/config/test-body-html.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test body html change
22 | */
23 |
24 | test.cb("config: body html change", t => {
25 | t.plan(1);
26 | rimraf.sync(config.output);
27 |
28 | const expected = `
29 | Starting design manual
30 | Detected changed configuration (body html)
31 | Forcing pages rebuild
32 | Starting components
33 | Found 0 changed components
34 | Generated components
35 | Starting pages
36 | Found 2 changed pages
37 | Generated test/config/tmp/page.html
38 | Generated test/config/tmp/page2.html
39 | Generated pages
40 | Design manual complete
41 | `;
42 | buildAndMatchLogs(null, config, null, () => {
43 | buildAndMatchLogs(
44 | t,
45 | Object.assign(config, { bodyHtml: "" }),
46 | expected
47 | );
48 | });
49 | });
50 |
--------------------------------------------------------------------------------
/test/config/test-component-body-html.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test component body html change
22 | */
23 |
24 | test.cb("config: component body html change", t => {
25 | t.plan(1);
26 | rimraf.sync(config.output);
27 |
28 | const expected = `
29 | Starting design manual
30 | Detected changed configuration (components body html)
31 | Forcing components rebuild
32 | Starting components
33 | Found 3 changed components
34 | Rendering component ./lib/component1.html
35 | Rendering component ./lib/component2.html
36 | Rendering component ./lib/component3.html
37 | Generated components
38 | Starting pages
39 | Found 1 changed page
40 | Generated test/config/tmp/page.html
41 | Generated pages
42 | Design manual complete
43 | `;
44 | buildAndMatchLogs(null, config, null, () => {
45 | buildAndMatchLogs(
46 | t,
47 | Object.assign(config, { componentBodyHtml: "" }),
48 | expected
49 | );
50 | });
51 | });
52 |
--------------------------------------------------------------------------------
/test/config/test-component-head-html.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test component head html change
22 | */
23 |
24 | test.cb("config: component head html change", t => {
25 | t.plan(1);
26 | rimraf.sync(config.output);
27 |
28 | const expected = `
29 | Starting design manual
30 | Detected changed configuration (components head html)
31 | Forcing components rebuild
32 | Starting components
33 | Found 3 changed components
34 | Rendering component ./lib/component1.html
35 | Rendering component ./lib/component2.html
36 | Rendering component ./lib/component3.html
37 | Generated components
38 | Starting pages
39 | Found 1 changed page
40 | Generated test/config/tmp/page.html
41 | Generated pages
42 | Design manual complete
43 | `;
44 |
45 | buildAndMatchLogs(null, config, null, () => {
46 | buildAndMatchLogs(
47 | t,
48 | Object.assign(config, { componentHeadHtml: "" }),
49 | expected
50 | );
51 | });
52 | });
53 |
--------------------------------------------------------------------------------
/test/config/test-component.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test component changes
22 | */
23 |
24 | test.cb("config: component change", t => {
25 | t.plan(1);
26 |
27 | rimraf.sync(__dirname + "/tmp/");
28 |
29 | const expected = `
30 | Starting design manual
31 | Starting components
32 | Found 1 changed component
33 | Rendering component ./lib/component1.html
34 | Generated components
35 | Starting pages
36 | Found 1 changed page
37 | Generated test/config/tmp/page.html
38 | Generated pages
39 | Design manual complete
40 | `;
41 |
42 | buildAndMatchLogs(
43 | null,
44 | Object.assign(config, { components: "./test/components.json" }),
45 | null,
46 | () => {
47 | buildAndMatchLogs(
48 | t,
49 | Object.assign(config, { components: "./test/components2.json" }),
50 | expected
51 | );
52 | }
53 | );
54 | });
55 |
--------------------------------------------------------------------------------
/test/config/test-contentsflag.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test contents flag change
22 | */
23 |
24 | test.cb("config: contents flag change", t => {
25 | t.plan(1);
26 | rimraf.sync(config.output);
27 |
28 | const expected = `
29 | Starting design manual
30 | Detected changed configuration (contents flag)
31 | Forcing pages rebuild
32 | Starting components
33 | Found 0 changed components
34 | Generated components
35 | Starting pages
36 | Found 2 changed pages
37 | Generated test/config/tmp/page.html
38 | Generated test/config/tmp/page2.html
39 | Generated pages
40 | Design manual complete
41 | `;
42 |
43 | buildAndMatchLogs(null, config, null, () => {
44 | buildAndMatchLogs(
45 | t,
46 | Object.assign(config, { contentsFlag: "beep" }),
47 | expected
48 | );
49 | });
50 | });
51 |
--------------------------------------------------------------------------------
/test/config/test-error.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test error in config file
22 | */
23 |
24 | test.cb("config: error in config", t => {
25 | t.plan(1);
26 | rimraf.sync(config.output);
27 |
28 | const expected = `
29 | Starting design manual
30 | Error parsing previous configuration
31 | Forcing components rebuild
32 | Forcing pages rebuild
33 | Starting components
34 | Found 3 changed components
35 | Rendering component ./lib/component1.html
36 | Rendering component ./lib/component2.html
37 | Rendering component ./lib/component3.html
38 | Generated components
39 | Starting pages
40 | Found 2 changed pages
41 | Generated test/config/tmp/page.html
42 | Generated test/config/tmp/page2.html
43 | Generated pages
44 | Design manual complete
45 | `;
46 |
47 | buildAndMatchLogs(null, config, null, () => {
48 | fs.writeFileSync(
49 | path.resolve(config.output, "design-manual-config.json"),
50 | "foo"
51 | );
52 | buildAndMatchLogs(t, config, expected);
53 | });
54 | });
55 |
--------------------------------------------------------------------------------
/test/config/test-head-html.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test head html change
22 | */
23 |
24 | test.cb("config: head html change", t => {
25 | t.plan(1);
26 | rimraf.sync(config.output);
27 |
28 | const expected = `
29 | Starting design manual
30 | Detected changed configuration (head html)
31 | Forcing pages rebuild
32 | Starting components
33 | Found 0 changed components
34 | Generated components
35 | Starting pages
36 | Found 2 changed pages
37 | Generated test/config/tmp/page.html
38 | Generated test/config/tmp/page2.html
39 | Generated pages
40 | Design manual complete
41 | `;
42 |
43 | buildAndMatchLogs(null, config, null, () => {
44 | buildAndMatchLogs(
45 | t,
46 | Object.assign(config, { headHtml: "" }),
47 | expected
48 | );
49 | });
50 | });
51 |
--------------------------------------------------------------------------------
/test/config/test-meta.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test meta change
22 | */
23 |
24 | const expectedMetaChange = `
25 | Starting design manual
26 | Detected changed configuration (meta)
27 | Forcing pages rebuild
28 | Starting components
29 | Found 0 changed components
30 | Generated components
31 | Starting pages
32 | Found 2 changed pages
33 | Generated test/config/tmp/page.html
34 | Generated test/config/tmp/page2.html
35 | Generated pages
36 | Design manual complete
37 | `;
38 |
39 | test.cb("config: meta change", t => {
40 | t.plan(1);
41 | buildAndMatchLogs(null, config, null, () => {
42 | buildAndMatchLogs(
43 | t,
44 | Object.assign(config, {
45 | meta: { domain: "0", title: "0", avatar: "0", version: "0" }
46 | }),
47 | expectedMetaChange
48 | );
49 | });
50 | });
51 |
52 | test.cb("config: meta change (domain)", t => {
53 | t.plan(1);
54 | buildAndMatchLogs(
55 | t,
56 | Object.assign(config, {
57 | meta: { domain: "1", title: "0", avatar: "0", version: "0" }
58 | }),
59 | expectedMetaChange
60 | );
61 | });
62 |
63 | test.cb("config: meta change (title)", t => {
64 | t.plan(1);
65 | buildAndMatchLogs(
66 | t,
67 | Object.assign(config, {
68 | meta: { domain: "1", title: "1", avatar: "0", version: "0" }
69 | }),
70 | expectedMetaChange
71 | );
72 | });
73 |
74 | test.cb("config: meta change (avatar)", t => {
75 | t.plan(1);
76 | buildAndMatchLogs(
77 | t,
78 | Object.assign(config, {
79 | meta: { domain: "1", title: "1", avatar: "1", version: "0" }
80 | }),
81 | expectedMetaChange
82 | );
83 | });
84 |
85 | test.cb("config: meta change (version)", t => {
86 | t.plan(1);
87 | buildAndMatchLogs(
88 | t,
89 | Object.assign(config, {
90 | meta: { domain: "1", title: "1", avatar: "1", version: "1" }
91 | }),
92 | expectedMetaChange
93 | );
94 | });
95 |
--------------------------------------------------------------------------------
/test/config/test-nav.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test nav change
22 | */
23 |
24 | test.cb("config: nav change", t => {
25 | t.plan(1);
26 | rimraf.sync(config.output);
27 |
28 | const expected = `
29 | Starting design manual
30 | Detected changed configuration (nav)
31 | Forcing pages rebuild
32 | Starting components
33 | Found 0 changed components
34 | Generated components
35 | Starting pages
36 | Found 2 changed pages
37 | Generated test/config/tmp/page.html
38 | Generated test/config/tmp/page2.html
39 | Generated pages
40 | Design manual complete
41 | `;
42 |
43 | buildAndMatchLogs(null, config, null, () => {
44 | buildAndMatchLogs(
45 | t,
46 | Object.assign(config, { nav: [{ label: "🏡", href: "/" }] }),
47 | expected
48 | );
49 | });
50 | });
51 |
--------------------------------------------------------------------------------
/test/config/test-new.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const utils = require("../utils");
4 | const buildAndMatchLogs = utils.buildAndMatchLogs;
5 |
6 | const config = {
7 | output: __dirname + "/tmp/",
8 | pages: __dirname + "/",
9 | components: "./test/components.json",
10 | meta: {
11 | domain: "website.com",
12 | title: "Design Manual"
13 | },
14 | renderComponents: true,
15 | renderCSS: false
16 | };
17 |
18 | /**
19 | * test if no configuration was found
20 | */
21 |
22 | test.cb("config: new config", t => {
23 | t.plan(1);
24 | rimraf.sync(config.output);
25 |
26 | const expected = `
27 | Starting design manual
28 | Could not find previous configuration
29 | Forcing components rebuild
30 | Forcing pages rebuild
31 | Starting components
32 | Found 3 changed components
33 | Rendering component ./lib/component1.html
34 | Rendering component ./lib/component2.html
35 | Rendering component ./lib/component3.html
36 | Generated components
37 | Starting pages
38 | Found 2 changed pages
39 | Generated test/config/tmp/page.html
40 | Generated test/config/tmp/page2.html
41 | Generated pages
42 | Design manual complete
43 | `;
44 |
45 | buildAndMatchLogs(t, config, expected);
46 | });
47 |
--------------------------------------------------------------------------------
/test/config/test-output.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test output change, rebuild all
22 | */
23 |
24 | test.cb("config: output change", t => {
25 | t.plan(1);
26 | rimraf.sync(__dirname + "/tmp2/");
27 |
28 | const expected = `
29 | Starting design manual
30 | Could not find previous configuration
31 | Forcing components rebuild
32 | Forcing pages rebuild
33 | Starting components
34 | Found 3 changed components
35 | Rendering component ./lib/component1.html
36 | Rendering component ./lib/component2.html
37 | Rendering component ./lib/component3.html
38 | Generated components
39 | Starting pages
40 | Found 2 changed pages
41 | Generated test/config/tmp2/page.html
42 | Generated test/config/tmp2/page2.html
43 | Generated pages
44 | Design manual complete
45 | `;
46 |
47 | buildAndMatchLogs(null, config, null, () => {
48 | buildAndMatchLogs(
49 | t,
50 | Object.assign(config, { output: __dirname + "/tmp2/" }),
51 | expected
52 | );
53 | });
54 | });
55 |
56 | test.after.cb(t => {
57 | rimraf.sync(__dirname + "/tmp2/");
58 | t.end();
59 | });
60 |
--------------------------------------------------------------------------------
/test/config/test-prerender.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test prerender change
22 | */
23 |
24 | test.cb("config: prerender change", t => {
25 | t.plan(1);
26 | rimraf.sync(config.output);
27 |
28 | const expected = `
29 | Starting design manual
30 | Detected changed configuration (prerender)
31 | Forcing pages rebuild
32 | Starting components
33 | Found 0 changed components
34 | Generated components
35 | Starting pages
36 | Found 2 changed pages
37 | Generated test/config/tmp/page.html
38 | Generated test/config/tmp/page2.html
39 | Generated pages
40 | Design manual complete
41 | `;
42 |
43 | buildAndMatchLogs(null, config, null, () => {
44 | buildAndMatchLogs(t, Object.assign(config, { prerender: 1 }), expected);
45 | });
46 | });
47 |
--------------------------------------------------------------------------------
/test/config/test-same.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const utils = require("../utils");
4 | const buildAndMatchLogs = utils.buildAndMatchLogs;
5 |
6 | const config = {
7 | output: __dirname + "/tmp/",
8 | pages: __dirname + "/",
9 | components: "./test/components.json",
10 | meta: {
11 | domain: "website.com",
12 | title: "Design Manual"
13 | },
14 | renderComponents: true,
15 | renderCSS: false
16 | };
17 |
18 | /**
19 | * test if no configuration was found
20 | */
21 |
22 | test.cb("config: new config", t => {
23 | t.plan(1);
24 | rimraf.sync(config.output);
25 |
26 | const expected = `
27 | Starting design manual
28 | Starting components
29 | Found 0 changed components
30 | Generated components
31 | Starting pages
32 | Found 0 changed pages
33 | Generated pages
34 | Design manual complete
35 | `;
36 |
37 | buildAndMatchLogs(null, config, null, () => {
38 | buildAndMatchLogs(t, config, expected);
39 | });
40 | });
41 |
--------------------------------------------------------------------------------
/test/config/test-validate.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 | const path = require("path");
5 | const utils = require("../utils");
6 | const buildAndMatchLogs = utils.buildAndMatchLogs;
7 |
8 | const config = {
9 | output: __dirname + "/tmp/",
10 | pages: __dirname + "/",
11 | components: "./test/components.json",
12 | meta: {
13 | domain: "website.com",
14 | title: "Design Manual"
15 | },
16 | renderComponents: true,
17 | renderCSS: false
18 | };
19 |
20 | /**
21 | * Test mandatory options
22 | */
23 |
24 | test.cb("config: validate output", t => {
25 | t.plan(1);
26 |
27 | const options = Object.assign({}, config, { output: null });
28 |
29 | const expected = `
30 | Design Manual error: options.output is required
31 | Design manual complete
32 | `;
33 |
34 | buildAndMatchLogs(t, options, expected);
35 | });
36 |
37 | test.cb("config: validate pages", t => {
38 | t.plan(1);
39 |
40 | const options = Object.assign({}, config, { pages: null });
41 |
42 | const expected = `
43 | Design Manual error: options.pages is required
44 | Design manual complete
45 | `;
46 |
47 | buildAndMatchLogs(t, options, expected);
48 | });
49 |
50 | test.cb("config: validate components", t => {
51 | t.plan(1);
52 |
53 | const options = Object.assign({}, config, { components: null });
54 |
55 | const expected = `
56 | Design Manual error: options.components is required
57 | Design manual complete
58 | `;
59 |
60 | buildAndMatchLogs(t, options, expected);
61 | });
62 |
63 | test.cb("config: validate meta", t => {
64 | t.plan(1);
65 |
66 | const options = Object.assign({}, config, { meta: null });
67 |
68 | const expected = `
69 | Design Manual error: options.meta is required
70 | Design manual complete
71 | `;
72 |
73 | buildAndMatchLogs(t, options, expected);
74 | });
75 |
76 | test.cb("config: validate meta.title", t => {
77 | t.plan(1);
78 |
79 | const options = Object.assign({}, config, {
80 | meta: { title: null, domain: "foo" }
81 | });
82 |
83 | const expected = `
84 | Design Manual error: options.meta.title is required
85 | Design manual complete
86 | `;
87 |
88 | buildAndMatchLogs(t, options, expected);
89 | });
90 |
91 | test.cb("config: validate meta.domain", t => {
92 | t.plan(1);
93 |
94 | const options = Object.assign({}, config, {
95 | meta: { title: "foo", domain: null }
96 | });
97 |
98 | const expected = `
99 | Design Manual error: options.meta.domain is required
100 | Design manual complete
101 | `;
102 |
103 | buildAndMatchLogs(t, options, expected);
104 | });
105 |
--------------------------------------------------------------------------------
/test/defaults/components.md:
--------------------------------------------------------------------------------
1 | # Components
2 |
3 | This is the components page.
4 |
5 | ---
6 |
7 | ## Components
8 |
9 | These are components
10 |
11 | ### Contents
12 |
13 | !{component1}
14 | !{component2}
15 | !{component3}
16 |
--------------------------------------------------------------------------------
/test/defaults/test.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 |
4 | const isThere = require("is-there");
5 | const DM = require("../../lib/index");
6 |
7 | const config = {
8 | output: __dirname + "/tmp/",
9 | pages: __dirname + "/",
10 | components: "./test/components.json",
11 | meta: {
12 | domain: "website.com",
13 | title: "Design Manual"
14 | }
15 | };
16 |
17 | test.cb("defaults", t => {
18 | t.plan(7);
19 | rimraf.sync(__dirname + "/tmp");
20 |
21 | DM.build(
22 | Object.assign({}, config, {
23 | onLog: () => {},
24 | onComplete: () => {
25 | setTimeout(() => {
26 | // test styles/js generated
27 | t.true(isThere(config.output + "all.min.css"), "css exists");
28 |
29 | // test register files generated
30 | t.true(
31 | isThere(config.output + "design-manual-components.json"),
32 | "design manual components json exists"
33 | );
34 | t.true(
35 | isThere(config.output + "design-manual-config.json"),
36 | "design manual config json exists"
37 | );
38 |
39 | // test page generated
40 | t.true(
41 | isThere(config.output + "components.html"),
42 | "components.html exists"
43 | );
44 |
45 | // test lib files generated
46 | t.true(
47 | isThere(config.output + "lib/component1.html"),
48 | "component1.html exists"
49 | );
50 | t.true(
51 | isThere(config.output + "lib/component2.html"),
52 | "component2.html exists"
53 | );
54 | t.true(
55 | isThere(config.output + "lib/component3.html"),
56 | "component3.html exists"
57 | );
58 |
59 | t.end();
60 | }, 1000);
61 | }
62 | })
63 | );
64 | });
65 |
--------------------------------------------------------------------------------
/test/gulp/test.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const gulp = require("gulp");
4 |
5 | const DM = require("../../lib/index");
6 |
7 | const config = {
8 | output: __dirname + "/tmp/",
9 | pages: __dirname + "/",
10 | components: "./test/components.json",
11 | meta: {
12 | domain: "website.com",
13 | title: "Design Manual"
14 | }
15 | };
16 |
17 | test.cb("gulp", t => {
18 | t.plan(1);
19 | rimraf.sync(__dirname + "/tmp");
20 |
21 | setTimeout(() => {
22 | gulp.task("design-manual")(() => {
23 | console.log("first: should never finish");
24 | t.fail();
25 | t.end();
26 | });
27 | }, 0);
28 |
29 | setTimeout(() => {
30 | gulp.task("design-manual")(() => {
31 | console.log("third: should finish");
32 | t.pass();
33 | t.end();
34 | });
35 | }, 250);
36 |
37 | setTimeout(() => {
38 | gulp.task("design-manual")(() => {
39 | console.log("second: should never finish");
40 | t.fail();
41 | t.end();
42 | });
43 | }, 200);
44 | });
45 |
46 | gulp.task("design-manual", done => {
47 | DM.build(
48 | Object.assign({}, config, {
49 | onLog: () => {},
50 | onComplete: function() {
51 | done();
52 | }
53 | })
54 | );
55 | });
56 |
--------------------------------------------------------------------------------
/test/interrupt/components.md:
--------------------------------------------------------------------------------
1 | # Components
2 |
3 | This is the components page.
4 |
5 | ---
6 |
7 | ## Components
8 |
9 | These are components
10 |
11 | ### Contents
12 |
13 | !{component1}
14 | !{component2}
15 | !{component3}
16 |
--------------------------------------------------------------------------------
/test/interrupt/test.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 |
4 | const DM = require("../../lib/index");
5 |
6 | const config = {
7 | output: __dirname + "/tmp/",
8 | pages: __dirname + "/",
9 | components: "./test/components.json",
10 | meta: {
11 | domain: "website.com",
12 | title: "Design Manual"
13 | }
14 | };
15 |
16 | test.cb("interrupt", t => {
17 | t.plan(1);
18 | rimraf.sync(__dirname + "/tmp");
19 |
20 | DM.build(
21 | Object.assign({}, config, {
22 | onLog: () => {},
23 | onComplete: () => {
24 | t.fail();
25 | t.end();
26 | }
27 | })
28 | );
29 |
30 | setTimeout(() => {
31 | DM.build(
32 | Object.assign({}, config, {
33 | onLog: () => {},
34 | onComplete: () => {
35 | t.pass();
36 | t.end();
37 | }
38 | })
39 | );
40 | }, 250);
41 |
42 | setTimeout(() => {
43 | DM.build(
44 | Object.assign({}, config, {
45 | onLog: () => {},
46 | onComplete: () => {
47 | t.fail();
48 | t.end();
49 | }
50 | })
51 | );
52 | }, 200);
53 | });
54 |
--------------------------------------------------------------------------------
/test/page-html-options/page.md:
--------------------------------------------------------------------------------
1 | this is a page
2 |
--------------------------------------------------------------------------------
/test/page-html-options/test.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const fs = require("fs");
3 | const rimraf = require("rimraf");
4 |
5 | const DM = require("../../lib/index");
6 |
7 | const config = {
8 | output: __dirname + "/tmp/",
9 | pages: __dirname + "/",
10 | components: "./test/components.json",
11 | meta: {
12 | domain: "website.com",
13 | title: "Design Manual"
14 | },
15 | renderComponents: false,
16 | renderCSS: false
17 | };
18 |
19 | test.cb("add head html", t => {
20 | t.plan(1);
21 | rimraf.sync(__dirname + "/tmp/head/");
22 |
23 | DM.build(
24 | Object.assign({}, config, {
25 | output: config.output + "head/",
26 | headHtml: "",
27 | onLog: () => {},
28 | onComplete: () => {
29 | setTimeout(() => {
30 | let componentsHtmlTmp = fs.readFileSync(
31 | config.output + "head/page.html",
32 | "utf8"
33 | );
34 | t.truthy(componentsHtmlTmp.indexOf("") > -1);
35 |
36 | t.end();
37 | }, 1000);
38 | }
39 | })
40 | );
41 | });
42 |
43 | test.cb("add body html", t => {
44 | t.plan(1);
45 | rimraf.sync(__dirname + "/tmp/body/");
46 |
47 | DM.build(
48 | Object.assign({}, config, {
49 | output: config.output + "body/",
50 | bodyHtml: '',
51 | onLog: () => {},
52 | onComplete: () => {
53 | setTimeout(() => {
54 | let componentsHtmlTmp = fs.readFileSync(
55 | config.output + "body/page.html",
56 | "utf8"
57 | );
58 | t.truthy(
59 | componentsHtmlTmp.indexOf('') > -1
60 | );
61 | t.end();
62 | }, 1000);
63 | }
64 | })
65 | );
66 | });
67 |
--------------------------------------------------------------------------------
/test/prerender/page.md:
--------------------------------------------------------------------------------
1 | # Components
2 |
3 | This is the components page.
4 |
5 | ---
6 |
7 | ## Components
8 |
9 | These are components
10 |
11 | ### Contents
12 |
13 | !{component1}
14 | !{component3}
15 |
--------------------------------------------------------------------------------
/test/prerender/test.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 |
5 | const DM = require("../../lib/index");
6 |
7 | const config = {
8 | output: __dirname + "/tmp/",
9 | pages: __dirname + "/",
10 | components: "./test/components.json",
11 | renderComponents: true,
12 | renderCSS: false,
13 | prerender: {
14 | port: 3000,
15 | path: "",
16 | serveFolder: __dirname + "/tmp/"
17 | },
18 | meta: {
19 | domain: "website.com",
20 | title: "Design Manual"
21 | }
22 | };
23 |
24 | test.cb("render pages with components and get their heights set", t => {
25 | t.plan(2);
26 | rimraf.sync(__dirname + "/tmp");
27 |
28 | DM.build(
29 | Object.assign({}, config, {
30 | onLog: () => {},
31 | onComplete: () => {
32 | setTimeout(() => {
33 | let componentsHtmlTmp = fs.readFileSync(
34 | config.output + "page.html",
35 | "utf8"
36 | );
37 | t.truthy(
38 | componentsHtmlTmp.indexOf('scrolling="no" height="70"') > -1
39 | );
40 | t.truthy(
41 | componentsHtmlTmp.indexOf('scrolling="no" height="163"') > -1
42 | );
43 |
44 | t.end();
45 | }, 1000);
46 | }
47 | })
48 | );
49 | });
50 |
51 | test.cb("render pages with components and don't prerender", t => {
52 | t.plan(2);
53 | rimraf.sync(__dirname + "/tmp");
54 |
55 | DM.build(
56 | Object.assign({}, config, {
57 | prerender: false,
58 | onLog: () => {},
59 | onComplete: () => {
60 | setTimeout(() => {
61 | let componentsHtmlTmp = fs.readFileSync(
62 | config.output + "page.html",
63 | "utf8"
64 | );
65 | t.truthy(
66 | componentsHtmlTmp.indexOf(
67 | '
'
68 | ) > -1
69 | );
70 | t.truthy(
71 | componentsHtmlTmp.indexOf(
72 | '
'
73 | ) > -1
74 | );
75 |
76 | t.end();
77 | }, 1000);
78 | }
79 | })
80 | );
81 | });
82 |
--------------------------------------------------------------------------------
/test/puppeteer/222.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
Document
8 |
9 |
10 |
11 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/test/puppeteer/test.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const serveStatic = require("serve-static");
3 | const cp = require("child_process");
4 | const http = require("http");
5 |
6 | test("get components height", async t => {
7 | const height = new Promise((resolve, reject) => {
8 | // static file server
9 | const serve = serveStatic(__dirname);
10 | const server = http.createServer((req, res) => {
11 | serve(req, res, function(err) {
12 | res.statusCode = err ? err.status || 500 : 404;
13 | res.end(err ? err.stack : "sorry!");
14 | });
15 | });
16 |
17 | server.on("listening", () => {
18 | let puppet = cp.fork(`lib/puppeteer.js`);
19 |
20 | puppet.once("message", function(data) {
21 | if (data === "puppeteer-ready") {
22 | puppet.once("message", function(data) {
23 | if (data.height) {
24 | resolve(data.height);
25 | }
26 | });
27 |
28 | puppet.send({
29 | url: "http://localhost:3000/222.html"
30 | });
31 | }
32 | });
33 | });
34 |
35 | server.listen(3000);
36 | });
37 |
38 | t.is(await height, 222);
39 | });
40 |
--------------------------------------------------------------------------------
/test/render-css/test.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 |
4 | const isThere = require("is-there");
5 | const DM = require("../../lib/index");
6 |
7 | const config = {
8 | output: __dirname + "/tmp/",
9 | pages: __dirname + "/",
10 | components: "./test/components.json",
11 | renderComponents: false,
12 | renderCSS: false,
13 | meta: {
14 | domain: "website.com",
15 | title: "Design Manual"
16 | }
17 | };
18 |
19 | test.cb("render css", t => {
20 | t.plan(1);
21 | rimraf.sync(__dirname + "/tmp");
22 |
23 | DM.build(
24 | Object.assign({}, config, {
25 | renderCSS: true,
26 | onLog: () => {},
27 | onComplete: () => {
28 | t.true(isThere(config.output + "all.min.css"), "css exists");
29 | t.end();
30 | }
31 | })
32 | );
33 | });
34 |
35 | test.cb("don't render css", t => {
36 | t.plan(1);
37 | rimraf.sync(__dirname + "/tmp");
38 |
39 | DM.build(
40 | Object.assign({}, config, {
41 | renderCSS: false,
42 | onLog: () => {},
43 | onComplete: () => {
44 | t.true(!isThere(config.output + "app.min.js"), "css does not exist");
45 | t.end();
46 | }
47 | })
48 | );
49 | });
50 |
--------------------------------------------------------------------------------
/test/render-pages/code-frameless.md:
--------------------------------------------------------------------------------
1 | $${component1}
2 |
--------------------------------------------------------------------------------
/test/render-pages/code.md:
--------------------------------------------------------------------------------
1 | ${component1}
2 |
--------------------------------------------------------------------------------
/test/render-pages/component-frameless.md:
--------------------------------------------------------------------------------
1 | !!{component1}
2 |
--------------------------------------------------------------------------------
/test/render-pages/component.md:
--------------------------------------------------------------------------------
1 | !{component1}
2 |
--------------------------------------------------------------------------------
/test/render-pages/page.md:
--------------------------------------------------------------------------------
1 | # Components
2 |
3 | This is the components page.
4 |
5 | ---
6 |
7 | ## Components
8 |
9 | These are components
10 |
11 | ### Contents
12 |
13 | !{component1}
14 | !{component2}
15 | !!{component3}
16 | ${component3}
17 | $${component3}
18 |
--------------------------------------------------------------------------------
/test/render-pages/test.js:
--------------------------------------------------------------------------------
1 | const test = require("ava");
2 | const rimraf = require("rimraf");
3 | const fs = require("fs");
4 |
5 | const DM = require("../../lib/index");
6 |
7 | const config = {
8 | output: __dirname + "/tmp/",
9 | pages: __dirname + "/",
10 | components: "./test/components.json",
11 | renderComponents: true,
12 | renderCSS: false,
13 | meta: {
14 | domain: "website.com",
15 | title: "Design Manual"
16 | }
17 | };
18 |
19 | test.cb("render pages without components", t => {
20 | t.plan(3);
21 | rimraf.sync(__dirname + "/tmp/");
22 |
23 | DM.build(
24 | Object.assign({}, config, {
25 | renderComponents: false,
26 | onLog: () => {},
27 | onComplete: () => {
28 | setTimeout(() => {
29 | let componentsHtmlTmp = fs.readFileSync(
30 | config.output + "page.html",
31 | "utf8"
32 | );
33 | t.truthy(
34 | componentsHtmlTmp.indexOf(
35 | '
'
36 | ) > -1
37 | );
38 | t.truthy(
39 | componentsHtmlTmp.indexOf(
40 | '
'
41 | ) > -1
42 | );
43 | t.truthy(
44 | componentsHtmlTmp.indexOf(
45 | '
'
46 | ) > -1
47 | );
48 |
49 | t.end();
50 | }, 1000);
51 | }
52 | })
53 | );
54 | });
55 |
56 | test.cb("render component", t => {
57 | t.plan(2);
58 | rimraf.sync(__dirname + "/tmp/");
59 |
60 | DM.build(
61 | Object.assign({}, config, {
62 | renderComponents: true,
63 | onLog: () => {},
64 | onComplete: () => {
65 | setTimeout(() => {
66 | let componentsHtmlTmp = fs.readFileSync(
67 | config.output + "component.html",
68 | "utf8"
69 | );
70 | t.truthy(
71 | componentsHtmlTmp.indexOf(
72 | '
'
73 | ) > -1
74 | );
75 | t.truthy(
76 | componentsHtmlTmp.indexOf(
77 | '
'
78 | ) > -1
79 | );
80 |
81 | t.end();
82 | }, 1000);
83 | }
84 | })
85 | );
86 | });
87 |
88 | test.cb("render component frameless", t => {
89 | t.plan(2);
90 | rimraf.sync(__dirname + "/tmp/");
91 |
92 | DM.build(
93 | Object.assign({}, config, {
94 | renderComponents: true,
95 | onLog: () => {},
96 | onComplete: () => {
97 | setTimeout(() => {
98 | let componentsHtmlTmp = fs.readFileSync(
99 | config.output + "component-frameless.html",
100 | "utf8"
101 | );
102 | t.truthy(
103 | componentsHtmlTmp.indexOf(
104 | '
'
105 | ) > -1
106 | );
107 | t.truthy(
108 | componentsHtmlTmp.indexOf(
109 | '
'
110 | ) > -1
111 | );
112 |
113 | t.end();
114 | }, 1000);
115 | }
116 | })
117 | );
118 | });
119 |
120 | test.cb("render code", t => {
121 | t.plan(3);
122 | rimraf.sync(__dirname + "/tmp/");
123 |
124 | DM.build(
125 | Object.assign({}, config, {
126 | renderComponents: true,
127 | onLog: () => {},
128 | onComplete: () => {
129 | setTimeout(() => {
130 | let componentsHtmlTmp = fs.readFileSync(
131 | config.output + "code.html",
132 | "utf8"
133 | );
134 | t.truthy(
135 | componentsHtmlTmp.indexOf(
136 | '