Skip to content

Commit

Permalink
ts- testing (Real-Dev-Squad#1330)
Browse files Browse the repository at this point in the history
* ts- testing

* test: recursive search for test on linux dist

* TEST: add js in mocharc extension

* feat: idk what i did here

* empty

* add prettier fix

* run lint fix

* feat: this is annoying

---------

Co-authored-by: Sunny Sahsi <[email protected]>
Co-authored-by: ritikjaiswal75 <[email protected]>
  • Loading branch information
3 people authored Jul 27, 2023
1 parent 5c00318 commit 32cc9f2
Show file tree
Hide file tree
Showing 16 changed files with 1,155 additions and 773 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ module.exports = {
// Prettier for formatting
"prettier/prettier": "error",
},
ignorePatterns: ["public/*"],
ignorePatterns: ["public/*", "dist/*"],
};
65 changes: 32 additions & 33 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ name: "CodeQL"

on:
push:
branches: [ "develop", main ]
branches: ["develop", main]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "develop" ]
branches: ["develop"]
schedule:
- cron: '15 19 * * 5'
- cron: "15 19 * * 5"

jobs:
analyze:
Expand All @@ -32,43 +32,42 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
language: ["javascript"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
node-version: [18.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: yarn
- run: yarn test
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: yarn
- run: yarn test
4 changes: 3 additions & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
* Info: https://mochajs.org/#configuring-mocha-nodejs
*/
module.exports = {
timeout: '5000',
timeout: "5000",
extension: ["ts", "js"],
require: "ts-node/register",
};
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Real Dev Squad API Changelog

All notable changes to this project will be documented in this file.

<!--
Expand All @@ -11,12 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- Sample changelog
## [Project Version] - YYYY-MM-DD
### Added
### Added
- Feature name added
### Changed
### Deprecated
### Deprecated
### Removed
### Fixed
### Fixed
### Security
-->
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ yarn validate-setup

Head over to [TDD Tests Files List](scripts/tests/tdd-files-list.txt), and add the list of your new (or old) test files.

> You can use wildcard '*' in the filepaths
> You can use wildcard '\*' in the filepaths
Run TDD in watch mode. Exiting this command will print the coverage report. Try to achieve 100% coverage.

Expand Down
2 changes: 1 addition & 1 deletion docs/backendFlow.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Tests are written using:
- `scripts` : For different scripts needed for development & others
- `Dependencies` : Modules needed for the project to work/ be functional
- `devDependencies` : Dependencies only needed for the devlopment purpose

<br>

---
Expand Down
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node server.js",
"dev": "cross-env NODE_ENV=development nodemon server.js",
"start": "node ./dist/server.js",
"tsc": "tsc",
"postinstall": "yarn run tsc",
"dev": "cross-env NODE_ENV=development ts-node-dev server.js",
"lint": "eslint .",
"lint-fix": "eslint . --fix",
"validate-setup": "node scripts/validateSetup.js",
Expand Down Expand Up @@ -38,7 +40,13 @@
"winston": "^3.3.3"
},
"devDependencies": {
"chai": "^4.3.4",
"@types/chai": "^4.3.5",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.3",
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.3",
"@typescript-eslint/parser": "^6.1.0",
"chai": "^4.3.7",
"chai-http": "^4.3.0",
"cross-env": "^7.0.3",
"eslint": "^8.0.0",
Expand All @@ -52,13 +60,16 @@
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-standard": "^4.1.0",
"firebase-tools": "^11.28.0",
"mocha": "^10.0.0",
"mocha": "^10.2.0",
"nock": "^13.0.11",
"nodemon": "^2.0.7",
"nyc": "^15.1.0",
"pre-commit": "^1.2.2",
"prettier": "^2.5.1",
"sinon": "^15.0.0"
"sinon": "^15.0.0",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"typescript": "^5.1.6"
},
"engines": {
"node": "18.x"
Expand Down
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
]
"extends": ["config:base"]
}
2 changes: 1 addition & 1 deletion scripts/tests/tdd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export NODE_ENV='test'
echo '\nStart firestore emulator and run tests during TDD only:\n'

# Read config meanings here: https://github.com/istanbuljs/nyc#common-configuration-options
firebase emulators:exec "nyc --check-coverage=true --all=false --skip-full=true --per-file=true mocha --watch $allPaths"
firebase emulators:exec "nyc --check-coverage=true --all=false --skip-full=true --recursive --per-file=true mocha --watch $allPaths"

# Aim to achieve these results when you exit:
# =============================== Coverage summary ===============================
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/testUnit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ json=$(node -e "console.log(require('config').get('firestore'))")
project_id=$(echo $json | grep -o '"project_id":[^,}]*' | cut -d':' -f2 | tr -d '"' | tr -d '[:space:]')

echo 'Start firestore emulator and run unit tests:'
firebase emulators:exec 'nyc --x=controllers --x=test --x=docs --x=mockdata mocha test/unit/**' --project=$project_id
firebase emulators:exec 'nyc --x=controllers --x=test --x=docs --recursive --x=mockdata mocha test/unit/**' --project=$project_id
10 changes: 0 additions & 10 deletions test/utils/user.js

This file was deleted.

9 changes: 9 additions & 0 deletions test/utils/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { expect } from "chai";

function assertUserIds(users: any, ids: any) {
ids.forEach((id: number | string) => {
/* eslint-disable no-unused-expressions */
expect(users.some((user: { id: any }) => user.id === id)).to.be.true;
});
}
module.exports = { assertUserIds };
Loading

0 comments on commit 32cc9f2

Please sign in to comment.