microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
67.03k stars 3.68k forks source link

[BUG Error: Playwright Test did not expect test() to be called here - teardown file when using test #26957

Closed JenH11 closed 1 year ago

JenH11 commented 1 year ago
- done - done - done (hopefully :) ) ### System info - Playwright Version: [v1.37] - Operating System: [Windows 10 (not tested against other OS] - Browser: [Chromium (not tested against other browsers)] - Other info: ### Source code import fs from 'fs' import { test as teardown} from '@playwright/test'; teardown('Unlink state storage file', async ({ }) => { fs.readdirSync('./state-storage').forEach(filePath => { if (filePath.endsWith('.json')) { fs.unlink(`./state-storage/${filePath}`, (err) => { console.log(err); }); } }); }); - [ ] I provided exact source code that allows reproducing the issue locally.

Config file

projects: [ { name: 'setup', testDir: './', testMatch:'global_setup.ts', teardown: 'teardown', }, { name: 'chromium', retries: 0, dependencies: ['setup'], use: { headless: false, ...devices['Desktop Chrome'], launchOptions: { slowMo: !process.env.SLOMO ? 0 : parseInt(process.env.SLOMO), proxy: { server: 'http://172.16.2.155:3128' }, }, }, }, { name: 'teardown', testDir:'./', testMatch:'global_teardown.ts' }, ],

Test file (self-contained)

import fs from 'fs' import { test as teardown} from '@playwright/test';

teardown('Unlink state storage file', async ({ }) => { fs.readdirSync('./state-storage').forEach(filePath => { if (filePath.endsWith('.json')) { fs.unlink(./state-storage/${filePath}, (err) => { console.log(err); }); } }); });

Expected The tests execute within these projects and in this order - setup, chromium, project

Actual Tests do not execute and an error occurs

pavelfeldman commented 1 year ago

Your test file seems to be the same as your teardown, did you share a wrong file? I'm also not seeing error anywhere in your report.

pavelfeldman commented 1 year ago

We need more information to act on this report. As long as we can't repro it, it is unlikely with can make progress with it. Allow me to close it, but please file a new one and link to this issue when you get back to it!