Skip to content

Commit

Permalink
Seperate test uploads (#2107)
Browse files Browse the repository at this point in the history
Fixes #2106

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **Bug Fixes**
- Updated configuration settings to ensure coverage data is treated
independently for multiple components, improving accuracy in reports.

- **New Features**
- Enhanced the GitHub Actions workflow with directory specifications for
Codecov uploads, clarifying the source of coverage reports.
- Added new steps for uploading coverage reports for various components,
ensuring distinct handling of each component's coverage.
- Updated testing scripts to enable actual test execution and coverage
reporting.
- Created a new `receiveLoginData` function to manage login requests
with structured logging for better traceability.
- Introduced a new `MockNPSMessage` for easier unit testing and
integration.

- **Refactor**
- Improved coverage configuration in the test settings by integrating
default exclusions, allowing for better management of test coverage.
- Simplified the test setup in `clientConnect.test.ts` by removing local
state management and utilizing an external database session management
function.
- Corrected import paths across various modules to enhance
maintainability and consistency.
  - Removed unnecessary mock functions to streamline testing strategy.
- Restructured module organization for better clarity and
maintainability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
drazisil authored Sep 5, 2024
1 parent ae383b9 commit 087b88f
Show file tree
Hide file tree
Showing 29 changed files with 425 additions and 526 deletions.
20 changes: 10 additions & 10 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,47 @@ flags:
database:
paths:
- packages/database/**
carryforward: true
carryforward: false
gateway:
paths:
- packages/gateway/**
carryforward: true
carryforward: false
lobby:
paths:
- packages/lobby/**
carryforward: true
carryforward: false
login:
paths:
- packages/login/**
carryforward: true
carryforward: false
patch:
paths:
- packages/patch/**
carryforward: true
carryforward: false
persona:
paths:
- packages/persona/**
carryforward: true
carryforward: false
shard:
paths:
- packages/shard/**
carryforward: true
carryforward: false
shared:
paths:
- packages/shared/**
carryforward: true
carryforward: false
transactions:
paths:
- packages/transactions/**
carryforward: true
carryforward: false
interfaces:
paths:
- packages/interfaces/**
carryforward: false
core:
paths:
- packages/core/**
carryforward: true
carryforward: false

component_management:
individual_components:
Expand Down
114 changes: 102 additions & 12 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,123 @@ jobs:
with:
node-version: 22.x
- name: Setup pnpm
uses: pnpm/action-setup@v4.0.0
uses: pnpm/action-setup@v4.0.0
- name: Install and test
run: |
pnpm install
make test
env:
CODECOV_UPLOAD_BUNDLE_TOKEN: ${{ secrets.CODECOV_UPLOAD_BUNDLE_TOKEN }}
- name: Codecov
- name: Codecov install cli
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
pip install --user pytest
pip install --user codecov-cli
- name: Codecov create comit and report
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose create-commit --fail-on-error
codecovcli --verbose create-report --fail-on-error
- name: Codecov upload test results
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli do-upload --report-type test_results --file mcos.junit.xml
codecovcli --verbose do-upload --fail-on-error --flag cli --name cli-${{ matrix.node-version }}
codecovcli --verbose do-upload --fail-on-error --flag connection --name connection-${{ matrix.node-version }}
codecovcli --verbose do-upload --fail-on-error --flag database --name database-${{ matrix.node-version }}
codecovcli --verbose do-upload --fail-on-error --flag gateway --name gateway-${{ matrix.node-version }}
codecovcli --verbose do-upload --fail-on-error --flag mcots --name mcots-${{ matrix.node-version }}
codecovcli --verbose do-upload --fail-on-error --flag nps --name nps-${{ matrix.node-version }}
codecovcli --verbose do-upload --fail-on-error --flag patch --name patch-${{ matrix.node-version }}
codecovcli --verbose do-upload --fail-on-error --flag shard --name shard-${{ matrix.node-version }}
codecovcli --verbose do-upload --fail-on-error --flag shared --name shared-${{ matrix.node-version }}
codecovcli --verbose do-upload --fail-on-error --flag shared-packets --name shared-packets-${{ matrix.node-version }}
- name: Codecov upload cli coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag cli --name cli --dir packages/cli
- name: Codecov upload connection coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag connection --name connection --dir packages/connection
- name: Codecov upload database coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag database --name database --dir packages/database
- name: Codecov upload gateway coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag gateway --name gateway --dir packages/gateway
- name: Codecov upload lobby coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag lobby --name lobby --dir packages/lobby
- name: Codecov upload login coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag login --name login --dir packages/login
- name: Codecov upload mcots coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag mcots --name mcots --dir packages/mcots
- name: Codecov upload nps coverageq
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag nps --name nps --dir packages/nps
- name: Codecov upload patch coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag patch --name patch --dir packages/patch
- name: Codecov upload persona coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag persona --name persona --dir packages/persona
- name: Codecov upload sessions coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag sessions --name sessions --dir packages/sessions
- name: Codecov upload shard coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag shard --name shard --dir packages/shard
- name: Codecov upload shared coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag shared --name shared --dir packages/shared
- name: Codecov upload shared-packets coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag shared-packets --name shared-packets --dir packages/shared-packets
- name: Codecov upload transactions coverage
if: ${{ always() }} # using always() to always run this step because i am uploading test results and coverage in one step
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecovcli --verbose do-upload --fail-on-error --flag transactions --name transactions --dir packages/transactions
- uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4
with:
Expand Down
118 changes: 60 additions & 58 deletions packages/cli/ConsoleThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,71 +12,73 @@ import { ServerError } from "rusty-motors-shared";
* Console thread
*/
export class ConsoleThread extends SubThread {
parentThread: Gateway;
/**
* @param {object} options
* @param {Gateway} options.parentThread The parent thread
* @param {import("pino").Logger} options.log The logger
*/
constructor({
parentThread,
log,
}: {
parentThread: Gateway;
log: import("pino").Logger;
}) {
super("ReadInput", log, 100);
if (parentThread === undefined) {
throw new ServerError(
"parentThread is undefined when creating ReadInput",
);
}
this.parentThread = parentThread;
}
parentThread: Gateway;
/**
* @param {object} options
* @param {Gateway} options.parentThread The parent thread
* @param {import("pino").Logger} options.log The logger
*/
constructor({
parentThread,
log,
}: {
parentThread: Gateway;
log: import("pino").Logger;
}) {
super("ReadInput", log, 100);
if (parentThread === undefined) {
throw new ServerError(
"parentThread is undefined when creating ReadInput",
);
}
this.parentThread = parentThread;
}

/** @param {import("../interfaces/index.js").KeypressEvent} key */
handleKeypressEvent(key: import("../interfaces/index.js").KeypressEvent) {
const keyString = key.sequence;
/** @param {import("../interfaces/index.js").KeypressEvent} key */
handleKeypressEvent(
key: import("../shared/src/interfaces.js").KeypressEvent,
) {
const keyString = key.sequence;

if (keyString === "x") {
this.emit("userExit");
}
if (keyString === "x") {
this.emit("userExit");
}

if (keyString === "r") {
this.emit("userRestart");
}
if (keyString === "r") {
this.emit("userRestart");
}

if (keyString === "?") {
this.emit("userHelp");
}
}
if (keyString === "?") {
this.emit("userHelp");
}
}

override init() {
super.init();
emitKeypressEvents(process.stdin);
if (process.stdin.isTTY) {
process.stdin.setRawMode(true);
}
override init() {
super.init();
emitKeypressEvents(process.stdin);
if (process.stdin.isTTY) {
process.stdin.setRawMode(true);
}

this.log.info("GatewayServer started");
this.log.info("Press x to quit");
this.log.info("GatewayServer started");
this.log.info("Press x to quit");

process.stdin.resume();
process.stdin.on("keypress", (str, key) => {
if (key !== undefined) {
this.handleKeypressEvent(key);
}
});
}
process.stdin.resume();
process.stdin.on("keypress", (_str, key) => {
if (key !== undefined) {
this.handleKeypressEvent(key);
}
});
}

override run() {
// Intentionally left blank
}
override run() {
// Intentionally left blank
}

stop() {
// Remove all listeners from stdin, preventing further input
process.stdin.removeAllListeners("keypress");
process.stdin.pause();
super.shutdown();
}
stop() {
// Remove all listeners from stdin, preventing further input
process.stdin.removeAllListeners("keypress");
process.stdin.pause();
super.shutdown();
}
}
3 changes: 1 addition & 2 deletions packages/connection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"lint": "eslint .",
"format": "npm prettier --write .",
"test:db": "vitest run --coverage",
"test:diabled": "dotenvx run -f ../../.env -- pnpm run test:db",
"test": "echo 'No tests yet' && exit 0"
"test": "dotenvx run -f ../../.env -- pnpm run test:db"
},
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"check": "tsc",
"lint": "eslint .",
"format": "npx prettier --write .",
"test": "echo \"Error: no test specified\" && exit 0",
"test": "vitest run --coverage",
"test:crypto": "pnpm node --openssl-legacy-provider node_modules/vitest/vitest.mjs run --coverage"
},
"keywords": [],
Expand Down
Loading

0 comments on commit 087b88f

Please sign in to comment.