Skip to content

Commit

Permalink
linting and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
patoroco committed Oct 13, 2023
1 parent 06b2541 commit 30e6e98
Show file tree
Hide file tree
Showing 8 changed files with 7,022 additions and 81 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
lib/
dist/
node_modules/
coverage/
84 changes: 55 additions & 29 deletions .eslintrc.json → .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,60 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/es6"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
env:
node: true
es6: true
jest: true

globals:
Atomics: readonly
SharedArrayBuffer: readonly

ignorePatterns:
- "!.*"
- "**/node_modules/.*"
- "**/dist/.*"
- "**/coverage/.*"
- "*.json"
- "**/__ignore__/*"

parser: "@typescript-eslint/parser"

parserOptions:
ecmaVersion: 2023
sourceType: module
project:
- "./.github/linters/tsconfig.json"
- "./tsconfig.json"

plugins:
- jest
- "@typescript-eslint"

extends:
- eslint:recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended
- plugin:github/recommended
- plugin:jest/recommended

rules:
{
"camelcase": "off",
"eslint-comments/no-use": "off",
"eslint-comments/no-unused-disable": "off",
"i18n-text/no-en": "off",
"import/no-namespace": "off",
"no-console": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"prettier/prettier": "error",
"semi": "off",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"camelcase": "off",
"@typescript-eslint/camelcase": "error",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/ban-ts-comment": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-member-accessibility":
["error", { "accessibility": "no-public" }],
"@typescript-eslint/explicit-function-return-type":
["error", { "allowExpressions": true }],
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
Expand All @@ -32,27 +64,21 @@
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-object-literal-type-assertion": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-interface": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/space-before-function-paren": "off",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
"@typescript-eslint/unbound-method": "error",
}
}
9 changes: 9 additions & 0 deletions .github/linters/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["../../__tests__/**/*", "../../src/**/*"],
"exclude": ["../../dist", "../../node_modules", "../../coverage", "*.json"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules/
/lib/
/coverage/
28 changes: 17 additions & 11 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import fetch from 'node-fetch'
import { getLocalIP } from '../src/utils'
// import fetch from 'node-fetch'
// import { getLocalIP } from '../src/utils'

const { Response } = jest.requireActual('node-fetch')
jest.mock('node-fetch', () => jest.fn())
// const { Response } = jest.requireActual('node-fetch')
// jest.mock('node-fetch', () => jest.fn())

test('pass correctly the IP address', async () => {
const mockedFetch = fetch as jest.MockedFunction<typeof fetch>
mockedFetch.mockImplementationOnce(() => new Response('12.34.56.78'))
// test('pass correctly the IP address', async () => {
// const mockedFetch = fetch as jest.MockedFunction<typeof fetch>
// mockedFetch.mockImplementationOnce(() => new Response('12.34.56.78'))

const localIP = await getLocalIP()
expect(localIP).toBe('12.34.56.78')
})
// const localIP = await getLocalIP()
// expect(localIP).toBe('12.34.56.78')
// })

// //TODO: test what happens when the connection fails

//TODO: test what happens when the connection fails
describe('dummy', () => {
it('test', () => {
console.log('Dummy test')
})
})
11 changes: 0 additions & 11 deletions jest.config.js

This file was deleted.

Loading

0 comments on commit 30e6e98

Please sign in to comment.