Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MemoryHandle type from js-pdk #10

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion deno.lock

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

18 changes: 6 additions & 12 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "@extism/js-pdk"

declare const Host: {
inputBytes: () => void;
inputString: () => void;
Expand All @@ -8,23 +10,15 @@ declare const Host: {
// @ts-ignore
const { call, time, assert, group, reset, mock_input } = Host.getFunctions();

interface MemoryHandle {
offset: number;
length: number;
free(): void;
readBuffer(): ArrayBuffer;
readString(): string;
}

type Input = string | ArrayBuffer | object;

Host.inputBytes = function () {
Host.inputBytes = function() {
throw "Tests do not accept any input";
};

Host.inputString = Host.inputBytes;

Host.outputBytes = function (n: any) {
Host.outputBytes = function(n: any) {
throw "Tests should not return any output";
};

Expand Down Expand Up @@ -78,7 +72,7 @@ export class Test {
// this input is defined in an xtp.toml file, or by the --mock-input-data or --mock-input-file flags.
static mockInputBuffer(): ArrayBuffer {
const inputMem = Test.mockInput();
const buf = inputMem.readBuffer();
const buf = inputMem.readBytes();
inputMem.free();
return buf;
}
Expand Down Expand Up @@ -141,7 +135,7 @@ export class Test {
funcName: string,
input: Input,
): ArrayBuffer {
return Test.call(funcName, input).readBuffer();
return Test.call(funcName, input).readBytes();
}

// assert that the `outcome` is true, naming the assertion with `name`, which will be used as a label in the CLI runner. The `reason` argument
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
"description": "XTP test harness",
"main": "index.ts",
"scripts": {
"check": "tsc index.ts --noEmit"
"check": "tsc --noEmit"
},
"author": "Dylibso <[email protected]>",
"license": "BSD-3-Clause",
"devDependencies": {
"@extism/js-pdk": "^1.0.1"
},
"dependencies": {
"typescript": "^5.4.3"
}
Expand Down
24 changes: 24 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "es2020", // Specify ECMAScript target version
"module": "commonjs", // Specify module code generation
"lib": [
"es2020"
], // Specify a list of library files to be included in the compilation
"types": [
"@extism/js-pdk",
"./test.d.ts"
], // Specify a list of type definition files to be included in the compilation
"strict": true, // Enable all strict type-checking options
"esModuleInterop": true, // Enables compatibility with Babel-style module imports
"skipLibCheck": true, // Skip type checking of declaration files
"allowJs": true, // Allow JavaScript files to be compiled
"noEmit": true // Do not emit outputs (no .js or .d.ts files)
},
"include": [
"*.ts" // Include all TypeScript files in root directory
],
"exclude": [
"node_modules" // Exclude the node_modules directory
]
}
Loading