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

Unable to compose power-assert + espower in vanilla node 7 or 8 #85

Closed
TehShrike opened this issue May 20, 2017 · 9 comments
Closed

Unable to compose power-assert + espower in vanilla node 7 or 8 #85

TehShrike opened this issue May 20, 2017 · 9 comments

Comments

@TehShrike
Copy link

TehShrike commented May 20, 2017

I am trying to use power-assert to get pretty assert output in node, without using mocha or babel.

I'm trying to implement assertions by reading the documentation, but haven't been able to get it working so far.

Here is my attempt at a "vanilla node" (no mocha) seed: https://github.com/TehShrike/power-assert-espower-repro

entry point:

require('espower-loader')({
	pattern: 'test/*.js',
})

require('./test/test.js')

test/test.js:

const assert = require('power-assert')

const test = () => {
	const value1 = true
	const value2 = 3
	assert.deepEqual({ value: value1 }, { value: value2 })
}

test()

Instead of a nice pretty error message, I get:

/Users/josh/code/power-assert-espower-repro/node_modules/empower-core/lib/decorator.js:110
        ret = func.apply(thisObj, args);
                   ^
AssertionError: { value: true } deepEqual { value: 3 }
    at Decorator._callFunc (/Users/josh/code/power-assert-espower-repro/node_modules/empower-core/lib/decorator.js:110:20)
(snip)

What am I missing? I'm guessing this is a documentation/implementation issue, and not an actual bug.

(node 7.6.0)

@twada
Copy link
Member

twada commented May 21, 2017

@TehShrike Thank you for reporting and creating repro case!

I confirmed that vanilla assertions under Node v6 produces pretty output but Node v7 doesn't (but Node v7 + mocha produces pretty output as well).

I'll investigate this issue a bit deeper.

@TehShrike
Copy link
Author

Awesome, thank you so much.

@TehShrike TehShrike changed the title Unable to compose power-assert + espower in node Unable to compose power-assert + espower in node 7 May 22, 2017
@TehShrike
Copy link
Author

Looks like node 8 behaves the same as node 7.

@twada
Copy link
Member

twada commented Jun 1, 2017

@TehShrike Thank you for the information. I'm bit busy this week but still investigating...

@azu
Copy link
Member

azu commented Jun 1, 2017

I've figured out this.

// MIT © 2017 azu
const assert = require("assert");
try {
    assert(false);
} catch (e) {
    e.message = "custom message";
    throw e;
}

Node.js 6


/Users/azu/.ghq/github.com/TehShrike/power-assert-espower-repro/assert-error.js:7
    throw e;
    ^
AssertionError: custom message
    at Object.<anonymous> (/Users/azu/.ghq/github.com/TehShrike/power-assert-espower-repro/assert-error.js:4:5)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.runMain (module.js:590:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

Node.js 7

/Users/azu/.ghq/github.com/TehShrike/power-assert-espower-repro/assert-error.js:7
    throw e;
    ^
AssertionError: false == true
    at Object.<anonymous> (/Users/azu/.ghq/github.com/TehShrike/power-assert-espower-repro/assert-error.js:4:5)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:535:3

Node.js 8:

(Error code is added: nodejs/node#12651)

/Users/azu/.ghq/github.com/TehShrike/power-assert-espower-repro/assert-error.js:7
    throw e;
    ^

AssertionError [ERR_ASSERTION]: false == true
    at Object.<anonymous> (/Users/azu/.ghq/github.com/TehShrike/power-assert-espower-repro/assert-error.js:4:5)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

Actually, empower does e.message = buildPowerAssertText(formatter, errorEvent.originalMessage, errorEvent.powerAssertContext);.

But, Node.js 7~ does not show this e.message of throwing AssertionError.

I think that Node.js 7~ treat AssertionError as special object.

try {
    throw new Error("!");
} catch (e) {
    e.message = "custom message";
    throw e;
}

Node 8 work fine.

✈ node assert-error.js
/Users/azu/.ghq/github.com/TehShrike/power-assert-espower-repro/assert-error.js:7
    throw e;
    ^

Error: custom message
    at Object.<anonymous> (/Users/azu/.ghq/github.com/TehShrike/power-assert-espower-repro/assert-error.js:4:11)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

@azu
Copy link
Member

azu commented Jun 1, 2017

This change is introduced by nodejs/node#11273

@TehShrike TehShrike changed the title Unable to compose power-assert + espower in node 7 Unable to compose power-assert + espower in node 7 or 8 Jun 2, 2017
twada added a commit to power-assert-js/empower that referenced this issue Jun 3, 2017
when `modifyMessageOnRethrow` option is truthy.
since Node v8 (and v7) does not update message on rethrow.

refs power-assert-js/power-assert#85
@twada twada changed the title Unable to compose power-assert + espower in node 7 or 8 Unable to compose power-assert + espower in vanilla node 7 or 8 Jun 8, 2017
twada added a commit to power-assert-js/empower that referenced this issue Jun 8, 2017
when `modifyMessageOnRethrow` option is truthy.
since Node v8 (and v7) does not update message on rethrow.

refs power-assert-js/power-assert#85
@TehShrike
Copy link
Author

TehShrike commented Jun 9, 2017

After updating the dependencies in my power-assert-espower-repro repository (and removing the duplicate log/throw), this is the output using node 8:

> power-assert-espower-repro@1.0.0 test /Users/josh/code/power-assert-espower-repro
> node index.js

AssertionError [ERR_ASSERTION]:   # test/test.js:6
  
  assert.deepEqual({ value: value1 }, { value: value2 })
                   |        |         |        |        
                   |        |         |        3        
                   |        true      Object{value:3}   
                   Object{value:true}    

@twada
Copy link
Member

twada commented Jun 9, 2017

@TehShrike Yeah we did it! Thank you for reporting again.

@twada
Copy link
Member

twada commented Jun 14, 2017

This issue is fixed by power-assert 1.4.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants