Migrate to mocha
parent
76ca89e500
commit
c987a28b0c
|
@ -14,6 +14,7 @@ class Collector {
|
|||
this.parser = parser;
|
||||
this.schemas = [];
|
||||
this.tasks = [];
|
||||
this.taskCount = 0;
|
||||
this.modules = new Map;
|
||||
this.global = Scope.global([]);
|
||||
this.running = false;
|
||||
|
@ -82,6 +83,7 @@ class Collector {
|
|||
const task = this._collect(node, scope);
|
||||
|
||||
this.tasks.push(task);
|
||||
++this.taskCount;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -27,10 +27,11 @@
|
|||
"resolve": "^1.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jsondiffpatch": "^0.2.5",
|
||||
"jasmine": "^2.8.0",
|
||||
"mocha": "^4.0.1",
|
||||
"nyc": "^11.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "nyc --reporter=text node tests/do"
|
||||
"test": "nyc --reporter=text mocha tests/do"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,5 +27,6 @@
|
|||
"type": {"type": "array", "items": "double"}
|
||||
}]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 3
|
||||
}
|
||||
|
|
|
@ -17,5 +17,6 @@
|
|||
"namespace": "disorder",
|
||||
"fields": [{"name": "y", "type": "Y"}]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 3
|
||||
}
|
||||
|
|
55
tests/do
55
tests/do
|
@ -2,60 +2,35 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const jsondiffpatch = require('jsondiffpatch');
|
||||
|
||||
const collect = require('..');
|
||||
|
||||
function filter(name) {
|
||||
if (process.argv.length <= 2) {
|
||||
return true;
|
||||
}
|
||||
function run(title) {
|
||||
const actual = collect(title + '.js');
|
||||
const expected = JSON.parse(fs.readFileSync(title + '.json', 'utf8'));
|
||||
|
||||
const match = part => name.includes(part);
|
||||
const negate = process.argv[2] === '!';
|
||||
const argv = process.argv.slice(negate ? 3 : 2);
|
||||
it('should provide expected schemas', () => {
|
||||
assert.deepEqual(actual.schemas, expected.schemas);
|
||||
});
|
||||
|
||||
return negate ? !argv.some(match) : argv.some(match);
|
||||
}
|
||||
|
||||
function run(name) {
|
||||
try {
|
||||
const title = path.basename(name, 'js');
|
||||
console.log(`${title}...`);
|
||||
|
||||
const code = fs.readFileSync(name, 'utf8');
|
||||
const actual = collect(name);
|
||||
const expected = JSON.parse(fs.readFileSync(name + 'on', 'utf8'));
|
||||
|
||||
const delta = jsondiffpatch.diff(actual.schemas, expected.schemas);
|
||||
|
||||
if (delta) {
|
||||
jsondiffpatch.console.log(delta);
|
||||
}
|
||||
|
||||
return !delta;
|
||||
} catch (ex) {
|
||||
console.log(ex.message);
|
||||
|
||||
return false;
|
||||
}
|
||||
it('should run expected tasks', () => {
|
||||
assert.equal(actual.taskCount, expected.taskCount);
|
||||
});
|
||||
}
|
||||
|
||||
function main() {
|
||||
process.chdir(__dirname);
|
||||
|
||||
const success = fs.readdirSync(__dirname)
|
||||
fs.readdirSync('.')
|
||||
.filter(name => path.extname(name) === '.js')
|
||||
.filter(filter)
|
||||
.reduce((success, name) => {
|
||||
const ok = run(name);
|
||||
.forEach(name => {
|
||||
const title = path.basename(name, '.js');
|
||||
|
||||
return success && ok;
|
||||
}, true);
|
||||
|
||||
process.exit(success ? 0 : 1);
|
||||
describe(title, () => run(title));
|
||||
});
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
@ -27,5 +27,6 @@
|
|||
"type": {"type": "enum", "symbols": ["one", "two"]}
|
||||
}]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 3
|
||||
}
|
||||
|
|
|
@ -70,5 +70,6 @@
|
|||
{"name": "p", "type": "externals.second.P"}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 18
|
||||
}
|
||||
|
|
|
@ -50,5 +50,6 @@
|
|||
{"name": "z", "type": "boolean"}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 6
|
||||
}
|
||||
|
|
|
@ -62,5 +62,6 @@
|
|||
{"name": "z", "type": "_A_C"}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 6
|
||||
}
|
||||
|
|
|
@ -12,5 +12,6 @@
|
|||
"namespace": "maps",
|
||||
"values": "double"
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 2
|
||||
}
|
||||
|
|
|
@ -36,5 +36,6 @@
|
|||
{"name": "e", "type": {"type": "fixed", "size": 10}}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 3
|
||||
}
|
||||
|
|
|
@ -36,5 +36,6 @@
|
|||
{"name": "e", "type": "bytes"}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 3
|
||||
}
|
||||
|
|
|
@ -35,5 +35,6 @@
|
|||
{"name": "c", "type": "A"}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 4
|
||||
}
|
||||
|
|
|
@ -75,5 +75,6 @@
|
|||
{"name": "z", "type": "scopes._1.Z"}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 7
|
||||
}
|
||||
|
|
|
@ -27,5 +27,6 @@
|
|||
{"name": "b", "type": "double"}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 6
|
||||
}
|
||||
|
|
|
@ -12,5 +12,6 @@
|
|||
"namespace": "typeInMethod._1",
|
||||
"fields": [{"name": "t", "type": "typeInMethod.Test"}]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 2
|
||||
}
|
||||
|
|
|
@ -45,5 +45,6 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 3
|
||||
}
|
||||
|
|
|
@ -36,5 +36,6 @@
|
|||
]
|
||||
}]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 3
|
||||
}
|
||||
|
|
|
@ -24,5 +24,6 @@
|
|||
{"name": "a", "type": {"type": "enum", "symbols": ["one"]}}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"taskCount": 3
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue