Files
smartdeno/test/test.ts

60 lines
1.8 KiB
TypeScript

import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as smartdeno from '../ts/index.js';
let testSmartdeno: smartdeno.SmartDeno;
tap.test('should create a valid smartdeno instance', async () => {
testSmartdeno = new smartdeno.SmartDeno();
expect(testSmartdeno).toBeInstanceOf(smartdeno.SmartDeno);
expect(testSmartdeno.isRunning()).toBeFalse();
});
tap.test('should throw when executing before start', async () => {
let threw = false;
try {
await testSmartdeno.executeScript('console.log("test")');
} catch (e) {
threw = true;
expect(e.message).toInclude('not started');
}
expect(threw).toBeTrue();
});
tap.test('should download deno and start', async () => {
await testSmartdeno.start({
forceLocalDeno: true
});
expect(testSmartdeno.isRunning()).toBeTrue();
});
tap.test('should execute a script and return result', async () => {
const result = await testSmartdeno.executeScript(`console.log("Hello from Deno!")`);
expect(result.exitCode).toEqual(0);
expect(result.stdout).toInclude('Hello from Deno!');
});
tap.test('should execute a script with permissions', async () => {
const result = await testSmartdeno.executeScript(
`console.log(Deno.env.get("HOME") || "no-home")`,
{ permissions: ['env'] }
);
expect(result.exitCode).toEqual(0);
});
tap.test('should handle script errors gracefully', async () => {
const result = await testSmartdeno.executeScript(`throw new Error("test error")`);
expect(result.exitCode).not.toEqual(0);
});
tap.test('should stop the instance', async () => {
await testSmartdeno.stop();
expect(testSmartdeno.isRunning()).toBeFalse();
});
tap.test('should be idempotent on multiple stop calls', async () => {
await testSmartdeno.stop();
expect(testSmartdeno.isRunning()).toBeFalse();
});
export default tap.start();