/
jsHarmonyTestSpec.js
63 lines (52 loc) · 1.77 KB
/
jsHarmonyTestSpec.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
/*
Copyright 2022 apHarmony
This file is part of jsHarmony.
jsHarmony is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jsHarmony is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this package. If not, see <http://www.gnu.org/licenses/>.
*/
var _ = require('lodash');
// Parameters:
// _id: id of test
function jsHarmonyTestSpec(_id, _sourcePath){
this.id = _id; //id of test
this.sourcePath = _sourcePath; // path to the file that defined the test
this.title = _id;
this.batch = null;
this.require = [];
this.commands = [];
this.importWarnings = [];
}
const allowedProperties = {
'id': '',
'title': '',
'batch': '',
'require': [],
'commands': [],
};
//Parse a JSON object and return a jsHarmonyTestSpec object
// Ensure the spec is correct and has no extra fields
// Parameters:
// id: id of test
// obj: The JSON object
//Returns a jsHarmonyTestSpec object
jsHarmonyTestSpec.fromJSON = function(id, sourcePath, settings, obj){
let jsTS = new jsHarmonyTestSpec(id, sourcePath);
let warnings = [];
_.forEach(_.keys(obj), function(key) {
if (!(key in allowedProperties)) {
warnings.push('Unknown property [' + key + '] in test ' + id);
}
});
const conf = _.assign({importWarnings: warnings},settings,obj);
_.assign(jsTS,conf);
return jsTS;
};
module.exports = exports = jsHarmonyTestSpec;