Code Monkey home page Code Monkey logo

cppnodeaddon's Introduction

TDD of a C++ Addon for NodeJs

This repository provides and example for TDD development of an Addon that uses NAN and ObjectWrap to expose a C++ object to NodeJs.

Development Environment: CLion

Javascript Test Framework: Mocha / Chai

Cpp Test Framework: Cppunit

Tested On Mac OS 10.12.5, Node version 8.1.2, Cppunit version:1.14.0

Setting up:

  • Install cppunit
    • Example, for mac: brew install cppunit
  • Install node-gyp and mocha with
    •   sudo npm install -g node-gyp
        sudo npm install -g mocha
      
  • In CLion, set the Javascript version to ES6 in preferences, and enable Node and NPM
  • In ./ and ./test/js directories, run npm install.
  • Edit CMakeLists.txt
    • specify where to find node and nan include files
      • include_directories(/usr/local/include ./node_modules/nan) 
        
    • Rename the executable because main is going to run tests
      • add_executable(CppClassTest ${SOURCE_FILES})
        
    • Add the cpp unit test link library to the target:
      • target_link_libraries(CppClassTest /usr/local/lib/libcppunit.a)
        

Note: when adding source files, the wrapper files should not be added to CMakeLists.txt, but the cpp unit test files should be added.

For example:

set(SOURCE_FILES main.cpp \
    src/SampleObject.cpp \
    src/SampleObject.h \
    test/cpp/BoilerplateTestCase.cpp \
    test/cpp/BoilerplateTestCase.h \
    test/cpp/SampleObjectTestCase.cpp \
    test/cpp/SampleObjectTestCase.h)

Contains all the objects and their tests, but not the wrapper objects (src/SampleObjectWrap.cpp and src/SampleObjectWrap.h)

Running Tests

  • build the project in CLion
  • For C++ tests, just run the main program (in CLion, RUN->CppClassTest)
  • For Js tests, build the project by using the command:
    •   node-gyp configure build
      
  • Then Run the tests with
    •   mocha test/js/*test.js
      

cppnodeaddon's People

Contributors

ralemy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.