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

Set up testing environment and coverage integration #25

Merged
merged 20 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
68 changes: 68 additions & 0 deletions .github/workflows/irltest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: IRL Test

on:
## Due to YouTube bot detection when downloading YouTube videos,
## this workflow will not be triggered automatically until we address it.
## Still if we run manually, it will returns an error.
# pull_request:
# branches: [ "master" ]
# schedule:
# - cron: '0 6,12,18,0 * * *'
workflow_dispatch:
inputs:
traceDeprecation:
description: 'Show stack traces on deprecations'
type: boolean
required: false
traceUncaught:
description: 'Show stack traces on behind uncaught exceptions'
type: boolean
required: false
traceWarnings:
description: 'Show stack traces on warnings'
type: boolean
required: false
traceExit:
description: 'Show stack traces when an environment exits'
type: boolean
required: false
tracePromises:
description: 'Show stack traces on promises'
type: boolean
required: false

env:
TRACE_DEPRECATION: ${{ inputs.traceDeprecation && 'trace-deprecation' || '' }}
TRACE_UNCAUGHT: ${{ inputs.traceUncaught && 'trace-uncaught' || '' }}
TRACE_WARNINGS: ${{ inputs.traceWarnings && 'trace-warnings' || '' }}
TRACE_EXIT: ${{ inputs.traceExit && 'trace-exit' || '' }}
TRACE_PROMISES: ${{ inputs.tracePromises && 'trace-promise' || '' }}

jobs:
irltest:
name: ${{ matrix.os }} / Node ${{ matrix.node-ver }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
node-ver: [ 18.x, 20.x ]

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js / ${{ matrix.node-ver }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-ver }}
cache: 'npm'
- name: Clean install the project
run: npm ci
- name: Run IRL Test
run: >
npm run test:irl --
--node-option ${{ env.TRACE_DEPRECATION }}
--node-option ${{ env.TRACE_UNCAUGHT }}
--node-option ${{ env.TRACE_WARNINGS }}
--node-option ${{ env.TRACE_EXIT }}
--node-option ${{ env.TRACE_PROMISES }}
30 changes: 30 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Unit Test

on:
push:
paths: [ "**/test/**/*" ]
pull_request:
branches: [ "master" ]

jobs:
unittest:
name: ${{ matrix.os }} / Node ${{ matrix.node-ver }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
node-ver: [ 18.x, 20.x ]

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js / ${{ matrix.node-ver }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-ver }}
cache: 'npm'
- name: Clean install the project
run: npm ci
- name: Run unit tests
run: npm run test:unit
10 changes: 10 additions & 0 deletions .nycrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"all": false,
"check-coverage": true,
"reporter": "text",
"report-dir": "./coverage",
"branches": 50,
"functions": 65,
"lines": 50,
"statements": 50
}
33 changes: 25 additions & 8 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
/**
* ESLint flat configuration for production environment.
*/

'use strict';

const globals = require('globals');
const js = require('@eslint/js');
const mochaPlugin = require('eslint-plugin-mocha');

/** @type {import('eslint').Linter.Config} */
module.exports = [
{
ignores: [
'**/docs/',
'config/example/**.{mjs,js,json}',
'**/test/',
'**/coverage/',
'jsdoc.config.js',
'eslint.config.test.js'
]
},

js.configs.recommended,
mochaPlugin.configs.flat.recommended,

{
files: [
'index.js',
'lib/**/*.js',
'eslint.config.js'
],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'commonjs',
Expand All @@ -16,7 +39,7 @@ module.exports = [
}
},
linterOptions: {
reportUnusedDisableDirectives: 'error'
reportUnusedDisableDirectives: true
},
rules: {
strict: [ 'error', 'safe' ],
Expand Down Expand Up @@ -50,12 +73,6 @@ module.exports = [
curly: [ 'error', 'multi-line', 'consistent' ],
'no-else-return': ['error'],
'default-param-last': ['error'],
},
ignores: [
'jsdoc.*',
'jsdoc.config.*',
'docs/**',
'config/example/**'
]
}
}
];
45 changes: 45 additions & 0 deletions eslint.config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* ESLint flat configuration for test environment.
*/

'use strict';

const globals = require('globals');
const mochaPlugin = require('eslint-plugin-mocha');
const baseConfig = require('./eslint.config.js');

module.exports = [
{
ignores: [
'**/docs/',
'**/coverage/',
'config/example/**.{mjs,js,json}',
'lib/',
'index.js',
'eslint.config.*'
]
},

mochaPlugin.configs.flat.recommended,

{
files: [
'**/test/'
],
languageOptions: {
ecmaVersion: 2021,
sourceType: 'module',
globals: {
...globals.es2021,
...globals.node,
...globals.mocha
}
},
linterOptions: {
reportUnusedDisableDirectives: true
},
rules: {
...baseConfig[baseConfig.length - 1].rules
}
}
];
2 changes: 0 additions & 2 deletions jsdoc.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @author Ryuu Mitsuki (https://github.com/mitsuki31)
*/

/* global module:readonly */

'use strict';

module.exports = {
Expand Down
Loading