feat(smartenv): add Bun and Deno OS detection support and update test runtime compatibility

This commit is contained in:
2026-05-01 11:03:45 +00:00
parent 8514c4def0
commit 1c609cc638
14 changed files with 4366 additions and 5894 deletions
+6 -6
View File
@@ -13,7 +13,7 @@ tap.test('should detect Bun runtime correctly', async () => {
expect(testEnv.isNode).toBeFalse();
expect(testEnv.isDeno).toBeFalse();
expect(testEnv.isBrowser).toBeFalse();
console.log(' Bun runtime detected correctly');
console.log('Bun runtime detected correctly');
});
tap.test('should get Bun version', async () => {
@@ -31,27 +31,27 @@ tap.test('should load modules for Bun', async () => {
const pathModule = await testEnv.getSafeModuleFor('bun', 'path');
expect(pathModule).not.toBeUndefined();
expect(typeof pathModule.join).toEqual('function');
console.log(' Successfully loaded module for Bun');
console.log('Successfully loaded module for Bun');
});
tap.test('should load modules for server runtimes', async () => {
const pathModule = await testEnv.getSafeModuleFor('server', 'path');
expect(pathModule).not.toBeUndefined();
expect(typeof pathModule.join).toEqual('function');
console.log(' Successfully loaded module with server target');
console.log('Successfully loaded module with server target');
});
tap.test('should load modules for array of runtimes', async () => {
const pathModule = await testEnv.getSafeModuleFor(['bun', 'node'], 'path');
expect(pathModule).not.toBeUndefined();
expect(typeof pathModule.join).toEqual('function');
console.log(' Successfully loaded module with array target');
console.log('Successfully loaded module with array target');
});
tap.test('should not load modules for wrong runtime', async () => {
const result = await testEnv.getSafeModuleFor('node', 'path');
expect(result).toBeUndefined();
console.log(' Correctly rejected Node.js-only module in Bun');
console.log('Correctly rejected Node.js-only module in Bun');
});
tap.test('should detect OS', async () => {
@@ -78,4 +78,4 @@ tap.test('should detect CI environment if present', async () => {
console.log('CI detection: ' + testEnv.isCI);
});
tap.start();
export default tap.start();
@@ -13,7 +13,7 @@ tap.test('should detect browser runtime correctly', async () => {
expect(testEnv.isNode).toBeFalse();
expect(testEnv.isDeno).toBeFalse();
expect(testEnv.isBun).toBeFalse();
console.log(' Browser runtime detected correctly');
console.log('Browser runtime detected correctly');
});
tap.test('should get user agent', async () => {
@@ -31,18 +31,18 @@ tap.test('should not get server runtime versions', async () => {
expect(testEnv.nodeVersion).toEqual('undefined');
expect(testEnv.denoVersion).toEqual('undefined');
expect(testEnv.bunVersion).toEqual('undefined');
console.log(' Server runtime versions correctly return undefined in browser');
console.log('Server runtime versions correctly return undefined in browser');
});
tap.test('should not load server modules', async () => {
const result = await testEnv.getSafeModuleFor('server', 'path');
expect(result).toBeUndefined();
console.log(' Correctly rejected server module in browser');
console.log('Correctly rejected server module in browser');
});
tap.test('should not detect as CI', async () => {
expect(testEnv.isCI).toBeFalse();
console.log(' CI detection correctly false in browser');
console.log('CI detection correctly false in browser');
});
tap.test('OS detection should return false in browser', async () => {
@@ -52,7 +52,7 @@ tap.test('OS detection should return false in browser', async () => {
expect(resultMac).toBeFalse();
expect(resultLinux).toBeFalse();
expect(resultWindows).toBeFalse();
console.log(' OS detection correctly returns false in browser');
console.log('OS detection correctly returns false in browser');
});
tap.start();
export default tap.start();
+5 -5
View File
@@ -13,7 +13,7 @@ tap.test('should detect Deno runtime correctly', async () => {
expect(testEnv.isNode).toBeFalse();
expect(testEnv.isBun).toBeFalse();
expect(testEnv.isBrowser).toBeFalse();
console.log(' Deno runtime detected correctly');
console.log('Deno runtime detected correctly');
});
tap.test('should get Deno version', async () => {
@@ -32,7 +32,7 @@ tap.test('should load modules for Deno', async () => {
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');
console.log('Successfully loaded module for Deno');
});
tap.test('should load modules for server runtimes', async () => {
@@ -40,13 +40,13 @@ tap.test('should load modules for server runtimes', async () => {
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');
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');
console.log('Correctly rejected Node.js-only module in Deno');
});
tap.test('should detect CI environment if present', async () => {
@@ -56,4 +56,4 @@ tap.test('should detect CI environment if present', async () => {
console.log('CI detection in Deno: ' + isCI);
});
tap.start();
export default tap.start();
+1 -1
View File
@@ -78,4 +78,4 @@ tap.test('should state wether we are in CI', async () => {
}
});
tap.start();
export default tap.start();