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

Convert test files js to ts #32

Closed
wants to merge 2 commits into from
Closed
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
51 changes: 51 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Node.js CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-
- name: Install dependencies
if: steps.yarn-cache-dir-path.outputs.cache-hit != 'true'
run: yarn install
- run: yarn lint
- run: yarn check-fmt
- run: yarn tsc
- run: yarn test-cover
env:
CI: true
- name: Coveralls Parallel
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.github_token }}
parallel: true
coverall:
needs: build
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.coveralls.yml

# nyc test coverage
.nyc_output
Expand All @@ -25,6 +26,7 @@ coverage

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
build/

# Dependency directories
node_modules
Expand All @@ -37,3 +39,12 @@ jspm_packages
.node_repl_history

.idea


# Yarn 2
.yarn/*
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ NODE_MODULES ?= "./node_modules"
NODE_MODULES_BIN ?= "${NODE_MODULES}/.bin"

FROM_VERSION ?= $(shell yarn run -s version)
EXAMPLE_FILES := $(shell find "examples" -name "*.js")

############## HELP ##############

Expand Down Expand Up @@ -55,3 +56,10 @@ release: ##@release generates a new release
@git commit -m "chore(v${RELEASE_VERSION}): bump version to ${RELEASE_VERSION}"
@git tag -a "v${RELEASE_VERSION}" -m "version ${RELEASE_VERSION}"
@git push origin v${RELEASE_VERSION}

examples: ##@examples run examples files
@echo "${YELLOW}start to run all examples files"
@if [ ! -d "build" ]; then yarn tsc; fi;\
for file in $(EXAMPLE_FILES); do echo "\n\nRun $${file}"; node $${file}; done;\

.PHONY: examples
47 changes: 47 additions & 0 deletions definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'none'

export type LogInstance = {
level?: LogLevel
time?: Date
namespace?: string
contextId?: string
message?: string
meta?: Record<string, unknown>
data?: unknown
}
export type Output = Pick<LogInstance, 'contextId' | 'meta' | 'data'>

export type NameSpaceConfig = {
regex?: RegExp
level?: number
}

export interface Logger {
trace: LogMethod
debug: LogMethod
info: LogMethod
warn: LogMethod
error: LogMethod
isLevelEnabled(level: string): boolean | undefined
}

export interface OutputAdapter {
(log: LogInstance): void
}

export interface LogMethod {
(contextId: string, message: string, data?: unknown): void
(message: string, data?: unknown): void
}

export interface Internal {
loggers?: Record<string, Logger | undefined>
namespaces?: NameSpaceConfig[]
levels?: LogLevel[]
level?: number
outputs?: OutputAdapter[]
globalContext?: Record<string, unknown>
isEnabled?(namespace: string, index: number): boolean
}

export type LogColor = 'red' | 'yellow' | 'blue' | 'white' | 'grey'
6 changes: 3 additions & 3 deletions examples/example1.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const logger = require('../index')
const logger = require('../build/index')

logger.setNamespaces('root:*')
logger.setLevel('debug')

const log = logger('root:testing')
const log = logger.createLogger('root:testing')
log.debug('sample message', {
foo: 'bar',
})
})
6 changes: 3 additions & 3 deletions examples/example2.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const logger = require('../index')
const logger = require('../build/index')

logger.setNamespaces('root:*')
logger.setLevel('debug')

const log = logger('root:testing')
const log = logger.createLogger('root:testing')
log.debug('ctxId', 'log with predefined context ID', {
foo: 'bar',
})
})
6 changes: 3 additions & 3 deletions examples/example3.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const logger = require('../index')
const logger = require('../build/index')

logger.setNamespaces('namespace:*')
logger.setLevel('debug')
//logger.setOutput(logger.outputs.json)

const log = logger('namespace:subNamespace')
log.debug('ctxId', 'Will be logged',{someData: 'someValue', someData2: 'someValue'})
const log = logger.createLogger('namespace:subNamespace')
log.debug('ctxId', 'Will be logged', { someData: 'someValue', someData2: 'someValue' })
6 changes: 3 additions & 3 deletions examples/example_context.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const logger = require('../index')
const logger = require('../build/index')

logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('*')
logger.setLevel('info')
logger.setGlobalContext({ version: '2.0.0', env: 'dev' })

const log = logger('namespace')
const log = logger.createLogger('namespace')

log.warn('message', { someData: 'someValue' })
log.warn('message', { someData: 'someValue' })
6 changes: 3 additions & 3 deletions examples/example_data.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const logger = require('../index')
const logger = require('../build/index')

logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('namespace:*')
logger.setLevel('info')

const log = logger('namespace:subNamespace')
const log = logger.createLogger('namespace:subNamespace')

log.warn('message', { someData: 'someValue' })
log.warn('message', { someData: 'someValue' })
6 changes: 3 additions & 3 deletions examples/example_pretty.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const logger = require('../index')
const logger = require('../build/index')

logger.setNamespaces('namespace:*')
logger.setLevel('debug')
logger.setOutput(logger.outputs.pretty)

const log = logger('namespace:subNamespace')
log.debug('ctxId', 'Will be logged',{someData: 'someValue', someData2: 'someValue'})
const log = logger.createLogger('namespace:subNamespace')
log.debug('ctxId', 'Will be logged', { someData: 'someValue', someData2: 'someValue' })
1 change: 1 addition & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'prettyoutput'
53 changes: 0 additions & 53 deletions index.d.ts

This file was deleted.

Loading