- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.6k
test_runner: support forced exit #52038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -179,6 +179,9 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors, | |
| } else if (force_repl) { | ||
| errors->push_back("either --watch or --interactive " | ||
| "can be used, not both"); | ||
| } else if (test_runner_force_exit) { | ||
| errors->push_back("either --watch or --test-force-exit " | ||
| "can be used, not both"); | ||
| 
      Comment on lines
    
      +182
     to 
      +184
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is becoming a repetitive check ( | ||
| } else if (!test_runner && (argv->size() < 1 || (*argv)[1].empty())) { | ||
| errors->push_back("--watch requires specifying a file"); | ||
| } | ||
|  | @@ -616,6 +619,9 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |
| AddOption("--test-concurrency", | ||
| "specify test runner concurrency", | ||
| &EnvironmentOptions::test_runner_concurrency); | ||
| AddOption("--test-force-exit", | ||
| "force test runner to exit upon completion", | ||
| &EnvironmentOptions::test_runner_force_exit); | ||
| AddOption("--test-timeout", | ||
| "specify test runner timeout", | ||
| &EnvironmentOptions::test_runner_timeout); | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Flags: --test-force-exit --test-reporter=spec | ||
| 'use strict'; | ||
| const { after, afterEach, before, beforeEach, test } = require('node:test'); | ||
|  | ||
| before(() => { | ||
| console.log('BEFORE'); | ||
| }); | ||
|  | ||
| beforeEach(() => { | ||
| console.log('BEFORE EACH'); | ||
| }); | ||
|  | ||
| after(() => { | ||
| console.log('AFTER'); | ||
| }); | ||
|  | ||
| afterEach(() => { | ||
| console.log('AFTER EACH'); | ||
| }); | ||
|  | ||
| test('passes but oops', () => { | ||
| setTimeout(() => { | ||
| throw new Error('this should not have a chance to be thrown'); | ||
| }, 1000); | ||
| }); | ||
|  | ||
| test('also passes'); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| BEFORE | ||
| BEFORE EACH | ||
| AFTER EACH | ||
| BEFORE EACH | ||
| AFTER EACH | ||
| AFTER | ||
| ✔ passes but oops (*ms) | ||
| ✔ also passes (*ms) | ||
| ℹ tests 2 | ||
| ℹ suites 0 | ||
| ℹ pass 2 | ||
| ℹ fail 0 | ||
| ℹ cancelled 0 | ||
| ℹ skipped 0 | ||
| ℹ todo 0 | ||
| ℹ duration_ms * | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| 'use strict'; | ||
| const { test } = require('node:test'); | ||
|  | ||
| test('fails and schedules more work', () => { | ||
| setTimeout(() => { | ||
| throw new Error('this should not have a chance to be thrown'); | ||
| }, 1000); | ||
|  | ||
| throw new Error('fails'); | ||
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| 'use strict'; | ||
| require('../common'); | ||
| const { match, doesNotMatch, strictEqual } = require('node:assert'); | ||
| const { spawnSync } = require('node:child_process'); | ||
| const fixtures = require('../common/fixtures'); | ||
| const fixture = fixtures.path('test-runner/throws_sync_and_async.js'); | ||
| const r = spawnSync(process.execPath, ['--test', '--test-force-exit', fixture]); | ||
|  | ||
| strictEqual(r.status, 1); | ||
| strictEqual(r.signal, null); | ||
| strictEqual(r.stderr.toString(), ''); | ||
|  | ||
| const stdout = r.stdout.toString(); | ||
| match(stdout, /error: 'fails'/); | ||
| doesNotMatch(stdout, /this should not have a chance to be thrown/); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case, there is no need for forced exit. the reporter closes on a call to
root.postRun