未验证 提交 4443a76b 编写于 作者: X xiaolei li 提交者: GitHub

[TD-12700]<enhence>update node conector test cases to follow selfdecr… (#9714)

* [TD-12700]<enhence>update node conector test cases to follow selfdecribe standard

* [TD-12700]<enhence>:nodejs test cases update

* [TD-12700]<enhence>(connector):modify nodejs test cases to follow self describe standard
上级 60bbbac7
/*
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/
module.exports = {
// All imported modules in your tests should be mocked automatically
// automock: false,
// Stop running tests after `n` failures
// bail: 0,
// The directory where Jest should store its cached dependency information
// cacheDirectory: "/tmp/jest_rt",
// Automatically clear mock calls, instances and results before every test
// clearMocks: true,
// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: true,
// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,
// The directory where Jest should output its coverage files
// coverageDirectory: "coverage",
// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],
// Indicates which provider should be used to instrument code for coverage
// coverageProvider: "v8",
// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],
// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,
// A path to a custom dependency extractor
// dependencyExtractor: undefined,
// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,
// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],
// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,
// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,
// A set of global variables that need to be available in all test environments
// globals: {},
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",
// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],
// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "jsx",
// "ts",
// "tsx",
// "json",
// "node"
// ],
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// moduleNameMapper: {},
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],
// Activates notifications for test results
// notify: false,
// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",
// A preset that is used as a base for Jest's configuration
// preset: undefined,
// Run tests from one or more projects
// projects: undefined,
// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
// Automatically reset mock state before every test
// resetMocks: false,
// Reset the module registry before running each individual test
// resetModules: false,
// A path to a custom resolver
// resolver: undefined,
// Automatically restore mock state and implementation before every test
// restoreMocks: false,
// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,
// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],
// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",
// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],
// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],
// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],
// The test environment that will be used for testing
// testEnvironment: "jest-environment-node",
// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
// Adds a location field to test results
// testLocationInResults: false,
// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],
testMatch: [
"**/test/cases/*.[jt]s?(x)"
],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "/node_modules/"
// ],
// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],
// This option allows the use of a custom results processor
// testResultsProcessor: undefined,
// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
// testURL: "http://localhost",
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
// timers: "real",
// A map from regular expressions to paths to transformers
// transform: undefined,
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "/node_modules/",
// "\\.pnp\\.[^\\/]+$"
// ],
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
// Indicates whether each individual test should be reported during the run
// verbose: undefined,
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],
// Whether to use watchman for file crawling
// watchman: true,
};
......@@ -46,7 +46,6 @@ TaosQuery.prototype.execute = async function execute() {
reject(err);
}
resolve(result)
});
return executionPromise;
}
......
......@@ -7,7 +7,8 @@
"test": "test"
},
"scripts": {
"test": "node test/test.js && node test/testMicroseconds.js && node test/testNanoseconds.js && node test/testUnsignedType.js && node test/testSchemalessInsert.js && node test/testJsonTag.js"
"test": "jest",
"catalog": "jest --json"
},
"repository": {
"type": "git",
......@@ -31,5 +32,8 @@
"ref-array-napi": "^1.2.1",
"ref-napi": "^1.5.2",
"ref-struct-napi": "^1.1.1"
},
"devDependencies": {
"jest": "^27.4.7"
}
}
此差异已折叠。
/**
* This is an util function will return the column info based on the create sql.
* @param {*} sql
* @returns Return an Array about the column names and column type.
*
*/
function getFeildsFromDll(sql) {
let fields = [];
let firstBracket = sql.indexOf('(');
let lastBracket = sql.lastIndexOf(')')
let metaStr = sql.slice(firstBracket, lastBracket + 1);
let splitTags = metaStr.split("tags");
splitTags.forEach((item, index, arr) => {
arr[index] = item.slice(1, item.length - 1)
})
splitTags.forEach((item) => {
let tmp = item.split(",");
tmp.forEach((item) => {
let newItem = item.trim();
let spaceInd = newItem.indexOf(' ', 1)
fields.push(newItem.slice(0, spaceInd));
fields.push(newItem.slice(spaceInd + 1, newItem.length))
})
})
return fields;
}
/**
* Based on the input array, it will generate sql that could be used to insert the data of array into the db.
* @param {*} tableName It could be the table name that you want to insert data.
* @param {*} stable If you want to using stable as template to create table automatically,
* set this to your stable name. Deault if '';
* @param {*} dataArr An Array of data that you want insert (it could be mutilple lines)
* @param {*} tagArr An Array used to store one sub table's tag info
* @param {*} numOfColumn The number of columns that the target table has.
* @returns Return an insert sql string.
*/
function buildInsertSql(tableName, stable = '', dataArr, tagArr = [], numOfColumn) {
let insertSql = "";
let dataPartial = "(";
let tagPart = "(";
dataArr.forEach((item, index) => {
// let item = dataArr[index];
if (typeof item == "string") {
dataPartial += '\'' + item + '\'';
} else {
dataPartial += item;
}
if ((index + 1) % numOfColumn == 0 && (index + 1) != dataArr.length) {
dataPartial += ")("
} else if ((index + 1) % numOfColumn == 0 && (index + 1) == dataArr.length) {
dataPartial += ")"
} else {
dataPartial += ","
}
})
if (stable != '') {
tagArr.forEach((item, index) => {
if (typeof item == "string") {
tagPart += '\'' + item + '\'';
} else {
tagPart += item;
}
if (index != tagArr.length - 1) {
tagPart += ",";
} else {
tagPart += ")";
}
})
}
if (stable == '') {
insertSql += `insert into ${tableName} values ${dataPartial};`
} else {
insertSql += `insert into ${tableName} using ${stable} tags ${tagPart} values ${dataPartial};`
}
return insertSql;
}
/**
* used to mapping the data type of an create clause into TDengine's datatype code
*/
const TDengineTypeCode = {
'null': 0,
'bool': 1,
'tinyint': 2,
'smallint': 3,
'int': 4,
'bigint': 5,
'float': 6,
'double': 7,
'binary': 8,
'timestamp': 9,
'nchar': 10,
'tinyint unsigned': 11,
'smallint unsigned': 12,
'int unsigned': 13,
'bigint unsigned': 14,
'json': 15,
}
/**
* Mapping the data type with corresponing size that has defined in tdengine
*/
const TDengineTypeBytes = {
'null': 0,
'bool': 1,
'tinyint': 1,
'smallint': 2,
'int': 4,
'bigint': 8,
'float': 4,
'double': 8,
'timestamp': 8,
'tinyint unsigned': 1,
'smallint unsigned': 2,
'int unsigned': 4,
'bigint unsigned': 8,
'json': 4096,
}
/**
* Used to create an array of taos feilds object.
* @param {*} arr This should be the return array from the method getFeildsFromDll()
* @returns Return an array of taosFeild Object
*/
function getFieldArr(arr) {
let feild = [];
for (let i = 0; i < arr.length;) {
let bracetPosi = arr[i + 1].indexOf('(');
let type = '';
let size = -1;
if (bracetPosi == -1) {
type = TDengineTypeCode[arr[i + 1]];
size = TDengineTypeBytes[arr[i + 1]];
}else{
type = TDengineTypeCode[arr[i + 1].slice(0, bracetPosi)];
size = Number(arr[i + 1].slice(bracetPosi + 1, arr[i + 1].indexOf(')')));
}
let fieldObj = {
name: arr[i].toLowerCase(),
type: type,
bytes: size
}
feild.push(fieldObj);
i = i + 2;
}
return feild;
}
/**
* Conbine arrays of data info and tag info together, and return a new array. This array construction is simmilar with query result
* from the tdengine by taos shell.This method only can be used by a subtable.
* @param {*} dataArr An array holds columns' data that will be insert into the db.
* @param {*} tagArr An array holds tags' data that is belong to a sub table.
* @param {*} numOfcolumn
* @returns return the an array of column data and tag data.
*/
function getResData(dataArr, tagArr, numOfcolumn) {
let resData = [];
dataArr.forEach((item, index) => {
resData.push(item);
if ((index + 1) % numOfcolumn == 0) {
tagArr.forEach((element) => {
resData.push(element);
}) ;
}
});
return resData;
}
module.exports = { getFeildsFromDll, buildInsertSql, getFieldArr, getResData };
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册