-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix broken tests on main #165
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"javascript.validate.enable": true, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "explicit" | ||
}, | ||
"editor.formatOnSave": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Disable Bzlmod | ||
common --noenable_bzlmod | ||
common --enable_workspace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.1.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Disable Bzlmod | ||
common --noenable_bzlmod | ||
common --enable_workspace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.1.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Disable Bzlmod | ||
common --noenable_bzlmod | ||
common --enable_workspace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.1.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Disable Bzlmod | ||
common --noenable_bzlmod | ||
common --enable_workspace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.1.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Disable Bzlmod | ||
common --noenable_bzlmod | ||
common --enable_workspace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.1.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Disable Bzlmod | ||
common --noenable_bzlmod | ||
common --enable_workspace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.1.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Disable Bzlmod | ||
common --noenable_bzlmod | ||
common --enable_workspace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.1.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Disable Bzlmod | ||
common --noenable_bzlmod | ||
common --enable_workspace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.1.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Disable Bzlmod | ||
common --noenable_bzlmod | ||
common --enable_workspace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.1.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Disable Bzlmod | ||
common --noenable_bzlmod | ||
common --enable_workspace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.1.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Disable Bzlmod | ||
common --noenable_bzlmod | ||
common --enable_workspace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.1.2 |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -67,9 +67,10 @@ const {shouldSync, getVersion} = require('../utils/version-onboarding.js'); | |||||||||||||||
const yarnCmds = require('../utils/yarn-commands.js'); | ||||||||||||||||
const {sortPackageJson} = require('../utils/sort-package-json'); | ||||||||||||||||
|
||||||||||||||||
const originalProcessExit = process.exit; | ||||||||||||||||
process.on('unhandledRejection', e => { | ||||||||||||||||
console.error(e.stack); | ||||||||||||||||
process.exit(1); | ||||||||||||||||
originalProcessExit(1); | ||||||||||||||||
}); | ||||||||||||||||
|
||||||||||||||||
// $FlowFixMe flow can't handle statics of async function | ||||||||||||||||
|
@@ -80,32 +81,88 @@ const tmp = tmpdir(); | |||||||||||||||
runTests(); | ||||||||||||||||
|
||||||||||||||||
async function t(test) { | ||||||||||||||||
const testName = test.name; | ||||||||||||||||
const match = (process.argv[2] || '').toLowerCase(); | ||||||||||||||||
if (test.name.toLowerCase().indexOf(match) > -1) { | ||||||||||||||||
|
||||||||||||||||
if (testName.toLowerCase().indexOf(match) > -1) { | ||||||||||||||||
if (match) console.log(`Testing ${test.name}`); | ||||||||||||||||
try { | ||||||||||||||||
await test(); | ||||||||||||||||
console.log(`✅ ${testName}`); | ||||||||||||||||
} catch (e) { | ||||||||||||||||
console.error(`\n\nTest "${test.name}" failed with error:`); | ||||||||||||||||
console.log(`❌ ${testName}`); | ||||||||||||||||
throw e; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/** | ||||||||||||||||
* Uses an error stack trace to determine which test from this | ||||||||||||||||
* file caused a given function to be called. | ||||||||||||||||
*/ | ||||||||||||||||
function getCallingTestFn() { | ||||||||||||||||
const error = new Error(); | ||||||||||||||||
if (!error.stack) return null; | ||||||||||||||||
|
||||||||||||||||
const errorStackLines = error.stack.split('\n'); | ||||||||||||||||
for (const line of errorStackLines) { | ||||||||||||||||
const trimmedLine = line.split('at ')[1]; | ||||||||||||||||
if (!trimmedLine) continue; | ||||||||||||||||
|
||||||||||||||||
const [, fnName, filePath] = | ||||||||||||||||
trimmedLine.match( | ||||||||||||||||
/^(?:async )?(?:(.+) \()?(?:file:\/\/)?([^:]+):(\d+):(\d+)\)?$/ | ||||||||||||||||
) || []; | ||||||||||||||||
|
||||||||||||||||
if ( | ||||||||||||||||
filePath === __filename && | ||||||||||||||||
fnName.startsWith('test') && | ||||||||||||||||
fnName.length > 4 | ||||||||||||||||
) { | ||||||||||||||||
return fnName; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return null; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
const testsExpectingExit /*: Map<string, number> */ = new Map(); | ||||||||||||||||
// $FlowFixMe | ||||||||||||||||
process.exit = (code = 0) => { | ||||||||||||||||
const callingTest = getCallingTestFn(); | ||||||||||||||||
if (callingTest && testsExpectingExit.has(callingTest)) { | ||||||||||||||||
testsExpectingExit.set(callingTest, code); | ||||||||||||||||
return; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// $FlowFixMe: bad libdef | ||||||||||||||||
assert.fail(`'process.exit' was unexpectedly called with code '${code}'`); | ||||||||||||||||
}; | ||||||||||||||||
Comment on lines
+129
to
+140
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. There are a number of tests that use Lines 198 to 204 in 172581c
This causes the tests process to immediately exit without reporting which test failed or showing any stack traces. The mechanism I added here allows The new You can see how helpful this new mechanism is when the |
||||||||||||||||
|
||||||||||||||||
async function expectProcessExit(expectedExitCode, run) { | ||||||||||||||||
const callingTest = getCallingTestFn() || ''; | ||||||||||||||||
const shouldUseFallbackExitMock = !callingTest; | ||||||||||||||||
|
||||||||||||||||
let exitCode = 0; | ||||||||||||||||
// $FlowFixMe | ||||||||||||||||
const originalExit = process.exit; | ||||||||||||||||
// $FlowFixMe | ||||||||||||||||
process.exit = (code = 0) => { | ||||||||||||||||
exitCode = code; | ||||||||||||||||
}; | ||||||||||||||||
if (shouldUseFallbackExitMock) { | ||||||||||||||||
// $FlowFixMe | ||||||||||||||||
process.exit = (code = 0) => { | ||||||||||||||||
exitCode = code; | ||||||||||||||||
}; | ||||||||||||||||
} else { | ||||||||||||||||
testsExpectingExit.set(callingTest, 0); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
try { | ||||||||||||||||
await run(); | ||||||||||||||||
} finally { | ||||||||||||||||
// $FlowFixMe | ||||||||||||||||
process.exit = originalExit; | ||||||||||||||||
if (shouldUseFallbackExitMock) { | ||||||||||||||||
// $FlowFixMe | ||||||||||||||||
process.exit = originalExit; | ||||||||||||||||
} else { | ||||||||||||||||
exitCode = testsExpectingExit.get(callingTest) || 0; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
assert.strictEqual( | ||||||||||||||||
exitCode, | ||||||||||||||||
|
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.
This just provides some visual differentiation in the logs