60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||
import * as smartenv from '../ts/index.js';
|
||
|
||
let testEnv: smartenv.Smartenv;
|
||
|
||
tap.test('should create smartenv instance', async () => {
|
||
testEnv = new smartenv.Smartenv();
|
||
});
|
||
|
||
tap.test('should detect Deno runtime correctly', async () => {
|
||
expect(testEnv.runtimeEnv).toEqual('deno');
|
||
expect(testEnv.isDeno).toBeTrue();
|
||
expect(testEnv.isNode).toBeFalse();
|
||
expect(testEnv.isBun).toBeFalse();
|
||
expect(testEnv.isBrowser).toBeFalse();
|
||
console.log(' Deno runtime detected correctly');
|
||
});
|
||
|
||
tap.test('should get Deno version', async () => {
|
||
const version = testEnv.denoVersion;
|
||
expect(version).not.toEqual('undefined');
|
||
expect(typeof version).toEqual('string');
|
||
console.log('Deno version is ' + version);
|
||
});
|
||
|
||
tap.test('should print environment', async () => {
|
||
testEnv.printEnv();
|
||
});
|
||
|
||
tap.test('should load modules for Deno', async () => {
|
||
// Deno requires 'node:' prefix for Node.js built-in modules
|
||
const pathModule = await testEnv.getSafeModuleFor('deno', 'node:path');
|
||
expect(pathModule).not.toBeUndefined();
|
||
expect(typeof pathModule.join).toEqual('function');
|
||
console.log(' Successfully loaded module for Deno');
|
||
});
|
||
|
||
tap.test('should load modules for server runtimes', async () => {
|
||
// Deno requires 'node:' prefix for Node.js built-in modules
|
||
const pathModule = await testEnv.getSafeModuleFor('server', 'node:path');
|
||
expect(pathModule).not.toBeUndefined();
|
||
expect(typeof pathModule.join).toEqual('function');
|
||
console.log(' Successfully loaded module with server target');
|
||
});
|
||
|
||
tap.test('should not load modules for wrong runtime', async () => {
|
||
const result = await testEnv.getSafeModuleFor('node', 'node:path');
|
||
expect(result).toBeUndefined();
|
||
console.log(' Correctly rejected Node.js-only module in Deno');
|
||
});
|
||
|
||
tap.test('should detect CI environment if present', async () => {
|
||
// CI detection relies on Node.js process.env, which may not work in Deno
|
||
// This test documents expected behavior
|
||
const isCI = testEnv.isCI;
|
||
console.log('CI detection in Deno: ' + isCI);
|
||
});
|
||
|
||
tap.start();
|