-
Notifications
You must be signed in to change notification settings - Fork 18
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: Reduce output noise #316
Conversation
This context property was changed in the component itself, but overlooked in the test as it did not create a failure, just an error log. ``` console.error Warning: React does not recognize the `projectPath` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `projectpath` instead. If you accidentally passed it from a parent component, remove it from the DOM element. at code at CodeBlock (/Users/davidcalhoun/Sites/a8c/studio/src/components/assistant-code-block.tsx:22:32) 15 | 16 | it( 'should render inline styles for language-generic code', () => { > 17 | render( <CodeBlock children="example-code" /> ); | ^ 18 | 19 | expect( screen.getByText( 'example-code' ) ).toBeVisible(); 20 | expect( screen.queryByText( 'Copy' ) ).not.toBeInTheDocument(); ```
Minimize unnecessary noise in test output. ``` console.warn PHP.run() output was: #!/usr/bin/env php at _NodePHP.run (node_modules/@php-wasm/node/index.cjs:72997:17) console.error PHPExecutionFailureError2: PHP.run() failed with exit code 1 and the following output: at _NodePHP.run (/Users/davidcalhoun/Sites/a8c/studio/node_modules/@php-wasm/node/index.cjs:72998:23) { response: _PHPResponse { httpStatusCode: 500, headers: { 'x-powered-by': [Array], 'content-type': [Array] }, bytes: Uint8Array(19) [ 35, 33, 47, 117, 115, 114, 47, 98, 105, 110, 47, 101, 110, 118, 32, 112, 104, 112, 10 ], exitCode: 1, errors: '' }, source: 'request' } at _NodePHP.run (node_modules/@php-wasm/node/index.cjs:73003:17) ```
Addresses warning logged in test output: ``` (node:82794) [DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead (Use `node --trace-deprecation ...` to show where the warning was created) ```
Reduce the noise in test results caused by various usages of `console` within the source.
@@ -8,7 +8,7 @@ describe( 'createCodeComponent', () => { | |||
const contextProps = { | |||
blocks: [], | |||
updateMessage: jest.fn(), | |||
projectPath: '/path/to/project', | |||
siteId: '1', |
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 mirrors recent changes from #300.
@@ -18,7 +18,7 @@ describe( 'executeWPCli', () => { | |||
fs.writeFileSync( path.join( tmpPath, 'index.php' ), '' ); | |||
} ); | |||
afterAll( () => { | |||
fs.rmdirSync( tmpPath, { recursive: true } ); |
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.
Based on the observed log, this method is deprecated.
(node:82794) [DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead
(Use `node --trace-deprecation ...` to show where the warning was created)
console.error = jest.fn(); | ||
console.warn = jest.fn(); |
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.
As noted in the above test description, we expect an error to occur. Silencing it for test output reduces noise.
* TODO: Replace this manual filter with a more robust logger that can be | ||
* disabled for the testing environment. Consider enabling a lint rule that | ||
* discourages direct use of `console` methods. |
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.
I consider this filtering approach to be a quick solution, but a more ideal solution would be a central logger utility that manages and formats logging in a consistent manner. This might allow us to disable logs in certain contexts (e.g., test runs via a VERBOSE=false
environment variable) and ensure the same information (e.g., helpful metadata) is included for each log.
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.
The changes look good on my end. I tested the changes against the trunk and the output looks much cleaner 👍 Thanks for making this improvement
Proposed Changes
Reduce the amount of noise found in test output to decrease the likelihood that we introduce new errors, warnings, or failures without noticing. Long term, we might consider leveraging
@wordpress/jest-console
to trigger a test failure whenever console output exists occurs from a test.fs.rmdir
withfs.rm
.Additional context can be found in the body of each commit message.
Testing Instructions
npm run test
Pre-merge Checklist
Footnotes
The one remaining warning relates to an identifiable issue stemming from usage of
@php-wasm/node
. ↩