-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use tap instead of ava, 100% test coverage, move types to types folde…
…r, activate linting in ci-pipeline (#65)
- Loading branch information
Showing
11 changed files
with
156 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ jobs: | |
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 | ||
with: | ||
license-check: true | ||
lint: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
files: | ||
- test/**/*[!jest].test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
|
||
const test = require('tap').test | ||
const build = require('..') | ||
|
||
test('emit with interpolated string', t => { | ||
t.plan(4) | ||
const { create, emit, emitted } = build() | ||
|
||
process.on('warning', onWarning) | ||
function onWarning (warning) { | ||
t.equal(warning.name, 'FastifyDeprecation') | ||
t.equal(warning.code, 'CODE') | ||
t.equal(warning.message, 'Hello world') | ||
t.ok(emitted.get('CODE')) | ||
} | ||
|
||
create('FastifyDeprecation', 'CODE', 'Hello %s') | ||
emit('CODE', 'world') | ||
emit('CODE', 'world') | ||
|
||
setImmediate(() => { | ||
process.removeListener('warning', onWarning) | ||
t.end() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
|
||
const test = require('tap').test | ||
const build = require('..') | ||
|
||
test('emit should emit a given code only once', t => { | ||
t.plan(4) | ||
|
||
const { create, emit, emitted } = build() | ||
|
||
process.on('warning', onWarning) | ||
function onWarning (warning) { | ||
t.equal(warning.name, 'FastifyDeprecation') | ||
t.equal(warning.code, 'CODE') | ||
t.equal(warning.message, 'Hello world') | ||
t.ok(emitted.get('CODE')) | ||
} | ||
|
||
create('FastifyDeprecation', 'CODE', 'Hello world') | ||
emit('CODE') | ||
emit('CODE') | ||
setImmediate(() => { | ||
process.removeListener('warning', onWarning) | ||
t.end() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
'use strict' | ||
|
||
const test = require('tap').test | ||
const build = require('..') | ||
|
||
process.removeAllListeners('warning') | ||
|
||
test('Create warning with zero parameter', t => { | ||
t.plan(3) | ||
|
||
const { create } = build() | ||
const buildWarnOpts = create('FastifyWarning', 'CODE', 'Not available') | ||
const opts = buildWarnOpts() | ||
t.equal(opts.name, 'FastifyWarning') | ||
t.equal(opts.message, 'Not available') | ||
t.equal(opts.code, 'CODE') | ||
}) | ||
|
||
test('Create error with 1 parameter', t => { | ||
t.plan(3) | ||
|
||
const { create } = build() | ||
const buildWarningOpts = create('FastifyWarning', 'CODE', 'hey %s') | ||
const opts = buildWarningOpts('alice') | ||
t.equal(opts.name, 'FastifyWarning') | ||
t.equal(opts.message, 'hey alice') | ||
t.equal(opts.code, 'CODE') | ||
}) | ||
|
||
test('Create error with 2 parameters', t => { | ||
t.plan(3) | ||
|
||
const { create } = build() | ||
const buildWarnOpts = create('FastifyWarning', 'CODE', 'hey %s, I like your %s') | ||
const opts = buildWarnOpts('alice', 'attitude') | ||
t.equal(opts.name, 'FastifyWarning') | ||
t.equal(opts.message, 'hey alice, I like your attitude') | ||
t.equal(opts.code, 'CODE') | ||
}) | ||
|
||
test('Create error with 3 parameters', t => { | ||
t.plan(3) | ||
|
||
const { create } = build() | ||
const buildWarnOpts = create('FastifyWarning', 'CODE', 'hey %s, I like your %s %s') | ||
const opts = buildWarnOpts('alice', 'attitude', 'see you') | ||
t.equal(opts.name, 'FastifyWarning') | ||
t.equal(opts.message, 'hey alice, I like your attitude see you') | ||
t.equal(opts.code, 'CODE') | ||
}) | ||
|
||
test('Should throw when error code has no fastify name', t => { | ||
t.plan(1) | ||
|
||
const { create } = build() | ||
|
||
t.throws(() => create(), new Error('Warning name must not be empty')) | ||
}) | ||
|
||
test('Should throw when error has no code', t => { | ||
t.plan(1) | ||
|
||
const { create } = build() | ||
|
||
t.throws(() => create('name'), new Error('Warning code must not be empty')) | ||
}) | ||
|
||
test('Should throw when error has no message', t => { | ||
t.plan(1) | ||
|
||
const { create } = build() | ||
|
||
t.throws(() => create('name', 'code'), new Error('Warning message must not be empty')) | ||
}) | ||
|
||
test('Should throw if emit is called with unknown code ', t => { | ||
t.plan(1) | ||
|
||
const { emit } = build() | ||
|
||
t.throws(() => emit('CODE'), new Error('The code \'CODE\' does not exist')) | ||
}) | ||
|
||
test('Cannot reuse the same code more than once', t => { | ||
t.plan(1) | ||
|
||
const { create } = build() | ||
create('FastifyWarning', 'CODE', 'Not available') | ||
|
||
t.throws(() => create('FastifyWarning', 'CODE', 'Not available'), new Error("The code 'CODE' already exist")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters