-
Notifications
You must be signed in to change notification settings - Fork 464
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
Set up unit tests #24
Conversation
- Set up a pattern for organizing a .cc and .js test files roughly corresponding to each class to be tested - Add unit tests for the Function and Error classes - Update test binding.gyp file to build on Windows (fix quotes) - Update test binding.gyp and README to enable exceptions with MSVC - Fix type of CallbackInfo::This
test/error.js
Outdated
let err = binding.error.catchError( | ||
() => { throw new TypeError('test'); }); | ||
assert(err instanceof TypeError); | ||
assert.equal(err.message, 'test'); |
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.
Just fyi, this is how we’d write this in Node core right now:
{
const err = binding.error.catchError(
() => { throw new TypeError('test'); });
assert(err instanceof TypeError);
assert.strictEqual(err.message, 'test');
}
(const
wherever possible, block scope + always using strict equality asserts)
test/index.js
Outdated
const assert = require('assert'); | ||
global.buildType = process.config.target_defaults.default_configuration; | ||
global.binding = require(`./build/${buildType}/binding.node`); | ||
global.assert = require('assert'); |
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 means that somebody looking at the test files themselves might need to look up where those “magic” globals come from … I’d be very okay with just copying these lines into the test files themselves :)
That would also have the advantage that they are are runnable as standalone node scripts, which might be nice when the test suite is bigger and takes longer to run.
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.
Yes, I didn't really like this use of global either. Ability to run the test files individually is a good point.
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.
LGTM. I'll add to the TODO's creating a CI job for this.
roughly corresponding to each class to be tested