-
Notifications
You must be signed in to change notification settings - Fork 471
/
Copy pathlistOfTestModules.js
88 lines (81 loc) · 3.3 KB
/
listOfTestModules.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
const fs = require('fs');
const path = require('path');
const exceptions = require('./exceptions');
const buildFiles = {};
const buidDirs = {};
/**
* @param fileName - expect to be in snake case , eg: this_is_a_test_file.cc
* @returns init function name in the file
*
* general format of init function name is camelCase version of the snake_case file name
*/
function getExportObjectName (fileName) {
fileName = fileName.split('_').map(token => exceptions.nouns[token] ? exceptions.nouns[token] : token).join('_');
const str = fileName.replace(/(_\w)/g, (k) => k[1].toUpperCase());
const exportObjectName = str.charAt(0).toUpperCase() + str.substring(1);
if (exceptions.exportNames[exportObjectName]) {
return exceptions.exportNames[exportObjectName];
}
return exportObjectName;
}
/**
* @param fileName - expect to be in snake case , eg: this_is_a_test_file.cc
* @returns property name of exported init function
*/
function getExportPropertyName (fileName) {
if (exceptions.propertyNames[fileName.toLowerCase()]) {
return exceptions.propertyNames[fileName.toLowerCase()];
}
return fileName;
}
/**
* creates a configuration list for all available test modules
* The configuration object contains the expected init function names and corresponding export property names
*/
function listOfTestModules (currentDirectory = path.join(__dirname, '/../test'), pre = '') {
fs.readdirSync(currentDirectory).forEach((file) => {
if (file === 'binding.cc' ||
file === 'binding.gyp' ||
file === 'build' ||
file === 'common' ||
file === 'thunking_manual.cc' ||
file === 'addon_build' ||
file[0] === '.') {
return;
}
const absoluteFilepath = path.join(currentDirectory, file);
const fileName = file.toLowerCase().replace('.cc', '');
if (fs.statSync(absoluteFilepath).isDirectory()) {
buidDirs[fileName] = [];
listOfTestModules(absoluteFilepath, pre + file + '/');
} else {
if (!file.toLowerCase().endsWith('.cc')) return;
if (currentDirectory.trim().split('/test/').length > 1) {
buidDirs[currentDirectory.split('/test/')[1].toLowerCase()].push(fileName);
}
const relativePath = (currentDirectory.split(`${fileName}.cc`)[0]).split('/test/')[1] || '';
buildFiles[fileName] = { dir: relativePath, propertyName: getExportPropertyName(fileName), objectName: getExportObjectName(fileName) };
}
});
}
listOfTestModules();
module.exports = {
dirs: buidDirs,
files: buildFiles
};
/**
* Test cases
* @fires only when run directly from terminal
* eg: node listOfTestModules
*/
if (require.main === module) {
const assert = require('assert');
assert.strictEqual(getExportObjectName('objectwrap_constructor_exception'), 'ObjectWrapConstructorException');
assert.strictEqual(getExportObjectName('typed_threadsafe_function'), 'TypedThreadSafeFunction');
assert.strictEqual(getExportObjectName('objectwrap_removewrap'), 'ObjectWrapRemovewrap');
assert.strictEqual(getExportObjectName('function_reference'), 'FunctionReference');
assert.strictEqual(getExportObjectName('async_worker'), 'AsyncWorker');
assert.strictEqual(getExportObjectName('async_progress_worker'), 'AsyncProgressWorker');
assert.strictEqual(getExportObjectName('async_worker_persistent'), 'PersistentAsyncWorker');
console.log('ALL tests passed');
}