Skip to content

Commit ca28709

Browse files
authored
Merge pull request #539 from ioBroker/copilot/adjust-typescript-test-adapter-creator
Use adapter-creator native TypeScript without build support
2 parents f8bf50e + e6ae36c commit ca28709

File tree

5 files changed

+35
-53
lines changed

5 files changed

+35
-53
lines changed

test/adapters/test-js.create-adapter.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
"language": "JavaScript",
2323
"nodeVersion": "20",
2424
"adminUi": "json",
25+
"tabReact": "no",
26+
"eslintConfig": "official",
2527
"tools": [
26-
"ESLint",
27-
"type checking"
28+
"ESLint"
2829
],
2930
"releaseScript": "no",
3031
"devServer": "no",
@@ -40,5 +41,5 @@
4041
"defaultBranch": "main",
4142
"license": "MIT License",
4243
"dependabot": "yes",
43-
"creatorVersion": "2.6.5"
44+
"creatorVersion": "3.0.0"
4445
}

test/adapters/test-pure-ts.create-adapter.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
"connectionType": "local",
2222
"dataSource": "poll",
2323
"connectionIndicator": "no",
24-
"language": "TypeScript",
24+
"language": "TypeScript (without build)",
2525
"nodeVersion": "20",
2626
"adminUi": "json",
27+
"tabReact": "no",
28+
"eslintConfig": "official",
2729
"tools": [
28-
"ESLint",
29-
"type checking"
30+
"ESLint"
3031
],
3132
"releaseScript": "no",
3233
"devServer": "no",
@@ -42,5 +43,5 @@
4243
"defaultBranch": "main",
4344
"license": "MIT License",
4445
"dependabot": "yes",
45-
"creatorVersion": "2.6.5"
46+
"creatorVersion": "3.0.0"
4647
}

test/adapters/test-ts.create-adapter.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
"language": "TypeScript",
2424
"nodeVersion": "20",
2525
"adminUi": "json",
26+
"tabReact": "no",
27+
"eslintConfig": "official",
2628
"tools": [
27-
"ESLint",
28-
"type checking"
29+
"ESLint"
2930
],
3031
"releaseScript": "no",
3132
"devServer": "no",
@@ -41,5 +42,5 @@
4142
"defaultBranch": "main",
4243
"license": "MIT License",
4344
"dependabot": "yes",
44-
"creatorVersion": "2.6.5"
45+
"creatorVersion": "3.0.0"
4546
}

test/pure-ts-adapters.test.js

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ const { describe, it, before, after } = require('mocha');
22
const assert = require('node:assert');
33
const fs = require('node:fs');
44
const path = require('node:path');
5-
const {
6-
runCommand,
5+
const {
6+
runCommand,
77
runCommandWithSignal,
88
runCommandWithFileChange,
9-
setupTestAdapter,
9+
setupTestAdapter,
1010
cleanupTestAdapter,
1111
validateIoPackageJson,
1212
validatePackageJson,
@@ -37,30 +37,8 @@ describe('dev-server integration tests - Pure TypeScript', function () {
3737
adapterName: 'Pure TypeScript',
3838
configFile: PURE_TS_ADAPTER_CONFIG,
3939
adapterDir: PURE_TS_ADAPTER_DIR,
40-
adaptersDir: ADAPTERS_DIR,
41-
needsTypeScriptPatching: true
40+
adaptersDir: ADAPTERS_DIR
4241
});
43-
44-
// Patch package.json to point main directly to src/main.ts (pure TypeScript mode)
45-
const packageJsonPath = path.join(PURE_TS_ADAPTER_DIR, 'package.json');
46-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
47-
packageJson.main = 'src/main.ts'; // Point directly to TypeScript file
48-
packageJson.files.push('src/'); // Ensure src is included in files
49-
50-
// Remove build scripts as they're not needed for pure TypeScript mode
51-
if (packageJson.scripts) {
52-
delete packageJson.scripts.build;
53-
delete packageJson.scripts['build:ts'];
54-
delete packageJson.scripts.prebuild;
55-
delete packageJson.scripts.watch;
56-
delete packageJson.scripts['watch:ts'];
57-
58-
// Keep type checking but make it not generate files
59-
packageJson.scripts.build = 'tsc --noEmit';
60-
}
61-
62-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
63-
console.log(`Patched ${packageJsonPath} to use pure TypeScript mode`);
6442
});
6543

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

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

9168
it('should have TypeScript source file but no dist directory', () => {

test/test-utils.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function runCommand(command, args, options = {}) {
3939
proc.on('close', (code) => {
4040
if (rejectedOrResolved) return;
4141
if (timeoutId) clearTimeout(timeoutId);
42+
console.log(`Process exited with code ${code}`);
4243
if (code === 0 || code === 255) {
4344
setTimeout(() => resolve({ stdout, stderr, code }), 5000);
4445
} else {
@@ -116,12 +117,12 @@ function runCommandWithTimeout(command, args, options = {}) {
116117
if (options.verbose) {
117118
console.log('STDOUT:', str.trim());
118119
}
119-
120+
120121
// Call custom stdout handler if provided
121122
if (options.onStdout) {
122123
options.onStdout(str, shutDown);
123124
}
124-
125+
125126
// Default behavior: shutdown on final message
126127
if (!options.onStdout && options.finalMessage && str.match(options.finalMessage) && !closed && !resolvedOrRejected) {
127128
console.log('Final message detected, shutting down...');
@@ -196,7 +197,8 @@ async function createTestAdapter(configFile, targetDir) {
196197
'@iobroker/create-adapter@latest',
197198
`--replay=${configPath}`,
198199
`--target=${targetDir}`,
199-
'--noInstall' // Skip npm install to speed up creation
200+
'--noInstall', // Skip npm install to speed up creation
201+
'--nonInteractive' // Run in non-interactive mode to fill in missing config details
200202
], {
201203
cwd: targetDir,
202204
timeout: 180000, // 3 minutes
@@ -250,7 +252,7 @@ async function setupTestAdapter(config) {
250252

251253
// Install dependencies
252254
await installAdapterDependencies(adapterName, adapterDir);
253-
255+
254256
console.log(`${adapterName} test adapter prepared successfully`);
255257
}
256258

@@ -260,7 +262,7 @@ async function setupTestAdapter(config) {
260262
async function applyTypeScriptPatches(adapterDir) {
261263
const mainTsPath = path.join(adapterDir, 'src', 'main.ts');
262264
let mainTsContent = fs.readFileSync(mainTsPath, 'utf8');
263-
265+
264266
// Patch variable declarations for TypeScript compliance
265267
mainTsContent = mainTsContent.replace(
266268
'let result = await this.checkPasswordAsync("admin", "iobroker");',
@@ -274,7 +276,7 @@ async function applyTypeScriptPatches(adapterDir) {
274276
'this.log.info("check group user admin group admin: " + result);',
275277
'this.log.info("check group user admin group admin: " + groupResult);',
276278
);
277-
279+
278280
fs.writeFileSync(mainTsPath, mainTsContent, 'utf8');
279281
console.log(`Patched ${mainTsPath} for TypeScript compliance`);
280282
}
@@ -314,7 +316,7 @@ function cleanupTestAdapter(adapterName, adapterDir) {
314316
function validateIoPackageJson(adapterDir, expectedName, shouldHaveTypescript = false) {
315317
const ioPackagePath = path.join(adapterDir, 'io-package.json');
316318
const assert = require('node:assert');
317-
319+
318320
assert.ok(fs.existsSync(ioPackagePath), 'io-package.json not found');
319321

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

330332
/**
331-
* Common assertions for package.json validation
333+
* Common assertions for package.json validation
332334
*/
333335
function validatePackageJson(adapterDir) {
334336
const packagePath = path.join(adapterDir, 'package.json');
335337
const assert = require('node:assert');
336-
338+
337339
assert.ok(fs.existsSync(packagePath), 'package.json not found');
338340

339341
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
340342
assert.ok(packageJson.name, 'package.json missing name');
341343
assert.ok(packageJson.version, 'package.json missing version');
342-
344+
343345
return packageJson;
344346
}
345347

@@ -349,7 +351,7 @@ function validatePackageJson(adapterDir) {
349351
function validateTypeScriptConfig(adapterDir) {
350352
const tsconfigPath = path.join(adapterDir, 'tsconfig.json');
351353
const assert = require('node:assert');
352-
354+
353355
assert.ok(fs.existsSync(tsconfigPath), 'tsconfig.json not found for TypeScript adapter');
354356
}
355357

@@ -461,7 +463,7 @@ function runCommandWithFileChange(command, args, options = {}) {
461463
if (!fileChanged && options.initialMessage && str.match(options.initialMessage)) {
462464
console.log('Initial message detected, triggering file change...');
463465
fileChanged = true;
464-
466+
465467
// Wait a bit then trigger file change
466468
setTimeout(() => {
467469
if (options.fileToChange) {
@@ -476,13 +478,13 @@ function runCommandWithFileChange(command, args, options = {}) {
476478
}
477479
}, 5000);
478480
}
479-
481+
480482
// Detect restart and wait for it to complete
481483
if (fileChanged && !restartDetected && str.match(/restarting|restart/i)) {
482484
console.log('Restart detected...');
483485
restartDetected = true;
484486
}
485-
487+
486488
// After restart, wait for final message
487489
if (restartDetected && options.finalMessage && str.match(options.finalMessage)) {
488490
console.log('Final message after restart detected, shutting down...');

0 commit comments

Comments
 (0)