Skip to content

Commit

Permalink
Chore: Organize and restructure tests (#2049)
Browse files Browse the repository at this point in the history
* chore: wrap logger tests in top-level describe

* chore: restructure tests directory

* chore: restructure logger tests

* chore: cleanup test descriptions

* fix: fix ci step to account for npm script rename

* chore: rename tests dir back to test

* fix: correct relative file paths

* make sure all tests actually run

* feat: add nyc configuration file

* chore: fix missing end of file newlines

* fix: ci steps

* fix: ci steps try 2

* chore: rename ci jobs

* chore: leverage yaml file for nyc configuration

* chore: move nyc configuration from npm script to associated configuration file

* chore: move common mocha configurations from npm script to dedicated configuration

* fix: disable mocha recursive option as path glob handles accordingly

* updated mocha options

* coverage should run all tests

* Revert "coverage should run all tests"

This reverts commit 9b2fb38.

Co-authored-by: Phred <fearphage@gmail.com>
  • Loading branch information
maverick1872 and fearphage committed Feb 7, 2022
1 parent 2017c50 commit 2b8cd55
Show file tree
Hide file tree
Showing 38 changed files with 1,265 additions and 1,192 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: CI Checks

on:
pull_request:
Expand All @@ -11,7 +11,7 @@ on:
- master

jobs:
unit-tests:
Tests:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -28,9 +28,11 @@ jobs:
run: npm clean-install
- name: Lint
run: npm run lint
- name: Test
run: npm test
- name: Coveralls
- name: Integration Tests
run: npm run test:integration
- name: Test Coverage
run: npm run test:coverage
- name: Report test coverage to Coveralls.io
if: matrix.node == '16'
uses: coverallsapp/github-action@master
with:
Expand Down
4 changes: 4 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exclude:
- test/helpers/scripts/*.js
exit: true
recursive: true
8 changes: 8 additions & 0 deletions .nycrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
reporter:
- text
- lcov
check-coverage: true
branches: 61.51
lines: 70.85
functions: 73.21
statements: 70.54
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@
"types": "./index.d.ts",
"scripts": {
"lint": "eslint lib/*.js lib/winston/*.js lib/winston/**/*.js --resolve-plugins-relative-to ./node_modules/@dabh/eslint-config-populist",
"pretest": "npm run lint",
"test": "nyc --reporter=text --reporter lcov npm run test:mocha",
"test:mocha": "mocha test/*.test.js test/**/*.test.js --exit",
"test": "mocha",
"test:coverage": "nyc npm run test:unit",
"test:unit": "mocha test/unit",
"test:integration": "mocha test/integration",
"build": "rimraf dist && babel lib -d dist",
"prepublishOnly": "npm run build"
},
"engines": {
"node": ">= 6.4.0"
"node": ">= 12.0.0"
},
"license": "MIT"
}
Empty file.
3 changes: 2 additions & 1 deletion test/helpers/scripts/default-exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

var path = require('path'),
winston = require('../../../lib/winston');
const testLogFixturesPath = path.join(__dirname, '..', '..', 'fixtures', 'logs');

winston.exceptions.handle([
new winston.transports.File({
filename: path.join(__dirname, '..', '..', 'fixtures', 'logs', 'default-exception.log'),
filename: path.join(testLogFixturesPath, 'default-exception.log'),
handleExceptions: true
})
]);
Expand Down
10 changes: 2 additions & 8 deletions test/helpers/scripts/default-rejections.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@

var path = require("path"),
winston = require("../../../lib/winston");
const testLogFixturesPath = path.join(__dirname, '..', '..', 'fixtures', 'logs');

winston.rejections.handle([
new winston.transports.File({
filename: path.join(
__dirname,
"..",
"..",
"fixtures",
"logs",
"default-rejection.log"
),
filename: path.join(testLogFixturesPath, "default-rejection.log"),
handleRejections: true
})
]);
Expand Down
3 changes: 2 additions & 1 deletion test/helpers/scripts/exit-on-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

var path = require('path'),
winston = require('../../../lib/winston');
const testLogFixturesPath = path.join(__dirname, '..', '..', 'fixtures', 'logs');

winston.exitOnError = function (err) {
process.stdout.write(err.message);
Expand All @@ -16,7 +17,7 @@ winston.exitOnError = function (err) {

winston.handleExceptions([
new winston.transports.File({
filename: path.join(__dirname, '..', 'logs', 'exit-on-error.log'),
filename: path.join(testLogFixturesPath, 'exit-on-error.log'),
handleExceptions: true
})
]);
Expand Down
3 changes: 2 additions & 1 deletion test/helpers/scripts/log-exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

var path = require('path'),
winston = require('../../../lib/winston');
const testLogFixturesPath = path.join(__dirname, '..', '..', 'fixtures', 'logs');

var logger = winston.createLogger({
transports: [
new winston.transports.File({
filename: path.join(__dirname, '..', '..', 'fixtures', 'logs', 'exception.log'),
filename: path.join(testLogFixturesPath, 'exception.log'),
handleExceptions: true
})
]
Expand Down
10 changes: 2 additions & 8 deletions test/helpers/scripts/log-rejections.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@

var path = require("path"),
winston = require("../../../lib/winston");
const testLogFixturesPath = path.join(__dirname, '..', '..', 'fixtures', 'logs');

var logger = winston.createLogger({
transports: [
new winston.transports.File({
filename: path.join(
__dirname,
"..",
"..",
"fixtures",
"logs",
"rejections.log"
),
filename: path.join(testLogFixturesPath, "rejections.log"),
handleRejections: true
})
]
Expand Down
3 changes: 2 additions & 1 deletion test/helpers/scripts/log-string-exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

var path = require('path'),
winston = require('../../../lib/winston');
const testLogFixturesPath = path.join(__dirname, '..', '..', 'fixtures', 'logs');

var logger = winston.createLogger({
transports: [
new winston.transports.File({
filename: path.join(__dirname, '..', '..', 'fixtures', 'logs', 'string-exception.log'),
filename: path.join(testLogFixturesPath, 'string-exception.log'),
handleExceptions: true
})
]
Expand Down
3 changes: 2 additions & 1 deletion test/helpers/scripts/unhandle-exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

var path = require('path'),
winston = require('../../../lib/winston');
const testLogFixturesPath = path.join(__dirname, '..', '..', 'fixtures', 'logs');

var logger = winston.createLogger({
transports: [
new winston.transports.File({
filename: path.join(__dirname, '..', 'logs', 'unhandle-exception.log')
filename: path.join(testLogFixturesPath, 'unhandle-exception.log')
})
]
});
Expand Down
3 changes: 2 additions & 1 deletion test/helpers/scripts/unhandle-rejections.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

var path = require('path'),
winston = require('../../../lib/winston');
const testLogFixturesPath = path.join(__dirname, '..', '..', 'fixtures', 'logs');

var logger = winston.createLogger({
transports: [
new winston.transports.File({
filename: path.join(__dirname, '..', 'logs', 'unhandle-rejections.log')
filename: path.join(testLogFixturesPath, 'unhandle-rejections.log')
})
]
});
Expand Down
4 changes: 2 additions & 2 deletions test/winston.test.js → test/integration/winston.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const { format } = require('util');
const assume = require('assume');
const winston = require('../lib/winston');
const winston = require('../../lib/winston');

describe('winston', function () {

Expand All @@ -35,7 +35,7 @@ describe('winston', function () {
});

it('exposes version', function () {
assume(winston.version).equals(require('../package').version);
assume(winston.version).equals(require('../../package.json').version);
});

it('abstract-winston-logger');
Expand Down
Loading

0 comments on commit 2b8cd55

Please sign in to comment.