fable 3.0.50 → 3.0.52
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/.config/configstore/update-notifier-npm.json +1 -1
- package/dist/fable.compatible.js +59 -39
- package/dist/fable.compatible.min.js +10 -18
- package/dist/fable.compatible.min.js.map +1 -1
- package/dist/fable.js +33 -13
- package/dist/fable.min.js +10 -18
- package/dist/fable.min.js.map +1 -1
- package/gulpfile.js +1 -164
- package/package.json +65 -78
- package/source/Fable.js +3 -0
- package/source/services/Fable-Service-Anticipate.js +87 -0
- package/source/services/Fable-Service-DataGeneration-DefaultValues.json +55 -0
- package/source/services/Fable-Service-DataGeneration.js +66 -0
- package/source/services/Fable-Service-FilePersistence-Web.js +1 -0
- package/source/services/Fable-Service-FilePersistence.js +180 -110
- package/test/Anticipate_tests.js +91 -0
- package/test/DataGeneration_tests.js +109 -0
- package/test/FilePersistence_tests.js +73 -6
- package/gulpfile-config.json +0 -11
- package/gulpfile-config_compatible.json +0 -11
- package/gulpfile-config_default.json +0 -11
|
@@ -8,120 +8,190 @@ class FableServiceFilePersistence extends libFableServiceBase
|
|
|
8
8
|
{
|
|
9
9
|
constructor(pFable, pOptions, pServiceHash)
|
|
10
10
|
{
|
|
11
|
-
|
|
11
|
+
super(pFable, pOptions, pServiceHash);
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
this.serviceType = 'FilePersistence';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (!this.options.hasOwnProperty('Mode'))
|
|
16
|
+
{
|
|
17
|
+
this.options.Mode = parseInt('0777', 8) & ~process.umask();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
this.currentInputFolder = `/tmp`;
|
|
21
|
+
this.currentOutputFolder = `/tmp`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
joinPath(pPathArray)
|
|
25
|
+
{
|
|
26
|
+
return libPath.resolve(...pPathArray);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
existsSync(pPath)
|
|
30
|
+
{
|
|
31
|
+
return libFS.existsSync(pPath);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exists(pPath, fCallback)
|
|
35
|
+
{
|
|
36
|
+
let tmpFileExists = this.existsSync(pPath);;
|
|
37
|
+
|
|
38
|
+
return fCallback(null, tmpFileExists);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
writeFileSync(pFileName, pFileContent, pOptions)
|
|
42
|
+
{
|
|
43
|
+
let tmpOptions = (typeof(pOptions) === 'undefined') ? 'utf8' : pOptions;
|
|
44
|
+
return libFS.writeFileSync(pFileName, pFileContent, tmpOptions);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
appendFileSync(pFileName, pAppendContent, pOptions)
|
|
48
|
+
{
|
|
49
|
+
let tmpOptions = (typeof(pOptions) === 'undefined') ? 'utf8' : pOptions;
|
|
50
|
+
return libFS.appendFileSync(pFileName, pAppendContent, tmpOptions);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
deleteFileSync(pFileName)
|
|
54
|
+
{
|
|
55
|
+
return libFS.unlinkSync(pFileName);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
writeFileSyncFromObject(pFileName, pObject)
|
|
59
|
+
{
|
|
60
|
+
return this.writeFileSync(pFileName, JSON.stringify(pObject, null, 4));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
writeFileSyncFromArray(pFileName, pFileArray)
|
|
64
|
+
{
|
|
65
|
+
if (!Array.isArray(pFileArray))
|
|
66
|
+
{
|
|
67
|
+
this.log.error(`File Persistence Service attempted to write ${pFileName} from array but the expected array was not an array (it was a ${typeof(pFileArray)}).`);
|
|
68
|
+
return Error('Attempted to write ${pFileName} from array but the expected array was not an array (it was a ${typeof(pFileArray)}).');
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
{
|
|
72
|
+
for (let i = 0; i < pFileArray.length; i++)
|
|
73
|
+
{
|
|
74
|
+
return this.appendFileSync(pFileName, `${pFileArray[i]}\n`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
19
77
|
}
|
|
20
78
|
|
|
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
|
-
|
|
79
|
+
// Default folder behaviors
|
|
80
|
+
|
|
81
|
+
getDefaultOutputPath(pFileName)
|
|
82
|
+
{
|
|
83
|
+
return libPath.join(this.currentOutputFolder, pFileName);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
dataFolderWriteSync(pFileName, pFileContent)
|
|
87
|
+
{
|
|
88
|
+
return this.writeFileSync(this.getDefaultOutputPath(pFileName), pFileContent);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
dataFolderWriteSyncFromObject(pFileName, pObject)
|
|
92
|
+
{
|
|
93
|
+
return this.writeFileSyncFromObject(this.getDefaultOutputPath(pFileName), pObject);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
dataFolderWriteSyncFromArray(pFileName, pFileArray)
|
|
97
|
+
{
|
|
98
|
+
return this.writeFileSyncFromArray(this.getDefaultOutputPath(pFileName), pFileArray);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Folder management
|
|
102
|
+
|
|
103
|
+
makeFolderRecursive (pParameters, fCallback)
|
|
104
|
+
{
|
|
105
|
+
let tmpParameters = pParameters;
|
|
106
|
+
|
|
107
|
+
if (typeof(pParameters) == 'string')
|
|
108
|
+
{
|
|
109
|
+
tmpParameters = { Path: pParameters };
|
|
110
|
+
}
|
|
111
|
+
else if (typeof(pParameters) !== 'object')
|
|
112
|
+
{
|
|
113
|
+
fCallback(new Error('Parameters object or string not properly passed to recursive folder create.'));
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if ((typeof(tmpParameters.Path) !== 'string'))
|
|
118
|
+
{
|
|
119
|
+
fCallback(new Error('Parameters object needs a path to run the folder create operation.'));
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!tmpParameters.hasOwnProperty('Mode'))
|
|
124
|
+
{
|
|
125
|
+
tmpParameters.Mode = this.options.Mode;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Check if we are just starting .. if so, build the initial state for our recursive function
|
|
129
|
+
if (typeof(tmpParameters.CurrentPathIndex) === 'undefined')
|
|
130
|
+
{
|
|
131
|
+
// Build the tools to start recursing
|
|
132
|
+
tmpParameters.ActualPath = libPath.normalize(tmpParameters.Path);
|
|
133
|
+
tmpParameters.ActualPathParts = tmpParameters.ActualPath.split(libPath.sep);
|
|
134
|
+
tmpParameters.CurrentPathIndex = 0;
|
|
135
|
+
tmpParameters.CurrentPath = '';
|
|
136
|
+
}
|
|
137
|
+
else
|
|
138
|
+
{
|
|
139
|
+
// This is not our first run, so we will continue the recursion.
|
|
140
|
+
// Build the new base path
|
|
141
|
+
if (tmpParameters.CurrentPath == libPath.sep)
|
|
142
|
+
{
|
|
143
|
+
tmpParameters.CurrentPath = tmpParameters.CurrentPath + tmpParameters.ActualPathParts[tmpParameters.CurrentPathIndex];
|
|
144
|
+
}
|
|
145
|
+
else
|
|
146
|
+
{
|
|
147
|
+
tmpParameters.CurrentPath = tmpParameters.CurrentPath + libPath.sep + tmpParameters.ActualPathParts[tmpParameters.CurrentPathIndex];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Increment the path index
|
|
151
|
+
tmpParameters.CurrentPathIndex++;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Check if the path is fully complete
|
|
155
|
+
if (tmpParameters.CurrentPathIndex >= tmpParameters.ActualPathParts.length)
|
|
156
|
+
{
|
|
157
|
+
fCallback(null);
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Check if the path exists (and is a folder)
|
|
162
|
+
libFS.open(tmpParameters.CurrentPath + libPath.sep + tmpParameters.ActualPathParts[tmpParameters.CurrentPathIndex], 'r',
|
|
163
|
+
function(pError, pFileDescriptor)
|
|
164
|
+
{
|
|
165
|
+
if (pFileDescriptor)
|
|
166
|
+
{
|
|
167
|
+
libFS.closeSync(pFileDescriptor);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (pError && pError.code=='ENOENT')
|
|
171
|
+
{
|
|
172
|
+
/* Path doesn't exist, create it */
|
|
173
|
+
libFS.mkdir(tmpParameters.CurrentPath + libPath.sep + tmpParameters.ActualPathParts[tmpParameters.CurrentPathIndex], tmpParameters.Mode,
|
|
174
|
+
(pCreateError) =>
|
|
175
|
+
{
|
|
176
|
+
if (!pCreateError)
|
|
177
|
+
{
|
|
178
|
+
// We have now created our folder and there was no error -- continue.
|
|
179
|
+
return this.makeFolderRecursive(tmpParameters, fCallback);
|
|
180
|
+
}
|
|
181
|
+
else
|
|
182
|
+
{
|
|
183
|
+
fCallback(pCreateError);
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
else
|
|
189
|
+
{
|
|
190
|
+
return this.makeFolderRecursive(tmpParameters, fCallback);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
}
|
|
125
195
|
}
|
|
126
196
|
|
|
127
197
|
module.exports = FableServiceFilePersistence;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the Anticipate pattern
|
|
3
|
+
* @author Steven Velozo <steven@velozo.com>
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const libFable = require('../source/Fable.js');
|
|
7
|
+
|
|
8
|
+
const Chai = require("chai");
|
|
9
|
+
const Expect = Chai.expect;
|
|
10
|
+
|
|
11
|
+
suite
|
|
12
|
+
(
|
|
13
|
+
'Fable Anticipate',
|
|
14
|
+
() =>
|
|
15
|
+
{
|
|
16
|
+
setup(() => { });
|
|
17
|
+
|
|
18
|
+
suite
|
|
19
|
+
(
|
|
20
|
+
'Basic Asynchronous Operations',
|
|
21
|
+
function ()
|
|
22
|
+
{
|
|
23
|
+
test
|
|
24
|
+
(
|
|
25
|
+
'Setup some async calls and make sure they run',
|
|
26
|
+
function (fTestComplete)
|
|
27
|
+
{
|
|
28
|
+
let testFable = new libFable();
|
|
29
|
+
let tmpAnticipate = testFable.serviceManager.instantiateServiceProvider('Anticipate');
|
|
30
|
+
tmpAnticipate.anticipate(function (fCallback)
|
|
31
|
+
{
|
|
32
|
+
testFable.log.info('Operation First test timeout entered...');
|
|
33
|
+
setTimeout(function ()
|
|
34
|
+
{
|
|
35
|
+
testFable.log.info(`Operation First test timeout done!`);
|
|
36
|
+
fCallback();
|
|
37
|
+
}, 500);
|
|
38
|
+
});
|
|
39
|
+
tmpAnticipate.anticipate(function (fCallback)
|
|
40
|
+
{
|
|
41
|
+
testFable.log.info('Operation Second test timeout entered...');
|
|
42
|
+
setTimeout(function ()
|
|
43
|
+
{
|
|
44
|
+
testFable.log.info(`Operation Second test timeout done!`);
|
|
45
|
+
fCallback();
|
|
46
|
+
}, 50);
|
|
47
|
+
});
|
|
48
|
+
tmpAnticipate.wait(function (pError)
|
|
49
|
+
{
|
|
50
|
+
testFable.log.info(`Wait 1 completed: ${pError}`)
|
|
51
|
+
return fTestComplete();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
test
|
|
56
|
+
(
|
|
57
|
+
'Setup some async calls to run together and make sure they run',
|
|
58
|
+
function (fTestComplete)
|
|
59
|
+
{
|
|
60
|
+
let testFable = new libFable();
|
|
61
|
+
let tmpAnticipate = testFable.serviceManager.instantiateServiceProvider('Anticipate');
|
|
62
|
+
tmpAnticipate.maxOperations = 2;
|
|
63
|
+
tmpAnticipate.anticipate(function (fCallback)
|
|
64
|
+
{
|
|
65
|
+
testFable.log.info('Operation First test timeout entered...');
|
|
66
|
+
setTimeout(function ()
|
|
67
|
+
{
|
|
68
|
+
testFable.log.info(`Operation First test timeout done!`);
|
|
69
|
+
fCallback();
|
|
70
|
+
}, 500);
|
|
71
|
+
});
|
|
72
|
+
tmpAnticipate.anticipate(function (fCallback)
|
|
73
|
+
{
|
|
74
|
+
testFable.log.info('Operation Second test timeout entered...');
|
|
75
|
+
setTimeout(function ()
|
|
76
|
+
{
|
|
77
|
+
testFable.log.info(`Operation Second test timeout done!`);
|
|
78
|
+
fCallback();
|
|
79
|
+
}, 50);
|
|
80
|
+
});
|
|
81
|
+
tmpAnticipate.wait(function (pError)
|
|
82
|
+
{
|
|
83
|
+
testFable.log.info(`Wait 1 completed: ${pError}`)
|
|
84
|
+
return fTestComplete();
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
);
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the Anticipate pattern
|
|
3
|
+
* @author Steven Velozo <steven@velozo.com>
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const libFable = require('../source/Fable.js');
|
|
7
|
+
|
|
8
|
+
const Chai = require("chai");
|
|
9
|
+
const Expect = Chai.expect;
|
|
10
|
+
|
|
11
|
+
suite
|
|
12
|
+
(
|
|
13
|
+
'Fable Data Generation',
|
|
14
|
+
() =>
|
|
15
|
+
{
|
|
16
|
+
setup(() => { });
|
|
17
|
+
|
|
18
|
+
suite
|
|
19
|
+
(
|
|
20
|
+
'Generate random numbers and strings',
|
|
21
|
+
function ()
|
|
22
|
+
{
|
|
23
|
+
test
|
|
24
|
+
(
|
|
25
|
+
'Just get me a random number',
|
|
26
|
+
function (fTestComplete)
|
|
27
|
+
{
|
|
28
|
+
let testFable = new libFable();
|
|
29
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
30
|
+
Expect(tmpDataGeneration.randomIntegerUpTo(100)).to.be.within(0, 100);
|
|
31
|
+
return fTestComplete();
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
test
|
|
35
|
+
(
|
|
36
|
+
'How about a random number string!',
|
|
37
|
+
function (fTestComplete)
|
|
38
|
+
{
|
|
39
|
+
let testFable = new libFable();
|
|
40
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
41
|
+
Expect(tmpDataGeneration.randomNumericString()).to.be.a('string');
|
|
42
|
+
Expect(tmpDataGeneration.randomNumericString().length).to.equal(10);
|
|
43
|
+
return fTestComplete();
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
test
|
|
47
|
+
(
|
|
48
|
+
'How about a random color?',
|
|
49
|
+
function (fTestComplete)
|
|
50
|
+
{
|
|
51
|
+
let testFable = new libFable();
|
|
52
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
53
|
+
testFable.log.info(`Random color: ${tmpDataGeneration.randomColor()}`);
|
|
54
|
+
Expect(tmpDataGeneration.randomColor()).to.be.a('string');
|
|
55
|
+
return fTestComplete();
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
test
|
|
59
|
+
(
|
|
60
|
+
'DayOfWeek',
|
|
61
|
+
function (fTestComplete)
|
|
62
|
+
{
|
|
63
|
+
let testFable = new libFable();
|
|
64
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
65
|
+
testFable.log.info(`Random Day of Week: ${tmpDataGeneration.randomDayOfWeek()}`);
|
|
66
|
+
Expect(tmpDataGeneration.randomDayOfWeek()).to.be.a('string');
|
|
67
|
+
return fTestComplete();
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
test
|
|
71
|
+
(
|
|
72
|
+
'Month',
|
|
73
|
+
function (fTestComplete)
|
|
74
|
+
{
|
|
75
|
+
let testFable = new libFable();
|
|
76
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
77
|
+
testFable.log.info(`Random Month: ${tmpDataGeneration.randomMonth()}`);
|
|
78
|
+
Expect(tmpDataGeneration.randomMonth()).to.be.a('string');
|
|
79
|
+
return fTestComplete();
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
test
|
|
83
|
+
(
|
|
84
|
+
'First name',
|
|
85
|
+
function (fTestComplete)
|
|
86
|
+
{
|
|
87
|
+
let testFable = new libFable();
|
|
88
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
89
|
+
testFable.log.info(`Random Name: ${tmpDataGeneration.randomName()}`);
|
|
90
|
+
Expect(tmpDataGeneration.randomName()).to.be.a('string');
|
|
91
|
+
return fTestComplete();
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
test
|
|
95
|
+
(
|
|
96
|
+
'Surname',
|
|
97
|
+
function (fTestComplete)
|
|
98
|
+
{
|
|
99
|
+
let testFable = new libFable();
|
|
100
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
101
|
+
testFable.log.info(`Random Surname: ${tmpDataGeneration.randomSurname()}`);
|
|
102
|
+
Expect(tmpDataGeneration.randomSurname()).to.be.a('string');
|
|
103
|
+
return fTestComplete();
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Unit tests for Fable
|
|
2
|
+
* Unit tests for the Fable simple-get RestClient
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
*
|
|
@@ -11,24 +11,91 @@ var libFable = require('../source/Fable.js');
|
|
|
11
11
|
var Chai = require("chai");
|
|
12
12
|
var Expect = Chai.expect;
|
|
13
13
|
|
|
14
|
+
// https://en.wiktionary.org/w/api.php?action=parse&prop=wikitext&format=json&page=dog
|
|
15
|
+
|
|
14
16
|
suite
|
|
15
17
|
(
|
|
16
|
-
'
|
|
18
|
+
'Fable FilePersistence',
|
|
17
19
|
function()
|
|
18
20
|
{
|
|
21
|
+
setup
|
|
22
|
+
(
|
|
23
|
+
function() { }
|
|
24
|
+
);
|
|
25
|
+
|
|
19
26
|
suite
|
|
20
27
|
(
|
|
21
|
-
'
|
|
28
|
+
'Basic File Management',
|
|
22
29
|
function()
|
|
23
30
|
{
|
|
24
31
|
test
|
|
25
32
|
(
|
|
26
|
-
'
|
|
27
|
-
function(
|
|
33
|
+
'Check that a file exists',
|
|
34
|
+
function(fTestComplete)
|
|
35
|
+
{
|
|
36
|
+
let testFable = new libFable();
|
|
37
|
+
let tmpFilePersistence = testFable.serviceManager.instantiateServiceProvider('FilePersistence');
|
|
38
|
+
Expect(tmpFilePersistence).is.an('object');
|
|
39
|
+
Expect(tmpFilePersistence.existsSync(`${__dirname}/../package.json`)).to.equal(true);
|
|
40
|
+
Expect(tmpFilePersistence.existsSync(`${__dirname}/package.json`)).to.equal(false);
|
|
41
|
+
return fTestComplete();
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
test
|
|
45
|
+
(
|
|
46
|
+
'Create, write, read and then delete a file.',
|
|
47
|
+
function(fTestComplete)
|
|
28
48
|
{
|
|
29
49
|
let testFable = new libFable();
|
|
50
|
+
let tmpFilePersistence = testFable.serviceManager.instantiateServiceProvider('FilePersistence');
|
|
51
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
52
|
+
|
|
53
|
+
let tmpLogFilePath = `/tmp/Fable-Test-${tmpDataGeneration.randomNumericString()}.log`;
|
|
54
|
+
testFable.log.info(`Writing test log file: [${tmpLogFilePath}]`);
|
|
55
|
+
|
|
56
|
+
Expect(tmpFilePersistence.existsSync(tmpLogFilePath)).to.equal(false);
|
|
57
|
+
|
|
58
|
+
// Now write some data to the file.
|
|
59
|
+
tmpFilePersistence.writeFileSyncFromObject(tmpLogFilePath, testFable.settings);
|
|
60
|
+
|
|
61
|
+
Expect(tmpFilePersistence.existsSync(tmpLogFilePath)).to.equal(true);
|
|
62
|
+
|
|
63
|
+
// Now delete the file
|
|
64
|
+
tmpFilePersistence.deleteFileSync(tmpLogFilePath);
|
|
65
|
+
|
|
66
|
+
Expect(tmpFilePersistence.existsSync(tmpLogFilePath)).to.equal(false);
|
|
67
|
+
|
|
68
|
+
return fTestComplete();
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
test
|
|
72
|
+
(
|
|
73
|
+
'Create, write, read and then delete a file.',
|
|
74
|
+
function(fTestComplete)
|
|
75
|
+
{
|
|
76
|
+
let testFable = new libFable();
|
|
77
|
+
let tmpFilePersistence = testFable.serviceManager.instantiateServiceProvider('FilePersistence');
|
|
78
|
+
let tmpDataGeneration = testFable.serviceManager.instantiateServiceProvider('DataGeneration');
|
|
79
|
+
|
|
80
|
+
let tmpLogFilePath = `/tmp/Fable-Test-${tmpDataGeneration.randomNumericString()}.log`;
|
|
81
|
+
testFable.log.info(`Writing test log file: [${tmpLogFilePath}]`);
|
|
82
|
+
|
|
83
|
+
Expect(tmpFilePersistence.existsSync(tmpLogFilePath)).to.equal(false);
|
|
84
|
+
|
|
85
|
+
// Now write some data to the file.
|
|
86
|
+
for (let i = 0; i < 100; i++)
|
|
87
|
+
{
|
|
88
|
+
tmpFilePersistence.appendFileSync(tmpLogFilePath, `Line ${i} got a number like ${tmpDataGeneration.randomColor()} ${tmpDataGeneration.randomNumericString(3,789)} for ${tmpDataGeneration.randomName()} ${tmpDataGeneration.randomSurname()}!\n`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
Expect(tmpFilePersistence.existsSync(tmpLogFilePath)).to.equal(true);
|
|
92
|
+
|
|
93
|
+
// Now delete the file
|
|
94
|
+
tmpFilePersistence.deleteFileSync(tmpLogFilePath);
|
|
95
|
+
|
|
96
|
+
Expect(tmpFilePersistence.existsSync(tmpLogFilePath)).to.equal(false);
|
|
30
97
|
|
|
31
|
-
return
|
|
98
|
+
return fTestComplete();
|
|
32
99
|
}
|
|
33
100
|
);
|
|
34
101
|
}
|
package/gulpfile-config.json
DELETED