Skip to content
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: more useful assert messaging for child-process-execSync #15972

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/sequential/test-child-process-execsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ try {
assert.strictEqual(e.errno, 'ETIMEDOUT');
err = e;
} finally {
assert.strictEqual(ret, undefined, 'we should not have a return value');
assert.strictEqual(ret, undefined,
`should not have a return value, received ${ret}`);
assert.strictEqual(caught, true, 'execSync should throw');
const end = Date.now() - start;
assert(end < SLEEP);
Expand All @@ -74,11 +75,11 @@ cmd = `"${process.execPath}" -e "console.log('${msg}');"`;
ret = execSync(cmd);

assert.strictEqual(ret.length, msgBuf.length);
assert.deepStrictEqual(ret, msgBuf, 'execSync result buffer should match');
assert.deepStrictEqual(ret, msgBuf);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned error message is not going to be great here and therefore it might be better to use a error message that includes both buffers. But this should not be blocking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BridgeAR When I run assert.deepStrictEqual in the default behavior using foobar (as in the test) and foobaz the default assertion thrown is this:

AssertionError: <Buffer 66 6f 6f 62 61 7a 0a> deepStrictEqual <Buffer 66 6f 6f 62 61 72 0a>

Are you saying that I should change it to look something like the following?:

AssertionError: ret  <Buffer 66 6f 6f 62 61 7a 0a> and msgBuf <Buffer 66 6f 6f 62 61 72 0a> should be equal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Na, just ignore my comment ;-)


ret = execSync(cmd, { encoding: 'utf8' });

assert.strictEqual(ret, `${msg}\n`, 'execSync encoding result should match');
assert.strictEqual(ret, `${msg}\n`);

const args = [
'-e',
Expand All @@ -90,8 +91,7 @@ assert.deepStrictEqual(ret, msgBuf);

ret = execFileSync(process.execPath, args, { encoding: 'utf8' });

assert.strictEqual(ret, `${msg}\n`,
'execFileSync encoding result should match');
assert.strictEqual(ret, `${msg}\n`);

// Verify that the cwd option works - GH #7824
{
Expand Down