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

Set up unit tests #24

Merged
merged 2 commits into from
Apr 18, 2017
Merged

Set up unit tests #24

merged 2 commits into from
Apr 18, 2017

Conversation

jasongin
Copy link
Member

  • 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

 - 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
@jasongin jasongin requested review from addaleax and mhdawson April 17, 2017 22:35
test/error.js Outdated
let err = binding.error.catchError(
() => { throw new TypeError('test'); });
assert(err instanceof TypeError);
assert.equal(err.message, 'test');
Copy link
Member

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');
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@mhdawson mhdawson left a 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.

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

Successfully merging this pull request may close these issues.

3 participants