Skip to content

Commit

Permalink
add nodejs with typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
bullishgopher committed Nov 14, 2023
1 parent 1759305 commit 4f26a6d
Show file tree
Hide file tree
Showing 14 changed files with 3,521 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false

[*.{js,json,ts,mts,yml,yaml}]
indent_size = 2
indent_style = space
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/**/*.js
27 changes: 27 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"env": {
"browser": false,
"es6": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module",
"ecmaVersion": 2020
},
"plugins": ["@typescript-eslint", "jest"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"prettier"
],
"rules": {
// The following rule is enabled only to supplement the inline suppression
// examples, and because it is not a recommended rule, you should either
// disable it, or understand what it enforces.
// https://typescript-eslint.io/rules/explicit-function-return-type/
"@typescript-eslint/explicit-function-return-type": "warn"
}
}
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: [jsynowiec]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
17 changes: 17 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Node.js CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: volta-cli/action@v1
- run: npm ci --no-audit
- run: npm run lint --if-present
- run: npm test
- run: npm run build --if-present
env:
CI: true
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,13 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# VS Code
.vscode
!.vscode/tasks.js

# JetBrains IDEs
.idea/

# Misc
.DS_Store
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"singleQuote": true,
"trailingComma": "all",
"overrides": [
{
"files": ["*.ts", "*.mts"],
"options": {
"parser": "typescript"
}
}
]
}
42 changes: 42 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Delays, greeter } from '../src/main.js';

describe('greeter function', () => {
const name = 'John';
let hello: string;

let timeoutSpy: jest.SpyInstance;

// Act before assertions
beforeAll(async () => {
// Read more about fake timers
// http://facebook.github.io/jest/docs/en/timer-mocks.html#content
// Jest 27 now uses "modern" implementation of fake timers
// https://jestjs.io/blog/2021/05/25/jest-27#flipping-defaults
// https://github.com/facebook/jest/pull/5171
jest.useFakeTimers();
timeoutSpy = jest.spyOn(global, 'setTimeout');

const p: Promise<string> = greeter(name);
jest.runOnlyPendingTimers();
hello = await p;
});

// Teardown (cleanup) after assertions
afterAll(() => {
timeoutSpy.mockRestore();
});

// Assert if setTimeout was called properly
it('delays the greeting by 2 seconds', () => {
expect(setTimeout).toHaveBeenCalledTimes(1);
expect(setTimeout).toHaveBeenLastCalledWith(
expect.any(Function),
Delays.Long,
);
});

// Assert greeter result
it('greets a user with `Hello, {name}` message', () => {
expect(hello).toBe(`Hello, ${name}`);
});
});
18 changes: 18 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
testEnvironment: 'node',
preset: 'ts-jest/presets/default-esm',
transform: {
'^.+\\.m?[tj]s?$': ['ts-jest', { useESM: true }],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.(m)?js$': '$1',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(m)?ts$',
coverageDirectory: 'coverage',
collectCoverageFrom: [
'src/**/*.ts',
'src/**/*.mts',
'!src/**/*.d.ts',
'!src/**/*.d.mts',
],
};
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "wallet-watch-bot",
"version": "0.1.0",
"description": "Sends a message to the discord channel when a transaction occurs for a specified Ethereum address",
"type": "module",
"engines": {
"node": ">= 18.12 <19"
},
"devDependencies": {
"@types/jest": "~29.5",
"@types/node": "~18",
"@typescript-eslint/eslint-plugin": "~6.2",
"@typescript-eslint/parser": "~6.2",
"eslint": "~8.46",
"eslint-config-prettier": "~9.0",
"eslint-plugin-jest": "~27.2",
"jest": "~29.6",
"prettier": "~3.0",
"rimraf": "~5.0",
"ts-api-utils": "~1.0",
"ts-jest": "~29.1",
"typescript": "~5.1"
},
"scripts": {
"start": "node build/src/main.js",
"clean": "rimraf coverage build tmp",
"prebuild": "npm run lint",
"build": "tsc -p tsconfig.json",
"build:watch": "tsc -w -p tsconfig.json",
"build:release": "npm run clean && tsc -p tsconfig.release.json",
"lint": "eslint . --ext .ts --ext .mts",
"test": "jest --coverage",
"prettier": "prettier --config .prettierrc --write .",
"test:watch": "jest --watch"
},
"author": "Jakub Synowiec <[email protected]>",
"license": "Apache-2.0",
"dependencies": {
"tslib": "~2.6"
},
"volta": {
"node": "18.12.1"
}
}
Loading

0 comments on commit 4f26a6d

Please sign in to comment.