Projektstart
This commit is contained in:
10
backend/node_modules/fastify/test/esm/errorCodes.test.mjs
generated
vendored
Normal file
10
backend/node_modules/fastify/test/esm/errorCodes.test.mjs
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { errorCodes } from '../../fastify.js'
|
||||
import t from 'tap'
|
||||
|
||||
t.test('errorCodes in ESM', async t => {
|
||||
// test a custom fastify error using errorCodes with ESM
|
||||
const customError = errorCodes.FST_ERR_VALIDATION('custom error message')
|
||||
t.ok(typeof customError !== 'undefined')
|
||||
t.ok(customError instanceof errorCodes.FST_ERR_VALIDATION)
|
||||
t.equal(customError.message, 'custom error message')
|
||||
})
|
||||
13
backend/node_modules/fastify/test/esm/esm.test.mjs
generated
vendored
Normal file
13
backend/node_modules/fastify/test/esm/esm.test.mjs
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import t from 'tap'
|
||||
import Fastify from '../../fastify.js'
|
||||
|
||||
t.test('esm support', async t => {
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.register(import('./plugin.mjs'), { foo: 'bar' })
|
||||
fastify.register(import('./other.mjs'))
|
||||
|
||||
await fastify.ready()
|
||||
|
||||
t.equal(fastify.foo, 'bar')
|
||||
})
|
||||
18
backend/node_modules/fastify/test/esm/index.test.js
generated
vendored
Normal file
18
backend/node_modules/fastify/test/esm/index.test.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const semver = require('semver')
|
||||
|
||||
if (semver.lt(process.versions.node, '14.13.0')) {
|
||||
t.skip('Skip named exports because Node version < 14.13.0')
|
||||
} else {
|
||||
// Node v8 throw a `SyntaxError: Unexpected token import`
|
||||
// even if this branch is never touch in the code,
|
||||
// by using `eval` we can avoid this issue.
|
||||
// eslint-disable-next-line
|
||||
new Function('module', 'return import(module)')('./named-exports.mjs').catch((err) => {
|
||||
process.nextTick(() => {
|
||||
throw err
|
||||
})
|
||||
})
|
||||
}
|
||||
14
backend/node_modules/fastify/test/esm/named-exports.mjs
generated
vendored
Normal file
14
backend/node_modules/fastify/test/esm/named-exports.mjs
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import t from 'tap'
|
||||
import { fastify } from '../../fastify.js'
|
||||
|
||||
// This test is executed in index.test.js
|
||||
t.test('named exports support', async t => {
|
||||
const app = fastify()
|
||||
|
||||
app.register(import('./plugin.mjs'), { foo: 'bar' })
|
||||
app.register(import('./other.mjs'))
|
||||
|
||||
await app.ready()
|
||||
|
||||
t.equal(app.foo, 'bar')
|
||||
})
|
||||
8
backend/node_modules/fastify/test/esm/other.mjs
generated
vendored
Normal file
8
backend/node_modules/fastify/test/esm/other.mjs
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// Imported in both index.test.js & esm.test.mjs
|
||||
import t from 'tap'
|
||||
|
||||
async function other (fastify, opts) {
|
||||
t.equal(fastify.foo, 'bar')
|
||||
}
|
||||
|
||||
export default other
|
||||
8
backend/node_modules/fastify/test/esm/plugin.mjs
generated
vendored
Normal file
8
backend/node_modules/fastify/test/esm/plugin.mjs
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// Imported in both index.test.js & esm.test.mjs
|
||||
async function plugin (fastify, opts) {
|
||||
fastify.decorate('foo', opts.foo)
|
||||
}
|
||||
|
||||
plugin[Symbol.for('skip-override')] = true
|
||||
|
||||
export default plugin
|
||||
Reference in New Issue
Block a user