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

chore: assertion enhancements and husky support #34

Open
wants to merge 1 commit 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
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint

on:
pull_request:
branches: ['master']
push:
branches: ['master']

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['20.10.0']
defaults:
run:
working-directory: .
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install libraries
run: npm install
- name: Run linter
run: npm run lint
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test

on:
pull_request:
branches: ['master']
push:
branches: ['master']

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['20.10.0']
defaults:
run:
working-directory: .
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install libraries
run: npm install
- name: Run test
run: npm test
26 changes: 26 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
if ! head -1 "$1" | grep -qE "^(feat|fix|ci|chore|docs|test|style|refactor|perf|build|revert)(\(.+?\))?: .{1,}$"; then
echo "" >&1
echo -e "\033[1;31m*********** Invalid Git Commit Message ***********\033[0m" >&1
echo -e "\033[1;31m correct format: <type>: <subject> \033[0m" >&1
echo -e "\033[1;31m example: docs: update README \033[0m" >&1
echo "" >&1
echo -e "\033[1;33m Type: \033[0m" >&1
echo -e "\033[1;33m build: \033[0m Changes that affect the build system or external dependencies (example scopes: webpack, karma, npm)" >&1
echo -e "\033[1;33m ci: \033[0m Changes to our CI configuration files and scripts (example scopes: azuredevops.yaml, Travis, Circle)" >&1
echo -e "\033[1;33m docs: \033[0m Documentation only changes" >&1
echo -e "\033[1;33m feat: \033[0m A new feature" >&1
echo -e "\033[1;33m fix: \033[0m A bug fix" >&1
echo -e "\033[1;33m perf: \033[0m A code change that improves performance" >&1
echo -e "\033[1;33m refactor: \033[0m A code change that neither fixes a bug nor adds a feature" >&1
echo -e "\033[1;33m style: \033[0m Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)" >&1
echo -e "\033[1;33m test: \033[0m Adding missing tests or correcting existing tests" >&1
echo ""
echo -e "\033[1;33m Subject: \033[0m" >&1
echo -e " A very short description of the change in one line." >&1
echo ""
exit 1
fi
if ! head -1 "$1" | grep -qE "^.{1,88}$"; then
echo "Aborting commit. Your commit message is too long." >&2
exit 1
fi
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npm run lint
npm test
2 changes: 2 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npm run lint
npm test
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"compile": "npm run clean && tsc",
"prepublishOnly": "npm run compile",
"test": "mocha --config '.mocha.yml'",
"lint": "tslint src/**/*.ts"
"lint": "tslint src/**/*.ts",
"prepare": "husky"
},
"repository": {
"type": "git",
Expand All @@ -36,6 +37,7 @@
"@types/mocha": "^8.2.2",
"@types/node": "^15.12.1",
"chai": "^4.3.4",
"husky": "^9.0.7",
"mocha": "^8.4.0",
"mongoose": "^6.2.10",
"rimraf": "^3.0.2",
Expand All @@ -47,4 +49,4 @@
"lodash": "^4.17.21",
"luxon": "^1.27.0"
}
}
}
10 changes: 7 additions & 3 deletions src/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ class Tester {
assert.isOk(parsed.filter['author.firstName'] instanceof RegExp);
assert.isOk(parsed.limit === 100);
assert.isOk(parsed.skip === 50);
assert.isNotNull(parsed.sort);
assert.isNotNull(parsed.select);
assert.isNotNull(parsed.populate);
assert.deepEqual(parsed.sort, { timestamp: -1 });
assert.deepEqual(parsed.select, { name: 1});
assert.deepEqual([{ path: 'children' }], parsed.populate);
}

@test('should parse populate query')
Expand Down Expand Up @@ -185,5 +185,9 @@ class Tester {
qry = 'filter={"$and": ["${isActive}", {"customer": "VDF"}]}';
parsed = parser.parse(qry, preDefined);
assert.isNotNull(parsed.filter['$and'][0].status);
assert.deepEqual(parsed.filter['$and'][0], {
status: { $in: ['In Progress', 'Pending'] }
});
assert.deepEqual(parsed.filter['$and'][1], { customer: 'VDF' });
}
}