-
-
Notifications
You must be signed in to change notification settings - Fork 32k
test_runner: support watch mode #45214
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |
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 @@ | ||
export const a = 1; |
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,3 @@ | ||
require('./dependency.js'); | ||
import('./dependency.mjs'); | ||
import('data:text/javascript,'); |
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,46 @@ | ||
// Flags: --expose-internals | ||
import '../common/index.mjs'; | ||
import { describe, it } from 'node:test'; | ||
import { spawn } from 'node:child_process'; | ||
import { writeFileSync, readFileSync } from 'node:fs'; | ||
import util from 'internal/util'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
|
||
async function testWatch({ files, fileToUpdate }) { | ||
const ran1 = util.createDeferredPromise(); | ||
const ran2 = util.createDeferredPromise(); | ||
const child = spawn(process.execPath, ['--watch', '--test', '--no-warnings', ...files], { encoding: 'utf8' }); | ||
let stdout = ''; | ||
child.stdout.on('data', (data) => { | ||
stdout += data.toString(); | ||
if (/ok 2/.test(stdout)) ran1.resolve(); | ||
if (/ok 3/.test(stdout)) ran2.resolve(); | ||
}); | ||
|
||
await ran1.promise; | ||
writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8')); | ||
await ran2.promise; | ||
child.kill(); | ||
} | ||
|
||
describe('test runner watch mode', () => { | ||
it('should run tests repeatedly', async () => { | ||
const file1 = fixtures.path('test-runner/index.test.js'); | ||
const file2 = fixtures.path('test-runner/subdir/subdir_test.js'); | ||
await testWatch({ files: [file1, file2], fileToUpdate: file2 }); | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('should run tests with dependency repeatedly', async () => { | ||
const file1 = fixtures.path('test-runner/index.test.js'); | ||
const dependent = fixtures.path('test-runner/dependent.js'); | ||
const dependency = fixtures.path('test-runner/dependency.js'); | ||
await testWatch({ files: [file1, dependent], fileToUpdate: dependency }); | ||
}); | ||
|
||
it('should run tests with ESM dependency', async () => { | ||
const file1 = fixtures.path('test-runner/index.test.js'); | ||
const dependent = fixtures.path('test-runner/dependent.js'); | ||
const dependency = fixtures.path('test-runner/dependency.mjs'); | ||
await testWatch({ files: [file1, dependent], fileToUpdate: dependency }); | ||
}); | ||
}); |
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.
Uh oh!
There was an error while loading. Please reload this page.