Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: v3.1.0-beta.1 #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -53,7 +53,6 @@ jobs:

- name: Publish NPM
run: |
cd dist
npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [18.x]

steps:
- name: Check out repository code
Expand Down Expand Up @@ -38,4 +38,4 @@ jobs:
- name: Unit Test
run: |
npm install --unsafe-perm
npm run coverage
npm run test
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
node_modules
dist
.tmp
package-lock.json
.DS_Store
.nyc_output
coverage
build
.vscode

dist/
lib/
build/
types/
11 changes: 0 additions & 11 deletions .mocharc.json

This file was deleted.

10 changes: 0 additions & 10 deletions .mocharc.nyc.json

This file was deleted.

59 changes: 58 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,58 @@
build
# Cortex
neurons
cortex_modules
.cortex

# Numerous always-ignore extensions
*.bak
*.patch
*.diff
*.err

# temp file for git conflict merging
*.orig
*.log
*.rej
*.swo
*.swp
*.zip
*.vi
*~
*.sass-cache
*.tmp.html
*.dump

# OS or Editor folders
.DS_Store
._*
.cache
.project
.settings
.tmproj
*.esproj
*.sublime-project
*.sublime-workspace
nbproject
thumbs.db
*.iml

# Folders to ignore
.hg
.svn
.CVS
.idea
.vscode
.gitignore
.babelrc*
.eslint*
.prettierrc*
.husky
.github
node_modules/

# Project files or folders to ignore
src/
tools/
coverage/
specs/
.nebula-up/
26 changes: 26 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dynamicImport": true
},
"loose": false,
"externalHelpers": true,
"keepClassNames": false
},
"env": {
"targets": {
"node": "17"
},
"mode": "usage",
"coreJs": "3.33.1",
"include": ["esnext.symbol.dispose", "esnext.symbol.async-dispose"]
},
"module": {
"type": "commonjs"
},
"minify": false
}
16 changes: 8 additions & 8 deletions tests/native.test.ts → __tests__/native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* Created by Wu Jian Ping on - 2021/02/09.
*/

import { expect } from 'chai'
import { bytesToLongLongString, hash64 } from '../dist'
import { describe, expect, test } from '@jest/globals';
import { bytesToLongLongString, hash64 } from '../src/native'

describe('native', () => {
it('bytesToLongLongString', () => {
test('bytesToLongLongString', () => {
const s = '-7897618527020261406'
const buffer = [146, 102, 5, 203, 5, 105, 223, 226]
expect(bytesToLongLongString(buffer)).equal(s)
expect(bytesToLongLongString(buffer)).toBe(s)
})

it('hash64', () => {
test('hash64', () => {
const testData = [
{ keyNo: 'f10011b64aa4e7503cd45a7fdc24387b', a: '2852836996923339651', b: '-6853534673140605817' },
{ keyNo: 'f1bc319830aa4bd525b6b211fc128e5e', a: '-6331077761356739522', b: '6750279366282124699' },
Expand All @@ -29,11 +29,11 @@ describe('native', () => {
{ keyNo: '5608c68f0f84a28a5c8c0479ebbd69c1', a: '8004344832703457518', b: '4306029215693896848' },
{ keyNo: '科技型企业', a: '-6865176517154056019', b: '8588244832922351093' }
]

for (const sample of testData) {
const data = hash64(sample.keyNo)
expect(data[0]).equal(sample.a)
expect(data[1]).equal(sample.b)
expect(data[0]).toBe(sample.a)
expect(data[1]).toBe(sample.b)
}
})
})
108 changes: 108 additions & 0 deletions __tests__/nebula.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* eslint-disable max-len */
/**
* Created by Wu Jian Ping on - 2021/06/09.
*/

import createClient, { type ClientOption } from '../src';
import { describe, expect, test } from '@jest/globals';

const defaultClientOption: ClientOption = {
servers: ['127.0.0.1:9669'],
userName: 'root',
password: 'nebula',
space: 'nebula_node',
pingInterval: 5000,
poolSize: 1
}

const executeCmd = async (cmd: string, clientOption = defaultClientOption) => {
const client = createClient(clientOption);
const response = await client.execute(cmd);
return {
response,
async [Symbol.asyncDispose]() {
await client.close();
},
};
};

const testCases = [
{
name: 'getSubgraph',
cmd: 'get subgraph with prop 2 steps from "p001" yield vertices as nodes, edges as relationships',
valid: (res: any) => {
expect(res.data?.nodes?.length).toBeGreaterThan(0);
expect(res.data?.relationships?.length).toBeGreaterThan(0);
},
},
{
name: 'fetProps',
cmd: 'fetch prop on company "c001" yield properties(vertex) as node',
valid: (res: any) => {
expect(res.data?.node?.length).toBeGreaterThan(0);
},
},
{
name: 'goFrom',
cmd: 'go from "c001" over employee yield properties($^) as a, properties($$) as b, properties(edge) as p',
valid: (res: any) => {
expect(res.data?.a?.length).toBeGreaterThan(0);
expect(res.data?.b?.length).toBeGreaterThan(0);
expect(res.data?.p?.length).toBeGreaterThan(0);
},
},
{
name: 'findNoloopPath',
cmd: 'find noloop path with prop from "p001" to "p002" over * yield path as p',
valid: (res: any) => {
expect(res.data?.p?.length).toBeGreaterThan(0);
},
},
{
name: 'returnList',
cmd: 'RETURN list[1, 2, 3] AS a',
valid: (res: any) => {
expect(res.data?.a).toStrictEqual([[1, 2, 3]]);
},
},
{
name: 'unwindList',
cmd: 'UNWIND list[list[1, 2, 3], list[2, 3, 4]] as a RETURN a',
valid: (res: any) => {
expect(res.data?.a).toStrictEqual([
[1, 2, 3],
[2, 3, 4],
]);
},
},
{
name: 'returnSet',
cmd: 'RETURN set{1, 2, 3} AS a',
valid: (res: any) => {
expect(res.data?.a?.length).toEqual(1);
expect(res.data?.a[0]?.length).toEqual(3);
},
},
{
name: 'returnMap',
cmd: 'RETURN map{a: LIST[1,2], b: SET{1,2,1}, c: "hee"} as a',
valid: (res: any) => {
expect(res.data?.a?.length).toEqual(1);
expect(res.data?.a[0]?.a).toStrictEqual([1, 2]);
expect(res.data?.a[0]?.b?.length).toEqual(2);
expect(res.data?.a[0]?.c).toEqual('hee');
},
},
{
name: 'explain',
cmd: 'EXPLAIN format="dot" match (v) return v limit 3',
valid: (res: any) => {},
},
];

describe('nebula', () => testCases.forEach((testCase) => {
test(testCase.name, async () => {
await using result = await executeCmd(testCase.cmd);
testCase.valid(result.response);
});
}));
File renamed without changes.
4 changes: 4 additions & 0 deletions __tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"include": ["./**/*.ts"],
}
75 changes: 0 additions & 75 deletions babel.config.json

This file was deleted.

10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest'],
},
roots: ["<rootDir>/src/", "<rootDir>/__tests__/"],
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: ["**/*.ts", "!**/*.d.ts", "!**/node_modules/**"],
};
Loading