Skip to content

Commit

Permalink
Enhance test suites, improve coverage, and refactor error handling (#44)
Browse files Browse the repository at this point in the history
- f825834 - ci(irltest): Remove inputs for workflow dispatch
- 9048231 - ci(coverage): Add step to set up FFmpeg
- dcc6b38 - ci(irltest): Add step to set up FFmpeg
- f0b51fd - ci: Streamline coverage workflow and re-enable IRL tests
- f2d68ec - chore(pkg): Update the script for collecting coverage
- 2fe6eea - chore(eslint): Ignore the `.mocharc.js` file
- adb0245 - fix(lint): Address several lint issues
- c96e168 - chore(nyc): Enforce coverage checks and update NYC config
- 1132e9d - test(irl): Refactor integration tests and fix error handling
- 78c929d - test(ytmp3): Add test suite for `ytmp3` module
- 61db2b6 - test(audioconv): Add unit tests for `convertAudio`
- 1e5d2ef - test(audioconv): Enhance test suites and coverage
- 8b095f9 - test(config): Enhance test suite and coverage
- ec54aa7 - test(utils): Enhance tests for `ProgressBar` and log creation
- 43c89e5 - test(url-utils): Improve test coverage and validation checks

Signed-off-by: Ryuu Mitsuki <dhefam31@gmail.com>
  • Loading branch information
mitsuki31 committed Aug 27, 2024
2 parents b91485e + f825834 commit ce987ff
Show file tree
Hide file tree
Showing 15 changed files with 1,021 additions and 148 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v3
id: setup-ffmpeg
with:
ffmpeg-version: release
linking-type: static
architecture: x64
github-token: ${{ github.server_url == 'https://github.com' && github.token || '' }}
- name: Clean install the project
run: npm ci
- name: Run coverage
# Currently only run coverage for unit tests
run: npx nyc npm run test:unit
run: npm run coverage
- name: Upload coverage
if: ${{ github.actor != 'dependabot[bot]' || github.actor != 'github-actions[bot]' }}
uses: codecov/codecov-action@v4
Expand Down
54 changes: 13 additions & 41 deletions .github/workflows/irltest.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
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 * * *'
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:
Expand All @@ -56,13 +25,16 @@ jobs:
with:
node-version: ${{ matrix.node-ver }}
cache: 'npm'
- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v3
id: setup-ffmpeg
with:
ffmpeg-version: release
linking-type: static
architecture: x64
github-token: ${{ github.server_url == 'https://github.com' && github.token || '' }}
- 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 }}
npm run test:irl
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Unit Test

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

Expand Down
33 changes: 33 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = {
// Executions
bail: false,
parallel: false,
jobs: 1,
retries: 0,
color: true,
reporter: 'spec',
'node-option': [],
// Diffs
diff: false,
'inline-diffs': true,
'full-trace': false, // Enable this if want to more verbose in debugging
// Files
recursive: true,
extensions: [
'.spec.js', '.spec.cjs', '.spec.mjs',
'.test.js', '.test.cjs', '.test.mjs'
],
ignore: [
'test/assets/**',
'tmp/**',
'coverage/**',
'docs/**'
],
// Restrictions
global: [],
'check-leaks': false,
'allow-uncaught': false,
'async-only': false,
'forbid-only': true,
'forbid-pending': false
};
6 changes: 5 additions & 1 deletion .nycrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"all": false,
"check-coverage": false,
"check-coverage": true,
"reporter": ["lcov", "text"],
"report-dir": "./coverage",
"exclude": [
".mocharc.js",
"tmp/**"
],
"branches": 50,
"functions": 65,
"lines": 50,
Expand Down
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = [
'**/test/',
'**/coverage/',
'jsdoc.config.js',
'eslint.config.test.js'
'eslint.config.test.js',
'.mocharc.js'
]
},

Expand Down
17 changes: 14 additions & 3 deletions lib/audioconv.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,18 @@ async function convertAudio(inFile, options = defaultOptions) {
ffmpegChain
.on('error', (err) => {
quiet || process.stdout.write('\n');
// Safely get the input file size and prevent any error
// if the input file has been deleted unexpectedly
let inputSize = NaN;
try {
inputSize = fs.statSync(inFile).size;
// eslint-disable-next-line no-unused-vars,no-empty
} catch (err) {}

writeErrorLog(createLogFile('audioConvError'), {
inputFile: inFile,
outputFile: outFile,
inputSize: fs.statSync(inFile).size
inputAudio: inFile,
outputAudio: outFile,
inputSize
}, err).then(() => {
if (!quiet) {
log.error('Failed to convert the audio file');
Expand Down Expand Up @@ -519,6 +527,9 @@ async function convertAudio(inFile, options = defaultOptions) {

module.exports = Object.freeze({
defaultOptions,
splitOptions,
writeErrorLog,
createConversionProgress,
resolveOptions,
checkFfmpeg,
convertAudio
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"test:unit": "mocha test/unittest",
"test:nyan:unit": "mocha test/unittest --reporter nyan",
"test:irl": "mocha test/irl.test.mjs",
"coverage": "nyc --reporter lcov --reporter text npm test"
"coverage": "nyc npm test"
},
"author": "Ryuu Mitsuki <dhefam31@gmail.com> (https://github.com/mitsuki31)",
"license": "MIT",
Expand Down
Binary file added test/assets/audio/testaudio-160-pcm_s32le.wav
Binary file not shown.
Loading

0 comments on commit ce987ff

Please sign in to comment.