Coder Social home page Coder Social logo

Unit Tests about node-pureimage HOT 16 CLOSED

joshmarinacci avatar joshmarinacci commented on July 3, 2024
Unit Tests

from node-pureimage.

Comments (16)

joshmarinacci avatar joshmarinacci commented on July 3, 2024

from node-pureimage.

robertmain avatar robertmain commented on July 3, 2024

Cool - I've had a look at using jest in the place of tape. Reason being is that (in my opinion) it produces better readable test output, it supports mocking and it's easier to configure (pretty much no config out of the box).

The syntax looks like this:

const Point = require('../../src/Point');
const Line  = require('../../src/Line');

describe('Line', () => {

    it('created from two points use them as start and end points', () => {
        let start = new Point(6, 8);
        let end   = new Point(12, 6);

        expect(() => new Line(start, end)).not.toThrow(TypeError);
        expect(() => new Line(6, 8)).toThrow();
    });

    it('created from 4 ordinates uses them as start and end points', () => {
        expect(() => new Line(6, 8, 12, 6)).not.toThrow();
        expect(() => new Line({}, "spaghetti", "hello world", [])).toThrow(TypeError);
    });

    it('can only be created with either 2 or 4 arguments', () => {
        let errorMsg = 'Please pass either two Point objects, or 4 integers to the constructor';

        expect(() => new Line()).toThrow(errorMsg);
        expect(() => new Line(12)).toThrow(errorMsg);
        expect(() => new Line(12, 30, 92)).toThrow(errorMsg);
        expect(() => new Line(12, 30, 92, 10, 99)).toThrow(errorMsg);
    });

    it('is the distance between two points', () => {
        let start = new Point(6, 8);
        let end   = new Point(0, 0);

        let line  = new Line(start, end);

        expect(line.getLength()).toBe(10);
    })
});

Which produces output that looks like this:
image

from node-pureimage.

robertmain avatar robertmain commented on July 3, 2024

Forgot to mention - it also supports mocking too, which might be nice when dealing with dependencies between objects like Context and Bitmap

from node-pureimage.

robertmain avatar robertmain commented on July 3, 2024

@joshmarinacci - I'm just busy converting some of the existing tests into unit tests...I was wondering what this did:

var PImage = require('../src/pureimage');

{

    // compositing tests
    // red onto white
    eq(PImage.compositePixel(0xFF0000FF, 0xFFFFFFFF), 0xFF0000FF);
    // blue onto white
    eq(PImage.compositePixel(0x00FF00FF, 0xFFFFFFFF), 0x00FF00FF);
    // red onto black
    eq(PImage.compositePixel(0xFF0000FF, 0x000000FF), 0xFF0000FF);
    // red 50% onto black
    eq(PImage.compositePixel(0xFF00007F, 0x000000FF), 0x7F0000FF);
}

function eq(a,b) {
    if(a != b) throw new Error(a.toString(16) + " is not equal to " + b.toString(16));
}
function dumpBytes(img) {
    for(var i=0; i<10; i++) {
        console.log(i,img._buffer[i].toString(16));
    }
}

It's clearly testing the compositePixel method - but I'm not quite sure what that method does - I also can't seem to find it in the library anywhere...unless it's referring to the composite method in the Bitmap class?

from node-pureimage.

joshmarinacci avatar joshmarinacci commented on July 3, 2024

from node-pureimage.

robertmain avatar robertmain commented on July 3, 2024

OK, no problem. In the mean time if you have a sec - #42 and #39 are done and ready for review/merge :)

from node-pureimage.

joshmarinacci avatar joshmarinacci commented on July 3, 2024

from node-pureimage.

robertmain avatar robertmain commented on July 3, 2024

haha, no problem - i know how it is :)

not a problem - always happy to help out :D

from node-pureimage.

robertmain avatar robertmain commented on July 3, 2024

Oh by the way - I just looked at https://travis-ci.org/joshmarinacci/node-pureimage and it says it's not an active repo. Have you enabled travis because it looks like it's not running the build

from node-pureimage.

joshmarinacci avatar joshmarinacci commented on July 3, 2024

from node-pureimage.

robertmain avatar robertmain commented on July 3, 2024

Looks like you're missing the GITHUB_TOKEN environment var from Travis. Take a look at the pre-requisites here: #39 (comment) :)

Also - you might want to consider adding a link to http://joshmarinacci.github.io/node-pureimage at the top of your README for the documentation :)

Also - travis should let you rerun the failed build

from node-pureimage.

joshmarinacci avatar joshmarinacci commented on July 3, 2024

from node-pureimage.

robertmain avatar robertmain commented on July 3, 2024

Odd - I took a look and it's mentioning that it couldn't push to gh-pages. It looks like it was saying that it couldn't push to Couldn't push the build to github.com/joshmarinacci/node-pureimage.git:gh-pages. I wonder if maybe the branch didn't exist at that point or something.

Try re-running the individual job again - if that still doesn't do it, you may have to raise an issue with Travis. Either way - looks like the docs are online! http://joshmarinacci.github.io/node-pureimage

from node-pureimage.

robertmain avatar robertmain commented on July 3, 2024

This looks like it might be related to travis-ci/travis-ci#8548

from node-pureimage.

robertmain avatar robertmain commented on July 3, 2024

@joshmarinacci

I emailed Travis support yesterday and they wondered if it might be because all 3 jobs are trying to do the deploy...can you try adding node: $TRAVIS_NODE_VERSION after line 18 of .travis.yml?

Like so:

language: node_js
node_js:
    - "node"
    - "7"
    - "8"
install: npm install
script:
  - npm run-script docs
deploy:
  overwrite: true
  provider: pages
  file_glob: true
  file: docs/*
  local_dir: docs
  skip_cleanup: true
  github_token: $GITHUB_TOKEN
  on:
    branch: master
    node: $TRAVIS_NODE_VERSION

This should restrict it so that only one build job actually deploys

from node-pureimage.

joshmarinacci avatar joshmarinacci commented on July 3, 2024

it looks like all of this was done.

from node-pureimage.

Related Issues (20)

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.