Skip to content

Commit

Permalink
feat: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Oct 6, 2020
1 parent 48ad9f5 commit af60019
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/@jsii/kernel/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ export interface LoadResponse {
export interface InvokeScriptRequest {
readonly pkgname: string;
readonly script: string;
readonly args?: any[];
readonly args?: string[];
}

export interface InvokeScriptResponse {
readonly status: number | null;
readonly stdout: string;
readonly stderr: string;
readonly stdout: Buffer;
readonly stderr: Buffer;
readonly output: string[];
}

Expand Down
9 changes: 6 additions & 3 deletions packages/@jsii/kernel/lib/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,15 @@ export class Kernel {
req: api.InvokeScriptRequest,
): api.InvokeScriptResponse {
const result = cp.spawnSync(
path.join(this._getPackageDir(req.pkgname), req.script),
req.args,
'node',
[path.join(this._getPackageDir(req.pkgname), req.script)].concat(
req.args ?? [],
),
{ encoding: 'utf-8' },
);

return {
output: result.output,
output: [path.join(this._getPackageDir(req.pkgname), req.script)],
stdout: result.stdout,
stderr: result.stderr,
status: result.status,
Expand Down
11 changes: 11 additions & 0 deletions packages/@jsii/kernel/test/kernel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,17 @@ defineTest('Override transitive property', (sandbox) => {
expect(propValue).toBe('N3W');
});

defineTest('invokeBinScript() return output', (sandbox) => {
sandbox.create({ fqn: 'jsii-calc.Calculator' });

const result = sandbox.invokeBinScript({
pkgname: 'jsii-calc',
script: 'bin/calc',
});

expect(result).toEqual('Hello World!\n');
});

// =================================================================================================

const testNames: { [name: string]: boolean } = {};
Expand Down
1 change: 1 addition & 0 deletions packages/@jsii/python-runtime/tests/test_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
from scope.jsii_calc_lib import IFriendly, EnumFromScopedModule, Number
from scope.jsii_calc_lib.custom_submodule_name import IReflectable, ReflectableEntry

from subprocess import Popen, PIPE, STDOUT

# Note: The names of these test functions have been chosen to map as closely to the
# Java Compliance tests as possible.
Expand Down
2 changes: 2 additions & 0 deletions packages/jsii-calc/bin/calc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('./calc.js');
5 changes: 5 additions & 0 deletions packages/jsii-calc/bin/calc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

/* eslint-disable no-console */

console.info('Hello World!');
3 changes: 3 additions & 0 deletions packages/jsii-calc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"bugs": {
"url": "https://github.com/aws/jsii/issues"
},
"bin": {
"calc": "bin/calc"
},
"repository": {
"type": "git",
"url": "https://github.com/aws/jsii.git",
Expand Down
5 changes: 4 additions & 1 deletion packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
],
"url": "https://aws.amazon.com"
},
"bin": {
"calc": "bin/calc"
},
"bundled": {
"@fixtures/jsii-calc-bundled": "^0.19.0"
},
Expand Down Expand Up @@ -14229,5 +14232,5 @@
}
},
"version": "0.0.0",
"fingerprint": "azqNkkl+/4FLzTVBLkOyHcokS4xLoYtHsri0z9kIehQ="
"fingerprint": "QHc8YZS13IljwCQpg6AZlBxIZvkAbfnCFh6Vi+e0Cgg="
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit af60019

Please sign in to comment.