From cd318639f3f326457e3163a34b5365b465d311ad Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Mon, 4 Nov 2024 22:40:34 -0500 Subject: [PATCH] WIP: test(transform-io): add node tests --- packages/transform-io/typescript/package.json | 12 ++++++++++-- .../transform-io/typescript/test/node/common.js | 7 +++++++ .../transform-io/typescript/test/node/hdf5-test.js | 14 ++++++++++++++ pnpm-lock.yaml | 3 +++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 packages/transform-io/typescript/test/node/common.js create mode 100644 packages/transform-io/typescript/test/node/hdf5-test.js diff --git a/packages/transform-io/typescript/package.json b/packages/transform-io/typescript/package.json index 10c1f2b1f..d9ac5e32e 100644 --- a/packages/transform-io/typescript/package.json +++ b/packages/transform-io/typescript/package.json @@ -15,7 +15,8 @@ }, "scripts": { "start": "pnpm copyDemoAppAssets && vite", - "test": "echo \"Error: no test specified\"", + "test": "pnpm test:node", + "test:node": "ava", "build": "pnpm build:tsc && pnpm build:browser:workerEmbedded && pnpm build:browser:workerEmbeddedMin && pnpm build:demo", "build:browser:workerEmbedded": "esbuild --loader:.worker.js=dataurl --bundle --format=esm --outfile=./dist/bundle/index-worker-embedded.js ./src/index-worker-embedded.ts", "build:browser:workerEmbeddedMin": "esbuild --minify --loader:.worker.js=dataurl --bundle --format=esm --outfile=./dist/bundle/index-worker-embedded.min.js ./src/index-worker-embedded.min.ts", @@ -36,9 +37,10 @@ "itk-wasm": "workspace:^" }, "devDependencies": { - "@itk-wasm/transform-io-build": "workspace:*", "@itk-wasm/demo-app": "workspace:*", + "@itk-wasm/transform-io-build": "workspace:*", "@types/node": "^20.2.5", + "ava": "^6.1.3", "esbuild": "^0.19.8", "shx": "^0.3.4", "typescript": "^5.3.2", @@ -48,5 +50,11 @@ "repository": { "type": "git", "url": "https://github.com/InsightSoftwareConsortium/ITK-Wasm" + }, + "ava": { + "files": [ + "test/node/**/*", + "!test/node/common.js" + ] } } diff --git a/packages/transform-io/typescript/test/node/common.js b/packages/transform-io/typescript/test/node/common.js new file mode 100644 index 000000000..20ebe703b --- /dev/null +++ b/packages/transform-io/typescript/test/node/common.js @@ -0,0 +1,7 @@ +import path from 'path' +import fs from 'fs' + +export const testInputPath = path.resolve('..', 'test', 'data', 'input') +export const testBaselinePath = path.resolve('..', 'test', 'data', 'baseline') +export const testOutputPath = path.resolve('..', 'test', 'output', 'typescript') +fs.mkdirSync(testOutputPath, { recursive: true }) \ No newline at end of file diff --git a/packages/transform-io/typescript/test/node/hdf5-test.js b/packages/transform-io/typescript/test/node/hdf5-test.js new file mode 100644 index 000000000..73fddb8c5 --- /dev/null +++ b/packages/transform-io/typescript/test/node/hdf5-test.js @@ -0,0 +1,14 @@ +import test from 'ava' +import path from 'path' + +import { hdf5ReadTransformNode } from '../../dist/index-node.js' + +import { testInputPath } from './common.js' + +const testInputFilePath = path.join(testInputPath, 'LinearTransform.h5') + +test('Test reading a HDF5 file', async t => { + const { couldRead, transform } = await hdf5ReadTransformNode(testInputFilePath) + t.true(couldRead) + console.log(transform) +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e4a6ea080..30dca980a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -778,6 +778,9 @@ importers: '@types/node': specifier: ^20.2.5 version: 20.12.10 + ava: + specifier: ^6.1.3 + version: 6.1.3 esbuild: specifier: ^0.19.8 version: 0.19.12