Projektstart
This commit is contained in:
46
backend/node_modules/pino/test/pkg/index.js
generated
vendored
Normal file
46
backend/node_modules/pino/test/pkg/index.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
'use strict'
|
||||
|
||||
const os = require('node:os')
|
||||
const { join } = require('node:path')
|
||||
const { readFile } = require('node:fs').promises
|
||||
const { watchFileCreated, file } = require('../helper')
|
||||
const { test } = require('tap')
|
||||
const pino = require('../../pino')
|
||||
|
||||
const { pid } = process
|
||||
const hostname = os.hostname()
|
||||
|
||||
/**
|
||||
* This file is packaged using pkg in order to test if transport-stream.js works in that context
|
||||
*/
|
||||
|
||||
test('pino.transport with worker destination overridden by bundler and mjs transport', async ({ same, teardown }) => {
|
||||
globalThis.__bundlerPathsOverrides = {
|
||||
'pino-worker': join(__dirname, '..', '..', 'lib/worker.js')
|
||||
}
|
||||
|
||||
const destination = file()
|
||||
const transport = pino.transport({
|
||||
targets: [
|
||||
{
|
||||
target: join(__dirname, '..', 'fixtures', 'ts', 'to-file-transport.es2017.cjs'),
|
||||
options: { destination }
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
teardown(transport.end.bind(transport))
|
||||
const instance = pino(transport)
|
||||
instance.info('hello')
|
||||
await watchFileCreated(destination)
|
||||
const result = JSON.parse(await readFile(destination))
|
||||
delete result.time
|
||||
same(result, {
|
||||
pid,
|
||||
hostname,
|
||||
level: 30,
|
||||
msg: 'hello'
|
||||
})
|
||||
|
||||
globalThis.__bundlerPathsOverrides = undefined
|
||||
})
|
||||
16
backend/node_modules/pino/test/pkg/pkg.config.json
generated
vendored
Normal file
16
backend/node_modules/pino/test/pkg/pkg.config.json
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"pkg": {
|
||||
"assets": [
|
||||
"../../lib/worker.js",
|
||||
"../../lib/transport-stream.js",
|
||||
"../../test/fixtures/ts/to-file-transport.es2017.cjs",
|
||||
"../../node_modules/pino-abstract-transport/index.js"
|
||||
],
|
||||
"targets": [
|
||||
"node18",
|
||||
"node20",
|
||||
"node22"
|
||||
],
|
||||
"outputPath": "test/pkg"
|
||||
}
|
||||
}
|
||||
58
backend/node_modules/pino/test/pkg/pkg.test.js
generated
vendored
Normal file
58
backend/node_modules/pino/test/pkg/pkg.test.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('tap')
|
||||
const config = require('./pkg.config.json')
|
||||
const { promisify } = require('node:util')
|
||||
const { unlink } = require('node:fs/promises')
|
||||
const { join } = require('node:path')
|
||||
const { platform } = require('node:process')
|
||||
const execFile = promisify(require('node:child_process').execFile)
|
||||
|
||||
const skip = process.env.PNPM_CI || process.env.CITGM || process.arch === 'ppc64'
|
||||
|
||||
/**
|
||||
* The following regex is for tesintg the deprecation warning that is thrown by the `punycode` module.
|
||||
* Exact text that it's matching is:
|
||||
* (node:1234) [DEP0040] DeprecationWarning: The `punycode` module is deprecated.
|
||||
Please use a userland alternative instead.
|
||||
|
||||
(Use `node --trace-deprecation ...` to show where the warning was created)
|
||||
*/
|
||||
const deprecationWarningRegex = /^\(\w+:\d+\)\s\[[\w|\d]+\]\sDeprecationWarning: The `punycode` module is deprecated\.\s+Please use a userland alternative instead\.\s+\(Use `node --trace-deprecation \.\.\.` to show where the warning was created\)\s+$/
|
||||
|
||||
test('worker test when packaged into executable using pkg', { skip }, async (t) => {
|
||||
const packageName = 'index'
|
||||
|
||||
// package the app into several node versions, check config for more info
|
||||
const filePath = `${join(__dirname, packageName)}.js`
|
||||
const configPath = join(__dirname, 'pkg.config.json')
|
||||
const { stderr } = await execFile('npx', ['pkg', filePath, '--config', configPath], { shell: true })
|
||||
|
||||
// there should be no error when packaging
|
||||
const expectedvalue = stderr === '' || deprecationWarningRegex.test(stderr)
|
||||
t.ok(expectedvalue)
|
||||
|
||||
// pkg outputs files in the following format by default: {filename}-{node version}
|
||||
for (const target of config.pkg.targets) {
|
||||
// execute the packaged test
|
||||
let executablePath = `${join(config.pkg.outputPath, packageName)}-${target}`
|
||||
|
||||
// when on windows, we need the .exe extension
|
||||
if (platform === 'win32') {
|
||||
executablePath = `${executablePath}.exe`
|
||||
} else {
|
||||
executablePath = `./${executablePath}`
|
||||
}
|
||||
|
||||
const { stderr } = await execFile(executablePath)
|
||||
|
||||
// check if there were no errors
|
||||
const expectedvalue = stderr === '' || deprecationWarningRegex.test(stderr)
|
||||
t.ok(expectedvalue)
|
||||
|
||||
// clean up afterwards
|
||||
await unlink(executablePath)
|
||||
}
|
||||
|
||||
t.end()
|
||||
})
|
||||
Reference in New Issue
Block a user