Skip to content

Commit

Permalink
NodeJS tests working properly with npm installer in metacall.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Jan 22, 2020
1 parent 762737c commit 0a0e5ef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
26 changes: 17 additions & 9 deletions tests/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,26 @@ RUN cd / \
&& tar -xzf tarball.tar.gz \
&& rm tarball.tar.gz

COPY tests/node/test.js /

COPY tests/scripts/ /scripts/

COPY tests/node/test.js /scripts/

ARG CACHE_INVALIDATE

RUN export NODE_ENV=debug \
&& echo "Running tests ${CACHE_INVALIDATE}" \
&& cd / \
&& sed -i "s#@METACALL_LIBRARY_PATH@#`find /gnu/store/ -type d -name '*metacall*[^R]' | head -n 1`/lib/libnode_port.node#g" test.js \
&& node test.js | grep \
-e 'Hello World' \
-e '666667'
RUN echo "Running tests ${CACHE_INVALIDATE}" \
&& export NODE_ENV=debug \
&& export LOADER_SCRIPT_PATH="/scripts/" \
&& export LOADER_LIBRARY_PATH="`find /gnu/store/ -type d -name '*metacall*[^R]' | head -n 1`/lib" \
&& export NODE_PATH="`find /gnu/store/ -type d -name '*libnode*' | head -n 1`/lib/node_modules" \
&& export NODE_EXE_PATH="`find /gnu/store/ -type d -name '*node*' | head -n 1`/bin/node" \
&& `find /gnu/store/ -type d -name '*metacall*[^R]' | head -n 1`/metacallcli install node metacall \
&& echo 'call mock()\nexit' | `find /gnu/store/ -type d -name '*metacall*[^R]' | head -n 1`/metacallcli load node test.js \
| grep \
-e 'Hello World'

# TODO: Check why calling python function ceates a deadlock
# && echo 'call python()\nexit' | `find /gnu/store/ -type d -name '*metacall*[^R]' | head -n 1`/metacallcli load node test.js \
# | grep \
# -e '666667'

ENTRYPOINT ["sh", "-c"]
22 changes: 14 additions & 8 deletions tests/node/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@


const path = require('path');
const { metacall, metacall_load_from_file, metacall_inspect } = require('@METACALL_LIBRARY_PATH@');
const { metacall, metacall_load_from_file, metacall_inspect } = require('metacall');

/* TODO: Monkey-patch */

/* Mock */
console.log(metacall_load_from_file('mock', [ 'test.mock' ]));
console.log(metacall('three_str', 'a', 'b', 'c'));
module.exports = {
mock: function() {
/* Mock */
console.log(metacall_load_from_file('mock', [ 'test.mock' ]));
console.log(metacall('three_str', 'a', 'b', 'c'));
},
python: function() {
/* Python */
console.log(metacall_load_from_file('py', [ 'sum.py' ]));
console.log(metacall_inspect());
console.log(metacall('sum', 111111, 222222, 33334));
},
};

/* Python */
console.log(metacall_load_from_file('py', [ '/scripts/sum.py' ]));
console.log(metacall_inspect());
console.log(metacall('sum', 111111, 222222, 33334));

0 comments on commit 0a0e5ef

Please sign in to comment.