-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
test: add unexpected behavior repro test #55095
Closed
pmarchini
wants to merge
1
commit into
nodejs:main
from
pmarchini:test/todo-test-runner-run-dependencies
Closed
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 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,124 @@ | ||
// Flags: --expose-internals | ||
import * as common from '../common/index.mjs'; | ||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
import { spawn } from 'node:child_process'; | ||
import { writeFileSync } from 'node:fs'; | ||
import util from 'internal/util'; | ||
import tmpdir from '../common/tmpdir.js'; | ||
|
||
if (common.isIBMi) | ||
common.skip('IBMi does not support `fs.watch()`'); | ||
|
||
if (common.isAIX) | ||
common.skip('folder watch capability is limited in AIX.'); | ||
|
||
tmpdir.refresh(); | ||
|
||
// Set up test files and dependencies | ||
const fixtureContent = { | ||
'dependency.js': 'module.exports = {};', | ||
'test.js': ` | ||
const test = require('node:test'); | ||
require('./dependency.js'); | ||
test('first test has ran');`, | ||
'test-2.js': ` | ||
const test = require('node:test'); | ||
require('./dependency.js'); | ||
test('second test has ran');`, | ||
}; | ||
|
||
const fixturePaths = Object.fromEntries(Object.keys(fixtureContent) | ||
.map((file) => [file, tmpdir.resolve(file)])); | ||
|
||
Object.entries(fixtureContent) | ||
.forEach(([file, content]) => writeFileSync(fixturePaths[file], content)); | ||
|
||
describe('test runner watch mode with more complex setup', () => { | ||
// This test is failing and needs to be fixed | ||
// The expected behavior is that the test runner should re-run the appropriate tests when a shared dependency changes | ||
it.todo('should re-run appropriate tests when dependencies change', async () => { | ||
// Start the test runner in watch mode | ||
const child = spawn(process.execPath, | ||
['--watch', '--test'], | ||
{ encoding: 'utf8', stdio: 'pipe', cwd: tmpdir.path }); | ||
|
||
let currentRunOutput = ''; | ||
const testRuns = []; | ||
|
||
const firstRunCompleted = util.createDeferredPromise(); | ||
const secondRunCompleted = util.createDeferredPromise(); | ||
const thirdRunCompleted = util.createDeferredPromise(); | ||
const fourthRunCompleted = util.createDeferredPromise(); | ||
|
||
child.stdout.on('data', (data) => { | ||
const str = data.toString(); | ||
currentRunOutput += str; | ||
|
||
if (/duration_ms\s\d+/.test(str)) { | ||
// Test run has completed | ||
testRuns.push(currentRunOutput); | ||
currentRunOutput = ''; | ||
if (testRuns.length === 1) { | ||
firstRunCompleted.resolve(); | ||
} else if (testRuns.length === 2) { | ||
secondRunCompleted.resolve(); | ||
} else if (testRuns.length === 3) { | ||
thirdRunCompleted.resolve(); | ||
} else if (testRuns.length === 4) { | ||
fourthRunCompleted.resolve(); | ||
} | ||
} | ||
}); | ||
|
||
// Wait for the initial test run to complete | ||
await firstRunCompleted.promise; | ||
|
||
// Modify 'dependency.js' to trigger re-run of both tests | ||
writeFileSync(fixturePaths['dependency.js'], 'module.exports = { modified: true };'); | ||
|
||
// Wait for the second test run to complete | ||
await secondRunCompleted.promise; | ||
|
||
// Modify 'test.js' to trigger re-run of only 'test.js' | ||
writeFileSync(fixturePaths['test.js'], ` | ||
const test = require('node:test'); | ||
require('./dependency.js'); | ||
test('first test has ran again');`); | ||
|
||
// Wait for the third test run to complete | ||
await thirdRunCompleted.promise; | ||
|
||
// Modify 'dependency.js' again to trigger re-run of both tests | ||
writeFileSync(fixturePaths['dependency.js'], 'module.exports = { modified: true, again: true };'); | ||
|
||
// Wait for the fourth test run to complete | ||
await fourthRunCompleted.promise; | ||
|
||
// Kill the child process | ||
child.kill(); | ||
|
||
// Analyze the test runs | ||
assert.strictEqual(testRuns.length, 4); | ||
|
||
// First test run - Both tests should run | ||
const firstRunOutput = testRuns[0]; | ||
assert.match(firstRunOutput, /first test has ran/); | ||
assert.match(firstRunOutput, /second test has ran/); | ||
|
||
// Second test run - We have modified 'dependency.js' only, so both tests should re-run | ||
const secondRunOutput = testRuns[1]; | ||
assert.match(secondRunOutput, /first test has ran/); | ||
assert.match(secondRunOutput, /second test has ran/); | ||
|
||
// Third test run - We have modified 'test.js' only | ||
const thirdRunOutput = testRuns[2]; | ||
assert.match(thirdRunOutput, /first test has ran again/); | ||
assert.doesNotMatch(thirdRunOutput, /second test has ran/); | ||
|
||
// Fourth test run - We have modified 'dependency.js' again, so both tests should re-run | ||
const fourthRunOutput = testRuns[3]; | ||
assert.match(fourthRunOutput, /first test has ran again/); | ||
assert.match(fourthRunOutput, /second test has ran/); | ||
}); | ||
}); |
Oops, something went wrong.
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.
Switch statement?
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.
Yep no problem at all 🚀