mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	test: print failed tests upon interrupt (#3316)
This commit is contained in:
		
							parent
							
								
									5f7b5469b9
								
							
						
					
					
						commit
						0a5d340e8e
					
				@ -20,6 +20,7 @@ const os = require('os');
 | 
			
		||||
const path = require('path');
 | 
			
		||||
const fs = require('fs');
 | 
			
		||||
const debug = require('debug');
 | 
			
		||||
const util = require('util');
 | 
			
		||||
const platform = process.env.REPORT_ONLY_PLATFORM || os.platform();
 | 
			
		||||
const GoldenUtils = require('../../utils/testrunner/GoldenUtils');
 | 
			
		||||
const {installCoverageHooks} = require('./coverage');
 | 
			
		||||
@ -170,6 +171,7 @@ class PlaywrightEnvironment extends NodeEnvironment {
 | 
			
		||||
 | 
			
		||||
    if (event.name === 'test_start') {
 | 
			
		||||
      const fn = event.test.fn;
 | 
			
		||||
      this._lastTest = event.test;
 | 
			
		||||
      event.test.fn = async () => {
 | 
			
		||||
        if (reportOnly) {
 | 
			
		||||
          if (fn.__fail)
 | 
			
		||||
@ -179,6 +181,9 @@ class PlaywrightEnvironment extends NodeEnvironment {
 | 
			
		||||
        debug('pw:test')(`start "${testOrSuiteName(event.test)}"`);
 | 
			
		||||
        try {
 | 
			
		||||
          await this.fixturePool.resolveParametersAndRun(fn);
 | 
			
		||||
        } catch(e) {
 | 
			
		||||
          debug('pw:test')(`error "${testOrSuiteName(event.test)}"`, util.inspect(e));
 | 
			
		||||
          throw e;
 | 
			
		||||
        } finally {
 | 
			
		||||
          await this.fixturePool.teardownScope('test');
 | 
			
		||||
          debug('pw:test')(`finish "${testOrSuiteName(event.test)}"`);
 | 
			
		||||
@ -186,6 +191,9 @@ class PlaywrightEnvironment extends NodeEnvironment {
 | 
			
		||||
      };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (event.name === 'error')
 | 
			
		||||
      debug('pw:test')(`error "${testOrSuiteName(this._lastTest)}"`, util.inspect(event.error));
 | 
			
		||||
 | 
			
		||||
    if (event.name === 'test_fn_failure') {
 | 
			
		||||
      await this.fixturePool.teardownScope('worker');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -14,13 +14,31 @@
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
const colors = require('colors/safe');
 | 
			
		||||
const fs = require('fs');
 | 
			
		||||
const os = require('os');
 | 
			
		||||
 | 
			
		||||
const failures = [];
 | 
			
		||||
 | 
			
		||||
module.exports = function Reporter() {
 | 
			
		||||
  this.onRunComplete = (test, runResults) => {
 | 
			
		||||
    runResults.platform = process.env.REPORT_ONLY_PLATFORM || os.platform();
 | 
			
		||||
    runResults.browserName = process.env.BROWSER || 'chromium';
 | 
			
		||||
    fs.writeFileSync('jest-report.json', JSON.stringify(runResults, undefined, 2));
 | 
			
		||||
  };
 | 
			
		||||
  this.onTestCaseResult = (test, testCaseResult) => {
 | 
			
		||||
    if (testCaseResult.status === 'failed')
 | 
			
		||||
      failures.push([test, testCaseResult]);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
process.on('SIGINT', async () => {
 | 
			
		||||
  for (let i = 0; i < failures.length; ++i) {
 | 
			
		||||
    const [test, testCaseResult] = failures[i];
 | 
			
		||||
    const path = test.path.replace(/.*test/, 'test');
 | 
			
		||||
    const name = colors.yellow(path) + ' — ' + colors.bold(colors.yellow(testCaseResult.fullName));
 | 
			
		||||
    process.stderr.write(`\n${i + 1}) ${colors.red('[FAIL]')} ${name}\n\n`);
 | 
			
		||||
    process.stderr.write(testCaseResult.failureMessages + '\n');
 | 
			
		||||
  }
 | 
			
		||||
  process.exit(130);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user