amphora-html 6.0.1-dev.0 → 7.0.0
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/README.md +17 -0
- package/index.js +2 -0
- package/lib/clone-deep.js +181 -0
- package/lib/files.js +66 -0
- package/lib/media.js +83 -79
- package/lib/render.js +44 -19
- package/lib/setup.js +55 -28
- package/lib/styleguide.js +40 -15
- package/lib/utils.js +127 -0
- package/package.json +21 -44
- package/.circleci/config.yml +0 -44
- package/.eslintrc +0 -75
- package/.github/workflows/push.yml +0 -26
- package/.istanbul.yml +0 -51
- package/__mocks__/fileMock.js +0 -3
- package/docs/README.md +0 -31
- package/docs/integration.md +0 -93
- package/docs/intro.md +0 -21
- package/docs/style.md +0 -47
- package/lib/log.test.js +0 -42
- package/lib/media.test.js +0 -908
- package/lib/render.test.js +0 -295
- package/lib/setup.test.js +0 -153
- package/lib/styleguide.test.js +0 -268
- package/test/setupFile.js +0 -3
- package/website/README.md +0 -114
- package/website/core/Footer.js +0 -55
- package/website/package.json +0 -16
- package/website/pages/en/index.js +0 -103
- package/website/pages/en/versions.js +0 -92
- package/website/sidebars.json +0 -13
- package/website/siteConfig.js +0 -66
- package/website/static/css/custom.css +0 -16
- package/website/static/img/logo.svg +0 -13
- package/website/versioned_docs/version-4.0.0/integration.md +0 -94
- package/website/versioned_docs/version-4.0.0/intro.md +0 -22
- package/website/versioned_docs/version-4.0.0/style.md +0 -48
- package/website/versioned_sidebars/version-4.0.0-sidebars.json +0 -13
- package/website/versions.json +0 -3
package/lib/render.test.js
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash'),
|
|
4
|
-
filename = __filename.split('/').pop().split('.').shift(),
|
|
5
|
-
setup = require('./setup'),
|
|
6
|
-
lib = require('./' + filename),
|
|
7
|
-
mediaService = require('./media'),
|
|
8
|
-
styleguide = require('./styleguide');
|
|
9
|
-
|
|
10
|
-
describe(_.startCase(filename), () => {
|
|
11
|
-
let fakeLog, getSchemaPathStub, getComponentPathStub, getIndicesStub;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
fakeLog = jest.fn();
|
|
15
|
-
getSchemaPathStub = jest.fn();
|
|
16
|
-
getComponentPathStub = jest.fn();
|
|
17
|
-
getIndicesStub = jest.fn();
|
|
18
|
-
setup.plugins = [];
|
|
19
|
-
|
|
20
|
-
jest.spyOn(styleguide, 'setDefaultVariations');
|
|
21
|
-
|
|
22
|
-
lib.setFsFns({ getSchemaPathStub, getComponentPathStub, getIndicesStub });
|
|
23
|
-
lib.setLog(fakeLog);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
function mockRes() {
|
|
27
|
-
return {
|
|
28
|
-
type: () => false,
|
|
29
|
-
send: () => false,
|
|
30
|
-
status: () => false
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function mockData() {
|
|
35
|
-
return {
|
|
36
|
-
_ref: 'site.com/_components/foo/instances/foo',
|
|
37
|
-
bar: true
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function mockPageMeta() {
|
|
42
|
-
return {
|
|
43
|
-
_layoutRef: 'site.com/_layouts/layout/instances/foo',
|
|
44
|
-
_ref: 'site.com/_pages/index',
|
|
45
|
-
locals: {
|
|
46
|
-
host: 'host.com'
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function mockPageMetaWithStyleguide() {
|
|
52
|
-
return {
|
|
53
|
-
_layoutRef: 'site.com/_layouts/layout/instances/foo',
|
|
54
|
-
_ref: 'site.com/_pages/index',
|
|
55
|
-
locals: {
|
|
56
|
-
host: 'host.com',
|
|
57
|
-
site: {
|
|
58
|
-
styleguide: 'stylez'
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function mockCmptMeta() {
|
|
65
|
-
return {
|
|
66
|
-
_ref: 'site.com/_components/foo/instances/foo',
|
|
67
|
-
locals: {
|
|
68
|
-
host: 'host.com'
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
describe('render', () => {
|
|
74
|
-
var hbs = {
|
|
75
|
-
partials: {
|
|
76
|
-
layout: _.noop,
|
|
77
|
-
foo: _.noop
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
test(
|
|
82
|
-
'if not in edit mode, calls hooks from plugins\' `render` functions',
|
|
83
|
-
() => {
|
|
84
|
-
const res = mockRes(),
|
|
85
|
-
meta = mockPageMeta(),
|
|
86
|
-
plugin = jest.fn().mockReturnValue(1);
|
|
87
|
-
|
|
88
|
-
jest.spyOn(mediaService, 'injectScriptsAndStyles').mockReturnValue('<html></html>');
|
|
89
|
-
jest.spyOn(hbs.partials, 'layout').mockReturnValue('<html></html>');
|
|
90
|
-
|
|
91
|
-
setup.plugins = [{ render: plugin }];
|
|
92
|
-
lib.setHbs(hbs);
|
|
93
|
-
|
|
94
|
-
return lib(mockData(), meta, res)
|
|
95
|
-
.then(() => {
|
|
96
|
-
expect(plugin.mock.calls.length).toBe(1);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
test(
|
|
102
|
-
'if not in edit mode, calls hooks from plugins\' `postRender` functions',
|
|
103
|
-
() => {
|
|
104
|
-
const res = mockRes(),
|
|
105
|
-
meta = mockPageMeta(),
|
|
106
|
-
plugin = jest.fn().mockReturnValue('html');
|
|
107
|
-
|
|
108
|
-
jest.spyOn(res, 'send');
|
|
109
|
-
jest.spyOn(mediaService, 'injectScriptsAndStyles').mockReturnValue('<html></html>');
|
|
110
|
-
jest.spyOn(hbs.partials, 'layout').mockReturnValue('<html></html>');
|
|
111
|
-
|
|
112
|
-
setup.plugins = [{ postRender: plugin }];
|
|
113
|
-
lib.setHbs(hbs);
|
|
114
|
-
|
|
115
|
-
return lib(mockData(), meta, res)
|
|
116
|
-
.then(() => {
|
|
117
|
-
expect(plugin.mock.calls.length).toBe(1);
|
|
118
|
-
expect(res.send.mock.calls[0][0]).toBe('html');
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
test(
|
|
124
|
-
'if in edit mode, do not call hooks from plugins\' `postRender` functions',
|
|
125
|
-
() => {
|
|
126
|
-
const res = mockRes(),
|
|
127
|
-
meta = mockPageMeta(),
|
|
128
|
-
plugin = jest.fn().mockReturnValue('html');
|
|
129
|
-
|
|
130
|
-
jest.spyOn(res, 'send');
|
|
131
|
-
jest.spyOn(mediaService, 'injectScriptsAndStyles').mockReturnValue('<html></html>');
|
|
132
|
-
jest.spyOn(hbs.partials, 'layout').mockReturnValue('<html></html>');
|
|
133
|
-
meta.locals.edit = true;
|
|
134
|
-
|
|
135
|
-
setup.plugins = [{ postRender: plugin }];
|
|
136
|
-
lib.setHbs(hbs);
|
|
137
|
-
|
|
138
|
-
return lib(mockData(), meta, res)
|
|
139
|
-
.then(() => {
|
|
140
|
-
expect(plugin.mock.calls.length).toBe(0);
|
|
141
|
-
expect(res.send.mock.calls[0][0]).toBe('<html></html>');
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
test(
|
|
147
|
-
"Given it is edit mode, skips hooks from plugins' `render` and `postRender` functions",
|
|
148
|
-
() => {
|
|
149
|
-
const res = mockRes(),
|
|
150
|
-
meta = mockPageMeta(),
|
|
151
|
-
plugin1 = jest.fn().mockReturnValue(1),
|
|
152
|
-
plugin2 = jest.fn().mockReturnValue(1);
|
|
153
|
-
|
|
154
|
-
getIndicesStub.mockReturnValue({ components: ['foo'] });
|
|
155
|
-
meta.locals.edit = true;
|
|
156
|
-
jest.spyOn(hbs.partials, 'layout').mockReturnValue('<html></html>');
|
|
157
|
-
setup.plugins = [{ render: plugin1, postRender: plugin2 }];
|
|
158
|
-
lib.setHbs(hbs);
|
|
159
|
-
|
|
160
|
-
return lib('some data', meta, res)
|
|
161
|
-
.then(() => {
|
|
162
|
-
expect(plugin1.mock.calls.length).toBe(0);
|
|
163
|
-
expect(plugin2.mock.calls.length).toBe(0);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
test('renders a page with a layout', () => {
|
|
169
|
-
const data = mockData(),
|
|
170
|
-
meta = mockPageMeta(),
|
|
171
|
-
res = mockRes();
|
|
172
|
-
|
|
173
|
-
jest.spyOn(res, 'send');
|
|
174
|
-
jest.spyOn(mediaService, 'injectScriptsAndStyles').mockReturnValue('<html></html>');
|
|
175
|
-
jest.spyOn(hbs.partials, 'layout').mockReturnValue('<html></html>');
|
|
176
|
-
lib.setHbs(hbs);
|
|
177
|
-
return lib(data, meta, res)
|
|
178
|
-
.then(() => {
|
|
179
|
-
expect(res.send.mock.calls[0][0]).toEqual('<html></html>');
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
test('look for component variations', () => {
|
|
184
|
-
const data = mockData(),
|
|
185
|
-
meta = mockPageMetaWithStyleguide(),
|
|
186
|
-
res = mockRes();
|
|
187
|
-
|
|
188
|
-
jest.spyOn(hbs.partials, 'layout').mockReturnValue('<html></html>');
|
|
189
|
-
jest.spyOn(styleguide, 'getVariations');
|
|
190
|
-
|
|
191
|
-
lib.setHbs(hbs);
|
|
192
|
-
return lib(data, meta, res)
|
|
193
|
-
.then(() => {
|
|
194
|
-
expect(styleguide.getVariations.mock.calls.length).toBe(1);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test('set default component variations', () => {
|
|
199
|
-
const data = mockData(),
|
|
200
|
-
meta = mockPageMetaWithStyleguide(),
|
|
201
|
-
res = mockRes();
|
|
202
|
-
|
|
203
|
-
jest.spyOn(styleguide, 'getVariations').mockReturnValue({
|
|
204
|
-
video: ['video_fullbleed', 'video_mobile']
|
|
205
|
-
});
|
|
206
|
-
jest.spyOn(hbs.partials, 'layout').mockReturnValue('<html></html>');
|
|
207
|
-
|
|
208
|
-
lib.setHbs(hbs);
|
|
209
|
-
|
|
210
|
-
return lib(data, meta, res)
|
|
211
|
-
.then(() => {
|
|
212
|
-
expect(styleguide.setDefaultVariations.mock.calls.length).toBe(1);
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test('renders a component individually', () => {
|
|
217
|
-
const data = mockData(),
|
|
218
|
-
res = mockRes(),
|
|
219
|
-
meta = mockCmptMeta(),
|
|
220
|
-
tpl = '<div></div>';
|
|
221
|
-
|
|
222
|
-
jest.spyOn(res, 'send');
|
|
223
|
-
jest.spyOn(mediaService, 'injectScriptsAndStyles').mockReturnValue('<html></html>');
|
|
224
|
-
jest.spyOn(hbs.partials, 'foo').mockReturnValue(tpl);
|
|
225
|
-
lib.setHbs(hbs);
|
|
226
|
-
return lib(data, meta, res)
|
|
227
|
-
.then(() => {
|
|
228
|
-
expect(res.send.mock.calls[0][0]).toBe(tpl);
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
test(
|
|
233
|
-
'given a template is not found, returns a reject promise',
|
|
234
|
-
() => {
|
|
235
|
-
const data = mockData(),
|
|
236
|
-
res = mockRes(),
|
|
237
|
-
meta = mockCmptMeta();
|
|
238
|
-
|
|
239
|
-
meta._ref = 'site.com/_components/bar/instances/bar';
|
|
240
|
-
jest.spyOn(res, 'status');
|
|
241
|
-
lib.setHbs(hbs);
|
|
242
|
-
|
|
243
|
-
return lib(data, meta, res)
|
|
244
|
-
.then(() => {
|
|
245
|
-
expect(res.status.mock.calls[0][0]).toBe(500);
|
|
246
|
-
expect(fakeLog.mock.calls[0][0]).toBe('error');
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
describe('configure', () => {
|
|
252
|
-
const fn = lib['configure'];
|
|
253
|
-
|
|
254
|
-
test('calls the mediaService configure function', () => {
|
|
255
|
-
jest.spyOn(mediaService, 'configure');
|
|
256
|
-
fn({ editAssetTags: true });
|
|
257
|
-
expect(mediaService.configure.mock.calls.length).toBe(1);
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
describe('addEnvVars', () => {
|
|
262
|
-
const fn = lib['addEnvVars'];
|
|
263
|
-
|
|
264
|
-
test('sets env vars', () => {
|
|
265
|
-
fn(['foo', 'bar', 'baz']);
|
|
266
|
-
expect(fakeLog.mock.calls.length).toBe(1);
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
describe('makeState', () => {
|
|
271
|
-
const fn = lib['makeState'];
|
|
272
|
-
|
|
273
|
-
test('adds layout schema to _layoutData state in edit mode if given a _layoutRef', () => {
|
|
274
|
-
const data = mockData(),
|
|
275
|
-
meta = mockPageMeta();
|
|
276
|
-
|
|
277
|
-
getIndicesStub.mockReturnValue({ components: ['foo'] });
|
|
278
|
-
meta.locals.edit = true;
|
|
279
|
-
|
|
280
|
-
expect(fn(data, meta)._layoutData).toHaveProperty('schema');
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
test('does not add layout to state if not given a _layoutRef', () => {
|
|
284
|
-
const data = mockData(),
|
|
285
|
-
meta = mockPageMeta();
|
|
286
|
-
|
|
287
|
-
delete meta._layoutRef;
|
|
288
|
-
|
|
289
|
-
getIndicesStub.mockReturnValue({ components: ['foo'] });
|
|
290
|
-
|
|
291
|
-
expect(fn(data, meta)).not.toHaveProperty('_layoutData');
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
});
|
package/lib/setup.test.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash'),
|
|
4
|
-
filename = __filename.split('/').pop().split('.').shift(),
|
|
5
|
-
lib = require('./' + filename),
|
|
6
|
-
render = require('./render'),
|
|
7
|
-
nymagHbs = require('clayhandlebars'),
|
|
8
|
-
hbs = nymagHbs(),
|
|
9
|
-
fs = require('fs'),
|
|
10
|
-
glob = require('glob');
|
|
11
|
-
|
|
12
|
-
jest.mock('fs', () => ({
|
|
13
|
-
readdirSync: () => '',
|
|
14
|
-
readFileSync: () => ''
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
describe(_.startCase(filename), () => {
|
|
18
|
-
let fakeLog, getComponentPathStub, getComponentsStub, getLayoutsStub, getLayoutPathStub;
|
|
19
|
-
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
fakeLog = jest.fn();
|
|
22
|
-
getComponentPathStub = jest.fn();
|
|
23
|
-
getComponentsStub = jest.fn();
|
|
24
|
-
getLayoutsStub = jest.fn();
|
|
25
|
-
getLayoutPathStub = jest.fn();
|
|
26
|
-
|
|
27
|
-
jest.spyOn(glob, 'sync');
|
|
28
|
-
lib.setFsFns({ getComponentPathStub, getComponentsStub, getLayoutsStub, getLayoutPathStub });
|
|
29
|
-
jest.spyOn(render, 'configure');
|
|
30
|
-
lib.setLog(fakeLog);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('init', () => {
|
|
34
|
-
const fn = lib['init'];
|
|
35
|
-
|
|
36
|
-
test('grabs handlebars templates from component directories', () => {
|
|
37
|
-
getComponentsStub.mockReturnValue(['c1', 'c2', 'c3', 'c4']);
|
|
38
|
-
getComponentPathStub.mockImplementation((name) => {
|
|
39
|
-
if (name === 'c1') return '/components/c1';
|
|
40
|
-
if (name === 'c2') return '/components/c2';
|
|
41
|
-
if (name === 'c3') return '/components/c3';
|
|
42
|
-
if (name === 'c4') return null;
|
|
43
|
-
return undefined;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
glob.sync.mockImplementation((path) => {
|
|
47
|
-
if (path === '/components/c1/template.*') return ['/components/c1/template.handlebars'];
|
|
48
|
-
if (path === '/components/c2/template.*') return ['/components/c2/template.hbs'];
|
|
49
|
-
if (path === '/components/c3/template.*') return ['/components/c3/template.nunjucks'];
|
|
50
|
-
return null;
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
jest.spyOn(fs, 'readFileSync');
|
|
54
|
-
jest.spyOn(nymagHbs, 'wrapPartial').mockImplementation((componentName) => {
|
|
55
|
-
if (componentName === 'c1') return 'hello, world';
|
|
56
|
-
return {};
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
fn();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('grabs handlebars templates from layout directories', () => {
|
|
63
|
-
getLayoutsStub.mockReturnValue(['layout', 'one-column-layout']);
|
|
64
|
-
getLayoutPathStub.mockImplementation((name) => {
|
|
65
|
-
if (name === 'layout') return '/layouts/layout';
|
|
66
|
-
if (name === 'one-column-layout') return '/layouts/one-column-layout';
|
|
67
|
-
return undefined;
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
jest.spyOn(fs, 'readFileSync');
|
|
71
|
-
jest.spyOn(nymagHbs, 'wrapPartial').mockImplementation((componentName) => {
|
|
72
|
-
if (componentName === 'layout') return 'hello, world';
|
|
73
|
-
return {};
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
fn();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('addHelpers', () => {
|
|
81
|
-
const fn = lib['addHelpers'];
|
|
82
|
-
|
|
83
|
-
test('calls the `registerHelper` function for each prop/value', () => {
|
|
84
|
-
jest.spyOn(hbs, 'registerHelper');
|
|
85
|
-
fn({test: _.noop});
|
|
86
|
-
expect(hbs.registerHelper.mock.calls[0]).toEqual([
|
|
87
|
-
'test',
|
|
88
|
-
_.noop
|
|
89
|
-
]);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe('configureRender', () => {
|
|
94
|
-
const fn = lib['configureRender'];
|
|
95
|
-
|
|
96
|
-
test('calls the render `configure` function', () => {
|
|
97
|
-
fn({ foo: 'bar' });
|
|
98
|
-
expect(render.configure.mock.calls.length).toBe(1);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('exposes the render options on the module', () => {
|
|
102
|
-
fn({ foo: 'bar' });
|
|
103
|
-
expect(lib.renderSettings).toEqual({ foo: 'bar' });
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe('addPlugins', () => {
|
|
108
|
-
const fn = lib['addPlugins'];
|
|
109
|
-
|
|
110
|
-
beforeEach(() => {
|
|
111
|
-
// clear plugins
|
|
112
|
-
lib.plugins.splice(0, lib.plugins.length);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test('adds render plugins', () => {
|
|
116
|
-
fn([{
|
|
117
|
-
render: _.noop
|
|
118
|
-
}]);
|
|
119
|
-
expect(lib.plugins.length).toBe(1);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('adds postRender plugins', () => {
|
|
123
|
-
fn([{
|
|
124
|
-
postRender: _.noop
|
|
125
|
-
}]);
|
|
126
|
-
expect(lib.plugins.length).toBe(1);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test('skips plugins with no `render` or `postRender` function', () => {
|
|
130
|
-
fn([{}]);
|
|
131
|
-
expect(lib.plugins.length).toBe(0);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe('addResolveMedia', () => {
|
|
136
|
-
const fn = lib['addResolveMedia'];
|
|
137
|
-
|
|
138
|
-
afterEach(function () {
|
|
139
|
-
lib.resolveMedia = undefined;
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('attaches resolveMedia to the module if it is a function', () => {
|
|
143
|
-
fn(_.noop);
|
|
144
|
-
|
|
145
|
-
expect(lib.resolveMedia).toBeInstanceOf(Function);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test('does not attach non-function arguments', () => {
|
|
149
|
-
fn(1);
|
|
150
|
-
expect(lib.resolveMedia).toBeUndefined();
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
});
|