feat(core): Add permission-controlled Deno execution, configurable script server port, improved downloader, dependency bumps and test updates
This commit is contained in:
55
test/test.ts
55
test/test.ts
@@ -1,20 +1,59 @@
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartdeno from '../ts/index.js'
|
||||
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 download deno', async () => {
|
||||
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', async () => {
|
||||
await testSmartdeno.executeScript(`console.log("A script from deno!")`);
|
||||
})
|
||||
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.start()
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user