forked from assemble/assemble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.data.js
96 lines (83 loc) · 2.97 KB
/
app.data.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
'use strict';
require('mocha');
require('should');
var path = require('path');
var assert = require('assert');
var support = require('./support');
var App = support.resolve();
var app;
describe('app.data', function() {
beforeEach(function() {
app = new App();
});
it('should set a key-value pair on cache.data:', function() {
app.data('a', 'b');
assert(app.cache.data.a === 'b');
});
it('should set an object on cache.data:', function() {
app.data({c: 'd'});
assert(app.cache.data.c === 'd');
});
it('should load data from a file onto cache.data:', function() {
app.data('test/fixtures/data/a.json');
assert(app.cache.data.a.one.a === 'aaa');
});
it('should load a glob of data onto cache.data:', function() {
app.data('test/fixtures/data/*.json');
assert(app.cache.data.a.one.a === 'aaa');
assert(app.cache.data.b.two.b === 'bbb');
assert(app.cache.data.c.three.c === 'ccc');
});
it('should use `namespace` defined on global opts:', function() {
app.option('namespace', function(key) {
return 'prefix_' + path.basename(key, path.extname(key));
});
app.data('test/fixtures/data/*.json');
assert(app.cache.data.prefix_a.one.a === 'aaa');
assert(app.cache.data.prefix_b.two.b === 'bbb');
assert(app.cache.data.prefix_c.three.c === 'ccc');
});
it('should use `namespace` defined on data opts:', function() {
app.data('test/fixtures/data/*.json', {
namespace: function(key) {
return 'prefix_' + path.basename(key, path.extname(key));
}
});
assert(app.cache.data.prefix_a.one.a === 'aaa');
assert(app.cache.data.prefix_b.two.b === 'bbb');
assert(app.cache.data.prefix_c.three.c === 'ccc');
});
it('should use `renameKey` defined on data opts:', function() {
app.data('test/fixtures/data/*.json', {
renameKey: function(key) {
return 'prefix_' + path.basename(key, path.extname(key));
}
});
assert(app.cache.data.prefix_a.one.a === 'aaa');
assert(app.cache.data.prefix_b.two.b === 'bbb');
assert(app.cache.data.prefix_c.three.c === 'ccc');
});
it('should extend `cache.data`', function() {
app.data({a: 'aaa', b: 'bbb', c: 'ccc'});
app.data({x: 'xxx', y: 'yyy', z: 'zzz'});
assert(app.cache.data.a === 'aaa');
assert(app.cache.data.b === 'bbb');
assert(app.cache.data.c === 'ccc');
assert(app.cache.data.x === 'xxx');
assert(app.cache.data.y === 'yyy');
assert(app.cache.data.z === 'zzz');
});
it('should extend the `cache.data` object when the first param is a string.', function() {
app.data('foo', {x: 'xxx', y: 'yyy', z: 'zzz'});
app.data('bar', {a: 'aaa', b: 'bbb', c: 'ccc'});
assert(app.cache.data.foo.x === 'xxx');
assert(app.cache.data.bar.a === 'aaa');
});
it('should be chainable.', function() {
app
.data({x: 'xxx', y: 'yyy', z: 'zzz'})
.data({a: 'aaa', b: 'bbb', c: 'ccc'});
assert(app.cache.data.x === 'xxx');
assert(app.cache.data.a === 'aaa');
});
});