Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions test/adapters/test-js.create-adapter.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
"language": "JavaScript",
"nodeVersion": "20",
"adminUi": "json",
"tabReact": "no",
"eslintConfig": "official",
"tools": [
"ESLint",
"type checking"
"ESLint"
],
"releaseScript": "no",
"devServer": "no",
Expand All @@ -40,5 +41,5 @@
"defaultBranch": "main",
"license": "MIT License",
"dependabot": "yes",
"creatorVersion": "2.6.5"
"creatorVersion": "3.0.0"
}
9 changes: 5 additions & 4 deletions test/adapters/test-pure-ts.create-adapter.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
"connectionType": "local",
"dataSource": "poll",
"connectionIndicator": "no",
"language": "TypeScript",
"language": "TypeScript (without build)",
"nodeVersion": "20",
"adminUi": "json",
"tabReact": "no",
"eslintConfig": "official",
"tools": [
"ESLint",
"type checking"
"ESLint"
],
"releaseScript": "no",
"devServer": "no",
Expand All @@ -42,5 +43,5 @@
"defaultBranch": "main",
"license": "MIT License",
"dependabot": "yes",
"creatorVersion": "2.6.5"
"creatorVersion": "3.0.0"
}
7 changes: 4 additions & 3 deletions test/adapters/test-ts.create-adapter.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
"language": "TypeScript",
"nodeVersion": "20",
"adminUi": "json",
"tabReact": "no",
"eslintConfig": "official",
"tools": [
"ESLint",
"type checking"
"ESLint"
],
"releaseScript": "no",
"devServer": "no",
Expand All @@ -41,5 +42,5 @@
"defaultBranch": "main",
"license": "MIT License",
"dependabot": "yes",
"creatorVersion": "2.6.5"
"creatorVersion": "3.0.0"
}
35 changes: 6 additions & 29 deletions test/pure-ts-adapters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const { describe, it, before, after } = require('mocha');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const {
runCommand,
const {
runCommand,
runCommandWithSignal,
runCommandWithFileChange,
setupTestAdapter,
setupTestAdapter,
cleanupTestAdapter,
validateIoPackageJson,
validatePackageJson,
Expand Down Expand Up @@ -37,30 +37,8 @@ describe('dev-server integration tests - Pure TypeScript', function () {
adapterName: 'Pure TypeScript',
configFile: PURE_TS_ADAPTER_CONFIG,
adapterDir: PURE_TS_ADAPTER_DIR,
adaptersDir: ADAPTERS_DIR,
needsTypeScriptPatching: true
adaptersDir: ADAPTERS_DIR
});

// Patch package.json to point main directly to src/main.ts (pure TypeScript mode)
const packageJsonPath = path.join(PURE_TS_ADAPTER_DIR, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
packageJson.main = 'src/main.ts'; // Point directly to TypeScript file
packageJson.files.push('src/'); // Ensure src is included in files

// Remove build scripts as they're not needed for pure TypeScript mode
if (packageJson.scripts) {
delete packageJson.scripts.build;
delete packageJson.scripts['build:ts'];
delete packageJson.scripts.prebuild;
delete packageJson.scripts.watch;
delete packageJson.scripts['watch:ts'];

// Keep type checking but make it not generate files
packageJson.scripts.build = 'tsc --noEmit';
}

fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
console.log(`Patched ${packageJsonPath} to use pure TypeScript mode`);
});

after(() => {
Expand All @@ -83,9 +61,8 @@ describe('dev-server integration tests - Pure TypeScript', function () {
assert.strictEqual(packageJson.main, 'src/main.ts', 'main field should point to src/main.ts');

// Verify the build scripts have been removed
assert.ok(packageJson.scripts.build.includes("--noEmit"), 'build script should be removed');
assert.ok(!packageJson.scripts?.['build:ts'], 'build:ts script should be removed');
assert.ok(!packageJson.scripts?.prebuild, 'prebuild script should be removed');
assert.ok(packageJson.scripts.check?.includes("--noEmit"), 'check script should use --noEmit for type checking only');
assert.ok(!packageJson.scripts?.prebuild, 'prebuild script should not exist');
});

it('should have TypeScript source file but no dist directory', () => {
Expand Down
30 changes: 16 additions & 14 deletions test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function runCommand(command, args, options = {}) {
proc.on('close', (code) => {
if (rejectedOrResolved) return;
if (timeoutId) clearTimeout(timeoutId);
console.log(`Process exited with code ${code}`);
if (code === 0 || code === 255) {
setTimeout(() => resolve({ stdout, stderr, code }), 5000);
} else {
Expand Down Expand Up @@ -116,12 +117,12 @@ function runCommandWithTimeout(command, args, options = {}) {
if (options.verbose) {
console.log('STDOUT:', str.trim());
}

// Call custom stdout handler if provided
if (options.onStdout) {
options.onStdout(str, shutDown);
}

// Default behavior: shutdown on final message
if (!options.onStdout && options.finalMessage && str.match(options.finalMessage) && !closed && !resolvedOrRejected) {
console.log('Final message detected, shutting down...');
Expand Down Expand Up @@ -196,7 +197,8 @@ async function createTestAdapter(configFile, targetDir) {
'@iobroker/create-adapter@latest',
`--replay=${configPath}`,
`--target=${targetDir}`,
'--noInstall' // Skip npm install to speed up creation
'--noInstall', // Skip npm install to speed up creation
'--nonInteractive' // Run in non-interactive mode to fill in missing config details
], {
cwd: targetDir,
timeout: 180000, // 3 minutes
Expand Down Expand Up @@ -250,7 +252,7 @@ async function setupTestAdapter(config) {

// Install dependencies
await installAdapterDependencies(adapterName, adapterDir);

console.log(`${adapterName} test adapter prepared successfully`);
}

Expand All @@ -260,7 +262,7 @@ async function setupTestAdapter(config) {
async function applyTypeScriptPatches(adapterDir) {
const mainTsPath = path.join(adapterDir, 'src', 'main.ts');
let mainTsContent = fs.readFileSync(mainTsPath, 'utf8');

// Patch variable declarations for TypeScript compliance
mainTsContent = mainTsContent.replace(
'let result = await this.checkPasswordAsync("admin", "iobroker");',
Expand All @@ -274,7 +276,7 @@ async function applyTypeScriptPatches(adapterDir) {
'this.log.info("check group user admin group admin: " + result);',
'this.log.info("check group user admin group admin: " + groupResult);',
);

fs.writeFileSync(mainTsPath, mainTsContent, 'utf8');
console.log(`Patched ${mainTsPath} for TypeScript compliance`);
}
Expand Down Expand Up @@ -314,7 +316,7 @@ function cleanupTestAdapter(adapterName, adapterDir) {
function validateIoPackageJson(adapterDir, expectedName, shouldHaveTypescript = false) {
const ioPackagePath = path.join(adapterDir, 'io-package.json');
const assert = require('node:assert');

assert.ok(fs.existsSync(ioPackagePath), 'io-package.json not found');

const ioPackage = JSON.parse(fs.readFileSync(ioPackagePath, 'utf8'));
Expand All @@ -328,18 +330,18 @@ function validateIoPackageJson(adapterDir, expectedName, shouldHaveTypescript =
}

/**
* Common assertions for package.json validation
* Common assertions for package.json validation
*/
function validatePackageJson(adapterDir) {
const packagePath = path.join(adapterDir, 'package.json');
const assert = require('node:assert');

assert.ok(fs.existsSync(packagePath), 'package.json not found');

const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
assert.ok(packageJson.name, 'package.json missing name');
assert.ok(packageJson.version, 'package.json missing version');

return packageJson;
}

Expand All @@ -349,7 +351,7 @@ function validatePackageJson(adapterDir) {
function validateTypeScriptConfig(adapterDir) {
const tsconfigPath = path.join(adapterDir, 'tsconfig.json');
const assert = require('node:assert');

assert.ok(fs.existsSync(tsconfigPath), 'tsconfig.json not found for TypeScript adapter');
}

Expand Down Expand Up @@ -461,7 +463,7 @@ function runCommandWithFileChange(command, args, options = {}) {
if (!fileChanged && options.initialMessage && str.match(options.initialMessage)) {
console.log('Initial message detected, triggering file change...');
fileChanged = true;

// Wait a bit then trigger file change
setTimeout(() => {
if (options.fileToChange) {
Expand All @@ -476,13 +478,13 @@ function runCommandWithFileChange(command, args, options = {}) {
}
}, 5000);
}

// Detect restart and wait for it to complete
if (fileChanged && !restartDetected && str.match(/restarting|restart/i)) {
console.log('Restart detected...');
restartDetected = true;
}

// After restart, wait for final message
if (restartDetected && options.finalMessage && str.match(options.finalMessage)) {
console.log('Final message after restart detected, shutting down...');
Expand Down