diff --git a/test/adapters/test-js.create-adapter.json b/test/adapters/test-js.create-adapter.json index d9edcf7e..61c3d788 100644 --- a/test/adapters/test-js.create-adapter.json +++ b/test/adapters/test-js.create-adapter.json @@ -22,9 +22,10 @@ "language": "JavaScript", "nodeVersion": "20", "adminUi": "json", + "tabReact": "no", + "eslintConfig": "official", "tools": [ - "ESLint", - "type checking" + "ESLint" ], "releaseScript": "no", "devServer": "no", @@ -40,5 +41,5 @@ "defaultBranch": "main", "license": "MIT License", "dependabot": "yes", - "creatorVersion": "2.6.5" + "creatorVersion": "3.0.0" } \ No newline at end of file diff --git a/test/adapters/test-pure-ts.create-adapter.json b/test/adapters/test-pure-ts.create-adapter.json index 4402187d..b76c8c86 100644 --- a/test/adapters/test-pure-ts.create-adapter.json +++ b/test/adapters/test-pure-ts.create-adapter.json @@ -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", @@ -42,5 +43,5 @@ "defaultBranch": "main", "license": "MIT License", "dependabot": "yes", - "creatorVersion": "2.6.5" + "creatorVersion": "3.0.0" } \ No newline at end of file diff --git a/test/adapters/test-ts.create-adapter.json b/test/adapters/test-ts.create-adapter.json index cbb38a42..c29e97da 100644 --- a/test/adapters/test-ts.create-adapter.json +++ b/test/adapters/test-ts.create-adapter.json @@ -23,9 +23,10 @@ "language": "TypeScript", "nodeVersion": "20", "adminUi": "json", + "tabReact": "no", + "eslintConfig": "official", "tools": [ - "ESLint", - "type checking" + "ESLint" ], "releaseScript": "no", "devServer": "no", @@ -41,5 +42,5 @@ "defaultBranch": "main", "license": "MIT License", "dependabot": "yes", - "creatorVersion": "2.6.5" + "creatorVersion": "3.0.0" } \ No newline at end of file diff --git a/test/pure-ts-adapters.test.js b/test/pure-ts-adapters.test.js index 044f7500..8983a010 100644 --- a/test/pure-ts-adapters.test.js +++ b/test/pure-ts-adapters.test.js @@ -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, @@ -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(() => { @@ -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', () => { diff --git a/test/test-utils.js b/test/test-utils.js index bab35af5..a9270f40 100644 --- a/test/test-utils.js +++ b/test/test-utils.js @@ -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 { @@ -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...'); @@ -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 @@ -250,7 +252,7 @@ async function setupTestAdapter(config) { // Install dependencies await installAdapterDependencies(adapterName, adapterDir); - + console.log(`${adapterName} test adapter prepared successfully`); } @@ -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");', @@ -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`); } @@ -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')); @@ -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; } @@ -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'); } @@ -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) { @@ -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...');