Skip to content

[Bug]: exitWithError not failing Playwright test #2602

@SWederell

Description

@SWederell

🔎 Search Terms

exitwitherror, playwright, error

The problem

When using Winston with Playwright, I want the test to fail if an Error occurs. Setting 'exitOnError' to true, or a function that fails the test, does not work, nor writes to the log.

What version of Winston presents the issue?

v3.19.0

What version of Node are you using?

v22.13.0

If this worked in a previous version of Winston, which was it?

No response

Minimum Working Example

playwright.config.ts

import { defineConfig } from "@playwright/test";

export default defineConfig({
	timeout: 600_000,
	testDir: ".",
	fullyParallel: false,
	workers: 1,
	reporter: [],
	use: {
		trace: "on",
		headless: true,
	},
	projects: [
		{
			name: "chromium",
			use: {
				viewport: { height: 1080, width: 1920 },
			},
		},
	],
});

winston.spec.ts

import { test } from '@playwright/test'
import { createLogger, format, transports } from 'winston'

test('temp test', () => {
  const { combine, timestamp, json, errors } = format

  const logger = createLogger({
    level: process.env.LOGGER_LEVEL || 'info',
    format: combine(timestamp(), json(), errors({ stack: true })),
    transports: [new transports.File({ filename: './temp.log', zippedArchive: false })],
    exitOnError: function () {
      console.log('exitonerror')
      throw new Error('Something failed, view logs')
    },
  })

  logger.error('Demo Error')
})

or

import { test } from '@playwright/test'
import { createLogger, format, transports } from 'winston'

test('temp test', () => {
  const { combine, timestamp, json, errors } = format

  const logger = createLogger({
    level: process.env.LOGGER_LEVEL || 'info',
    format: combine(timestamp(), json(), errors({ stack: true })),
    transports: [new transports.File({ filename: './temp.log', zippedArchive: false })],
    exitOnError: true,
  })

  logger.error('Demo Error')
})

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions