Skip to content

Commit

Permalink
add tests, remove metadata from Cargo.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
amilajack committed Dec 5, 2018
1 parent 4496ad7 commit 0f45968
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 20 deletions.
16 changes: 16 additions & 0 deletions __test__/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,18 @@ Array [
]
`;

exports[`tests should run async 1`] = `17`;

exports[`tests should run classes 1`] = `User {}`;

exports[`tests should run errors 1`] = `[Function]`;

exports[`tests should run errors 2`] = `[Function]`;

exports[`tests should run fibonacci-task 1`] = `"55"`;

exports[`tests should run fibonacci-task 2`] = `"55"`;

exports[`tests should run functions 1`] = `undefined`;

exports[`tests should run functions 2`] = `12`;
Expand All @@ -40,6 +50,12 @@ exports[`tests should run hello world 1`] = `"hello world!"`;

exports[`tests should run json 1`] = `"Hello, should run john!"`;

exports[`tests should run modules 1`] = `[Function]`;

exports[`tests should run modules 2`] = `[Function]`;

exports[`tests should run modules 3`] = `"baz"`;

exports[`tests should run objects 1`] = `
Object {
"myNumberProperty": 1234,
Expand Down
35 changes: 32 additions & 3 deletions __test__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ const arrays = require('../arrays');
const objects = require('../objects');
const args = require('../arguments');
const functions = require('../functions');
require('../word-counting');
// const fibonacciTask = require('../fibonacci-task');
const fibonacciTask = require('../fibonacci-task');
const sharingBinaryData = require('../sharing-binary-data');
const json = require('../json');
const classes = require('../classes');
const modules = require('../modules');
const errors = require('../errors');
const async = require('../async');
require('../word-counting');

describe('tests', () => {
it('should run hello world', () => {
Expand Down Expand Up @@ -51,7 +54,7 @@ describe('tests', () => {
});

it('should run json', () => {
expect(json.say_hello('should run john')).toMatchSnapshot();
expect(json.sayHello('should run john')).toMatchSnapshot();
});

it('should run share binary data', () => {
Expand All @@ -63,4 +66,30 @@ describe('tests', () => {
const user = new User(0, 'John', 'Doe', 'johndoe@gmail.com');
expect(user).toMatchSnapshot();
});

it('should run fibonacci-task', async () => {
const fib10 = await new Promise(resolve => {
fibonacciTask.fibonacci(10, (err, result) => resolve(result));
});
expect(fib10).toMatchSnapshot();
expect(fibonacciTask.fibonacciSync(10)).toMatchSnapshot();
});

it('should run modules', () => {
expect(modules.hello).toMatchSnapshot();
expect(modules.User).toMatchSnapshot();
expect(modules.baz).toMatchSnapshot();
});

it('should run errors', () => {
expect(errors.throwError).toMatchSnapshot();
expect(errors.throwCustomError).toMatchSnapshot();
});

it('should run async', async () => {
const result = await new Promise(resolve => {
async.performAsyncTask((err, value) => resolve(value));
});
expect(result).toMatchSnapshot();
});
});
1 change: 0 additions & 1 deletion arguments/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "arguments"
version = "0.1.0"
license = "MIT"
build = "build.rs"
exclude = ["artifacts.json", "index.node"]

Expand Down
1 change: 0 additions & 1 deletion arrays/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "arrays"
version = "0.1.0"
license = "MIT"
build = "build.rs"
exclude = ["artifacts.json", "index.node"]

Expand Down
2 changes: 0 additions & 2 deletions async/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[package]
name = "async"
version = "0.1.0"
authors = ["Amila Welihinda <amilajack@gmail.com>"]
license = "MIT"
build = "build.rs"
exclude = ["artifacts.json", "index.node"]

Expand Down
2 changes: 0 additions & 2 deletions errors/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[package]
name = "errors"
version = "0.1.0"
authors = ["Amila Welihinda <amilajack@gmail.com>"]
license = "MIT"
build = "build.rs"
exclude = ["artifacts.json", "index.node"]

Expand Down
6 changes: 3 additions & 3 deletions errors/native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn throw_error(mut cx: FunctionContext) -> JsResult<JsString> {
Ok(cx.string("hello to you too!"))
}

/// Throw type error
/// Throw TypeError
fn throw_type_error(mut cx: FunctionContext) -> JsResult<JsValue> {
let foo: JsResult<JsError> = cx.throw_type_error("not enough arguments");
Ok(cx.string("throw_error node").upcast())
Expand All @@ -37,8 +37,8 @@ fn throw_custom_error(mut cx: FunctionContext) -> JsResult<JsError> {
error
}

/// Creating error objects. These will not throw errors. They will
/// only create them
/// Creating error objects. This function will not throw errors. It will
/// only create them and return them
fn create_error_obj(mut cx: FunctionContext) -> JsResult<JsError> {
let arg0 = cx.argument::<JsString>(0)?.value();

Expand Down
1 change: 0 additions & 1 deletion functions/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
license = "MIT"
build = "build.rs"
exclude = ["artifacts.json", "index.node"]

Expand Down
4 changes: 2 additions & 2 deletions json/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const addon = require('../native/index.node');

// console.log(addon.say_hello());
// console.log(addon.sayHello());
// fails: TypeError: not enough arguments

console.log(addon.say_hello('john'));
console.log(addon.sayHello('john'));
// Hello, john!

// console.log(addon.greet({ name: "afsd" }));
Expand Down
2 changes: 1 addition & 1 deletion json/native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct User {
}

export! {
fn say_hello(name: String) -> String {
fn sayHello(name: String) -> String {
format!("Hello, {}!", name)
}

Expand Down
2 changes: 0 additions & 2 deletions modules/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[package]
name = "modules"
version = "0.1.0"
authors = ["Amila Welihinda <amilajack@gmail.com>"]
license = "MIT"
build = "build.rs"
exclude = ["artifacts.json", "index.node"]

Expand Down
1 change: 0 additions & 1 deletion objects/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "objects"
version = "0.1.0"
license = "MIT"
build = "build.rs"
exclude = ["artifacts.json", "index.node"]

Expand Down
1 change: 0 additions & 1 deletion primitives/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "primitives"
version = "0.1.0"
license = "MIT"
build = "build.rs"
exclude = ["artifacts.json", "index.node"]

Expand Down

0 comments on commit 0f45968

Please sign in to comment.