This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.spec.js
104 lines (103 loc) · 2.95 KB
/
build.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { STANDALONE } from "../../global/_enums/frameworkPath/frameworkPath.enum.js";
import { FRAMEWORK_PATH } from "../../global/_enums/names/global.names.enum.js";
import fileMotif from "../../file/file.motif.js";
import folderMotif from "../../folder/folder.motif.js";
import formatEnum from "../../get/_enums/format/format.enum.js";
import { FEATURE, MODULE } from "../../spec-section/_enums/type/spec-section.type.enum.js";
import websitePageMotif from "../website-page.motif.js";
import build from "./build.js";
export default {
type: MODULE,
group: [
{
type: FEATURE,
label: 'Given a name, a W_PAGE shape and a `scope`, '
+ 'build an HTML page at the target path.',
test: async () => {
const path = '_tests/website-page-build'
await folderMotif.create(path)
const templateContent = '<html></html>'
await build(
'index.html',
{
motif: websitePageMotif.id,
template: () => templateContent
},
path
)
try {
const { content } = await fileMotif.get(
path + '/index.html',
{ format: formatEnum.UTF_8 }
)
return content.localeCompare(templateContent)
=== 0
} catch {
return false
}
}
},
{
type: FEATURE,
label: 'Shape template is rendered with its own data',
test: async () => {
const path = '_tests/website-page-build-template-data'
await folderMotif.create(path)
const testText = 'hello bobby my name is hello'
await build(
'index.html',
{
motif: websitePageMotif.id,
template: ({ testText }) => testText,
data: { testText }
},
path
)
try {
const { content } = await fileMotif.get(
path + '/index.html',
{ format: formatEnum.UTF_8 }
)
return content.localeCompare(testText)
=== 0
} catch {
return false
}
}
},
{
type: FEATURE,
label: 'If `shape.data` contains an `images: '
+ '[ \'url\' ]` property, copy given images to '
+ 'the `dest` folder.',
test: async () => {
const path = '_tests/website-page-build-copy-images'
await folderMotif.create(path)
await build(
'index.html',
{
motif: websitePageMotif.id,
template: () => '',
data: {
images: [
(global[FRAMEWORK_PATH] === STANDALONE
? ''
: 'node_modules/motifs-js/')
+ 'logo.svg' ]
}
},
path
)
try {
const result = fileMotif.get(
path + '/index.html',
{ format: formatEnum.UTF_8 }
)
return !!result
} catch {
return false
}
}
}
]
}