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
186 lines (185 loc) · 5.62 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import { CASE, FEATURE, MODULE } from "../../spec-section/_enums/type/spec-section.type.enum.js";
import build from './build.js'
import folderMotif from "../../folder/folder.motif.js";
import websiteFolderMotif from "../website-folder.motif.js";
import fs from 'fs'
import { PROJECT_PATH } from "../../global/_enums/names/global.names.enum.js";
import { NOT_A_WEBSITE_FOLDER_SHAPE, NO_SCOPE_GIVEN } from "./_errors/build.errors.js";
import websitePageMotif from "../../website-page/website-page.motif.js";
export default {
type: MODULE,
group: [
{
type: FEATURE,
label: 'Creates a `name` folder at given `path`.',
test: async () => {
const path = '_tests/website-folder-build-one'
await folderMotif.create(path)
const name = 'mirador-78'
await build(
name,
websiteFolderMotif.shape({}),
path
)
try {
fs.statSync(global[PROJECT_PATH]
+ '/' + path
+ '/' + name)
return true
} catch {
return false
}
}
},
{
type: FEATURE,
label: 'Iterates on `content` property to '
+ 'render folder\'s children (W_FOLDER & W_PAGE).',
group: [
{
type: FEATURE,
label: 'When a page name is `\'\'`, '
+ 'replace it with `index.html`.',
test: async () => {
const path = '_tests/w-f-build-page-empty-name'
await folderMotif.create(path)
const name = 'kokoamo-3'
await build(
name,
websiteFolderMotif.shape({
'': websitePageMotif.shape(() => '')
}),
path
)
try {
fs.statSync(global[PROJECT_PATH]
+ '/' + path
+ '/' + name
+ '/index.html')
return true
} catch {
return false
}
}
},
{
type: FEATURE,
label: 'Build the static website tree according to '
+ 'the W_PAGE shape given.',
test: async () => {
const path = '_tests/website-folder-build-page-call'
await folderMotif.create(path)
const name = 'varimatras'
await build(
name,
websiteFolderMotif.shape({
'': websitePageMotif.shape(() => '', {}),
'about': websitePageMotif.shape(() => '', {}),
'articles': websiteFolderMotif.shape({
1: websitePageMotif.shape(() => '', {}),
2: websitePageMotif.shape(() => '', {})
})
}),
path)
try {
const sitePath = global[PROJECT_PATH] + '/' + path + '/' + name
fs.statSync(sitePath + '/index.html')
fs.statSync(sitePath + '/about')
fs.statSync(sitePath + '/about/index.html')
fs.statSync(sitePath + '/articles/1')
fs.statSync(sitePath + '/articles/1/index.html')
fs.statSync(sitePath + '/articles/2')
fs.statSync(sitePath + '/articles/2/index.html')
return true
} catch {
return false
}
}
}
]
},
{
type: FEATURE,
label: 'Create a sitemap for the WEBSITE.',
group: [
{
type: 'CASE',
label: 'Returns an object with the `sitemap` property.',
test: async () => {
const path = '_tests/website-folder-sitemap'
await folderMotif.create(path)
const name = 'fr-2021'
const result = await build(
name,
websiteFolderMotif.shape({}),
path
)
return !!result.sitemap
}
},
{
type: 'CASE',
label: 'Sitemap mimics website folder tree.',
test: async () => {
const path = '_tests/website-folder-sitemap-full'
await folderMotif.create(path)
const name = 'fr-2021'
const result = await build(
name,
websiteFolderMotif.shape({
'': websitePageMotif.shape(() => '', {}),
'storyboards': websiteFolderMotif.shape({
'': websitePageMotif.shape(() => '', {}),
'ave-hol-adin': websiteFolderMotif.shape({
1: websitePageMotif.shape(() => '', {}),
2: websitePageMotif.shape(() => '', {})
})
})
}),
path
)
return result.sitemap.length === 4
}
}
]
},
{
type: FEATURE,
label: 'Controls inputs.',
group: [
{
type: CASE,
label: 'Control that a `scope` is given',
test: async () => {
try {
await build(
'test',
{ motif: 'none' })
return false
} catch (err) {
return err.message
=== NO_SCOPE_GIVEN
}
}
},
{
type: CASE,
label: 'Control that `shape` holds a `motif` '
+ 'property with `websiteFolderPage.id` value',
test: async () => {
try {
await build(
'test',
{ motif: 'none' },
'')
return false
} catch (err) {
return err.message
=== NOT_A_WEBSITE_FOLDER_SHAPE
}
}
}
]
}
]
}