From 95c4ae3b161a6519a4ebc86192641759a9255b25 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Sun, 26 Oct 2025 17:44:43 +0000 Subject: [PATCH] fix(tests): Migrate tests to Deno native runner and update Deno config --- changelog.md | 10 +++ deno.json | 2 +- readme.md | 9 ++- test/test.cloudly.ts | 19 ++---- test/test.ts | 139 +++++++++++++++++---------------------- ts/00_commitinfo_data.ts | 2 +- 6 files changed, 86 insertions(+), 95 deletions(-) diff --git a/changelog.md b/changelog.md index 6d9bf7f..8959c9c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,15 @@ # Changelog +## 2025-10-26 - 6.0.1 - fix(tests) +Migrate tests to Deno native runner and update Deno config + +- Convert test suites from tap/tapbundle to Deno.test and @std/assert +- Replace CommonJS-style runtime imports with .ts module imports for Deno (test files updated) +- Use Deno.env.set to configure test environment variables and restore working directory after tests +- Update test/test.cloudly.ts to import CloudlyConnector directly and disable TLS verification for tests +- Adjust deno.json version field (6.0.0 -> 5.0.0) as part of Deno configuration changes +- Add local project .claude/settings.local.json for tooling permissions + ## 2025-10-26 - 6.0.0 - BREAKING CHANGE(szci) Rename project from npmci to szci and migrate runtime to Deno; add compiled binaries, installer and wrapper; update imports, env handling and package metadata diff --git a/deno.json b/deno.json index 9d808a9..119ba4f 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@ship.zone/szci", - "version": "6.0.0", + "version": "5.0.0", "exports": "./mod.ts", "nodeModulesDir": "auto", "tasks": { diff --git a/readme.md b/readme.md index 1da2891..0a8f391 100644 --- a/readme.md +++ b/readme.md @@ -250,10 +250,17 @@ deno task dev --help ### Testing -Tests will be migrated to Deno's native test framework: +SZCI uses Deno's native test framework: ```sh +# Run all tests deno task test + +# Run tests in watch mode +deno task test:watch + +# Run specific test file +deno test --allow-all test/test.cloudly.ts ``` ## 📦 Binary Sizes diff --git a/test/test.cloudly.ts b/test/test.cloudly.ts index a677be2..ef70b13 100644 --- a/test/test.cloudly.ts +++ b/test/test.cloudly.ts @@ -1,10 +1,10 @@ -process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'; -import { tap, expect } from '@push.rocks/tapbundle'; +// Disable TLS certificate validation for testing +Deno.env.set('NODE_TLS_REJECT_UNAUTHORIZED', '0'); -import * as cloudlyConnectorMod from '../ts/connector.cloudly/cloudlyconnector.js'; +import { CloudlyConnector } from '../ts/connector.cloudly/cloudlyconnector.ts'; -tap.test('should be able to announce a container to cloudly', async () => { - const cloudlyConnector = new cloudlyConnectorMod.CloudlyConnector(null); +Deno.test('should be able to announce a container to cloudly', async () => { + const cloudlyConnector = new CloudlyConnector(null); await cloudlyConnector.announceDockerContainer( { registryUrl: 'registry.losssless.com', @@ -15,12 +15,3 @@ tap.test('should be able to announce a container to cloudly', async () => { 'cloudly.lossless.one' ); }); - -tap.test('should close the program despite socket timeout', async (toolsArg) => { - // TODO: remove when unreffed timeouts in webrequest have been solved. - toolsArg.delayFor(0).then(() => { - process.exit(); - }); -}); - -tap.start(); diff --git a/test/test.ts b/test/test.ts index 644590b..4a59c22 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,97 +1,84 @@ -import { tap, expect } from '@git.zone/tstest/tapbundle'; -import * as path from 'path'; +import { assertEquals } from '@std/assert'; +import * as path from '@std/path'; import * as smartpath from '@push.rocks/smartpath'; -process.env.NPMTS_TEST = 'true'; -process.env.NPMCI_URL_CLOUDLY = 'localhost'; +// Set up test environment +Deno.env.set('NPMTS_TEST', 'true'); +Deno.env.set('NPMCI_URL_CLOUDLY', 'localhost'); +Deno.env.set('CI_REPOSITORY_URL', 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git'); +Deno.env.set('CI_BUILD_TOKEN', 'kjlkjfiudofiufs'); +Deno.env.set('NPMCI_LOGIN_DOCKER', 'docker.io|someuser|somepass'); +Deno.env.set('NPMCI_SSHKEY_1', 'hostString|somePrivKey|##'); -// set up environment -process.env.CI_REPOSITORY_URL = 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git'; -process.env.CI_BUILD_TOKEN = 'kjlkjfiudofiufs'; +// Get the test assets directory +const testAssetsDir = path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), 'assets/'); -// Docker -process.env.NPMCI_LOGIN_DOCKER = 'docker.io|someuser|somepass'; +// Save original cwd and change to test assets +const originalCwd = Deno.cwd(); +Deno.chdir(testAssetsDir); -// SSH env -process.env.NPMCI_SSHKEY_1 = 'hostString|somePrivKey|##'; - -process.cwd = () => { - return path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), 'assets/'); -}; - -import type * as npmciTypes from '../ts/index.js'; -const npmci = await import('../ts/index.js'); +import type { Dockerfile } from '../ts/manager.docker/mod.classes.dockerfile.ts'; +import { Szci } from '../ts/szci.classes.szci.ts'; +import * as DockerfileModule from '../ts/manager.docker/mod.classes.dockerfile.ts'; // ====== // Docker // ====== -let dockerfile1: npmciTypes.Dockerfile; -let dockerfile2: npmciTypes.Dockerfile; -let sortableArray: npmciTypes.Dockerfile[]; +let dockerfile1: Dockerfile; +let dockerfile2: Dockerfile; +let sortableArray: Dockerfile[]; -tap.test('should return valid Dockerfiles', async () => { - const npmciInstance = new npmci.Npmci(); - await npmciInstance.start(); - dockerfile1 = new npmci.Dockerfile(npmciInstance.dockerManager, { +Deno.test('should return valid Dockerfiles', async () => { + const szciInstance = new Szci(); + await szciInstance.start(); + dockerfile1 = new DockerfileModule.Dockerfile(szciInstance.dockerManager, { filePath: './Dockerfile', read: true, }); - dockerfile2 = new npmci.Dockerfile(npmciInstance.dockerManager, { + dockerfile2 = new DockerfileModule.Dockerfile(szciInstance.dockerManager, { filePath: './Dockerfile_sometag1', read: true, }); - expect(dockerfile1.version).toEqual('latest'); - return expect(dockerfile2.version).toEqual('sometag1'); + assertEquals(dockerfile1.version, 'latest'); + assertEquals(dockerfile2.version, 'sometag1'); }); -tap.test('should read a directory of Dockerfiles', async () => { - const npmciInstance = new npmci.Npmci(); - await npmciInstance.start(); - return npmci.Dockerfile.readDockerfiles(npmciInstance.dockerManager).then( - async (readDockerfilesArrayArg: npmciTypes.Dockerfile[]) => { - sortableArray = readDockerfilesArrayArg; - return expect(readDockerfilesArrayArg[1].version).toEqual('sometag1'); - } +Deno.test('should read a directory of Dockerfiles', async () => { + const szciInstance = new Szci(); + await szciInstance.start(); + const readDockerfilesArray = await DockerfileModule.Dockerfile.readDockerfiles( + szciInstance.dockerManager ); + sortableArray = readDockerfilesArray; + assertEquals(readDockerfilesArray[1].version, 'sometag1'); }); -tap.test('should sort an array of Dockerfiles', async () => { - return npmci.Dockerfile.sortDockerfiles(sortableArray).then( - async (sortedArrayArg: npmciTypes.Dockerfile[]) => { - console.log(sortedArrayArg); - } - ); +Deno.test('should sort an array of Dockerfiles', async () => { + const sortedArray = await DockerfileModule.Dockerfile.sortDockerfiles(sortableArray); + console.log(sortedArray); }); -tap.test('should build all Dockerfiles', async () => { - const npmciInstance = new npmci.Npmci(); - await npmciInstance.start(); - return npmciInstance.dockerManager.handleCli({ +Deno.test('should build all Dockerfiles', async () => { + const szciInstance = new Szci(); + await szciInstance.start(); + await szciInstance.dockerManager.handleCli({ _: ['docker', 'build'], }); }); -tap.test('should test all Dockerfiles', async () => { - const npmciInstance = new npmci.Npmci(); - await npmciInstance.start(); - return npmciInstance.dockerManager.handleCli({ +Deno.test('should test all Dockerfiles', async () => { + const szciInstance = new Szci(); + await szciInstance.start(); + await szciInstance.dockerManager.handleCli({ _: ['docker', 'test'], }); }); -tap.test('should test dockerfiles', async () => { - const npmciInstance = new npmci.Npmci(); - await npmciInstance.start(); - return npmciInstance.dockerManager.handleCli({ - _: ['docker', 'test'], - }); -}); - -tap.test('should login docker daemon', async () => { - const npmciInstance = new npmci.Npmci(); - await npmciInstance.start(); - return npmciInstance.dockerManager.handleCli({ +Deno.test('should login docker daemon', async () => { + const szciInstance = new Szci(); + await szciInstance.start(); + await szciInstance.dockerManager.handleCli({ _: ['docker', 'login'], }); }); @@ -99,9 +86,9 @@ tap.test('should login docker daemon', async () => { // === // SSH // === -tap.test('should prepare SSH keys', async () => { - const npmciModSsh = await import('../ts/mod_ssh/index.js'); - return await npmciModSsh.handleCli({ +Deno.test('should prepare SSH keys', async () => { + const npmciModSsh = await import('../ts/mod_ssh/index.ts'); + await npmciModSsh.handleCli({ _: ['ssh', 'prepare'], }); }); @@ -109,25 +96,21 @@ tap.test('should prepare SSH keys', async () => { // ==== // node // ==== -tap.test('should install a certain version of node', async () => { - const npmciInstance = new npmci.Npmci(); - await npmciInstance.start(); - await npmciInstance.nodejsManager.handleCli({ +Deno.test('should install a certain version of node', async () => { + const szciInstance = new Szci(); + await szciInstance.start(); + await szciInstance.nodejsManager.handleCli({ _: ['node', 'install', 'stable'], }); - await npmciInstance.nodejsManager.handleCli({ + await szciInstance.nodejsManager.handleCli({ _: ['node', 'install', 'lts'], }); - await npmciInstance.nodejsManager.handleCli({ + await szciInstance.nodejsManager.handleCli({ _: ['node', 'install', 'legacy'], }); }); -// make sure test ends all right -tap.test('reset paths', async () => { - process.cwd = () => { - return path.join(__dirname, '../'); - }; +// Restore original working directory after all tests +Deno.test('reset paths', () => { + Deno.chdir(originalCwd); }); - -tap.start(); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index da5a1b4..e1ce779 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@ship.zone/szci', - version: '6.0.0', + version: '6.0.1', description: 'Serve Zone CI - A tool to streamline Node.js and Docker workflows within CI environments, particularly GitLab CI, providing various CI/CD utilities. Powered by Deno with standalone executables.' }