Skip to content

Commit d30cbad

Browse files
committed
Add tests for Node port export functions
1 parent 7039968 commit d30cbad

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

source/ports/node_port/test/index.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ describe('metacall', () => {
4646
});
4747
});
4848

49-
// TODO: This fails in NodeJS 15.x because the error message is slightly different
49+
// TODO: This fails in NodeJS 15.x because the error message is slightly different
5050
/*
51-
describe('fail', () => {
51+
describe('fail', () => {
5252
it('require', () => {
5353
assert.throws(() => { require('./asd.invalid') }, new Error('Cannot find module \'./asd.invalid\''));
5454
// TODO: Improve error messages
@@ -59,7 +59,7 @@ describe('metacall', () => {
5959
assert.throws(() => { require('./asd.tsx') }, new Error('MetaCall could not load from file'));
6060
});
6161
});
62-
*/
62+
*/
6363

6464
describe('load', () => {
6565
it('metacall_load_from_file (py)', () => {
@@ -69,6 +69,14 @@ describe('metacall', () => {
6969
assert.notStrictEqual(script, undefined);
7070
assert.strictEqual(script.name, 'helloworld.py');
7171
});
72+
it('metacall_load_from_file_export (py)', () => {
73+
const handle = metacall_load_from_file_export('py', [ 'ducktype.py' ] );
74+
assert.notStrictEqual(handle, undefined);
75+
assert.strictEqual(handle.sum(1, 2), 3);
76+
77+
// TODO: Need a way to test the symbol is not globally defined.
78+
//assert.strictEqual(metacall('sum'), undefined);
79+
});
7280
it('metacall_load_from_file (rb)', () => {
7381
assert.strictEqual(metacall_load_from_file('rb', [ 'ducktype.rb' ]), undefined);
7482

@@ -80,6 +88,14 @@ describe('metacall', () => {
8088
assert.strictEqual(metacall_load_from_memory('py', 'def py_memory():\n\treturn 4;\n'), undefined);
8189
assert.strictEqual(metacall('py_memory'), 4.0);
8290
});
91+
it('metacall_load_from_memory_export (py)', () => {
92+
const handle = metacall_load_from_memory_export('py', 'def py_memory_export():\n\treturn 6;\n');
93+
assert.notStrictEqual(handle, undefined);
94+
assert.strictEqual(handle.py_memory_export(), 6.0);
95+
96+
// TODO: Need a way to test the symbol is not globally defined.
97+
//assert.strictEqual(metacall('py_memory_export'), undefined);
98+
});
8399
// Cobol tests are conditional (in order to pass CI/CD)
84100
if (process.env['OPTION_BUILD_LOADERS_COB']) {
85101
it('metacall_load_from_file (cob)', () => {
@@ -124,15 +140,15 @@ describe('metacall', () => {
124140
assert.notStrictEqual(escape, undefined);
125141
assert.strictEqual(escape('<html></html>'), '&lt;html&gt;&lt;/html&gt;');
126142
});
127-
// TODO: This fails, not sure why
128-
/*
143+
// TODO: This fails, not sure why
144+
/*
129145
it('require (py submodule)', () => {
130146
// This code loads directly a module without extension from Python
131147
const { py_encode_basestring_ascii } = require('json.encoder');
132148
assert.notStrictEqual(py_encode_basestring_ascii, undefined);
133149
assert.strictEqual(py_encode_basestring_ascii('asd'), '"asd"');
134150
});
135-
*/
151+
*/
136152
it('require (rb)', () => {
137153
// TODO: Both methods work, should we disable the commented out style to be NodeJS compilant?
138154
// const cache = require('cache.rb');
@@ -160,8 +176,8 @@ describe('metacall', () => {
160176
});
161177
});
162178

163-
// TODO: This fails because classes are not implemented in the NodeJS loader
164-
/*
179+
// TODO: This fails because classes are not implemented in the NodeJS loader
180+
/*
165181
describe('callback', () => {
166182
it('callback (py)', () => {
167183
const py_f = require('function.py');
@@ -209,7 +225,7 @@ describe('metacall', () => {
209225
assert.strictEqual(py_f.function_myclass_cb((klass) => py_f.function_myclass_method(klass)), 'hello world');
210226
assert.strictEqual(py_f.function_myclass_cb((klass) => py_f.function_myclass_method(klass)), 'hello world'); // Check for function lifetime
211227
*/
212-
/*
228+
/*
213229
214230
// Double recursion
215231
const sum = (value, f) => value <= 0 ? 0 : value + f(value - 1, sum);
@@ -279,5 +295,5 @@ describe('metacall', () => {
279295
assert.strictEqual(py_factorial(5), 120);
280296
});
281297
});
282-
*/
298+
*/
283299
});

0 commit comments

Comments
 (0)