fix(tests): Migrate tests to Deno native runner and update Deno config

This commit is contained in:
2025-10-26 17:44:43 +00:00
parent 536ebca6ab
commit 95c4ae3b16
6 changed files with 86 additions and 95 deletions

View File

@@ -1,5 +1,15 @@
# Changelog # 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) ## 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 Rename project from npmci to szci and migrate runtime to Deno; add compiled binaries, installer and wrapper; update imports, env handling and package metadata

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ship.zone/szci", "name": "@ship.zone/szci",
"version": "6.0.0", "version": "5.0.0",
"exports": "./mod.ts", "exports": "./mod.ts",
"nodeModulesDir": "auto", "nodeModulesDir": "auto",
"tasks": { "tasks": {

View File

@@ -250,10 +250,17 @@ deno task dev --help
### Testing ### Testing
Tests will be migrated to Deno's native test framework: SZCI uses Deno's native test framework:
```sh ```sh
# Run all tests
deno task test 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 ## 📦 Binary Sizes

View File

@@ -1,10 +1,10 @@
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'; // Disable TLS certificate validation for testing
import { tap, expect } from '@push.rocks/tapbundle'; 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 () => { Deno.test('should be able to announce a container to cloudly', async () => {
const cloudlyConnector = new cloudlyConnectorMod.CloudlyConnector(null); const cloudlyConnector = new CloudlyConnector(null);
await cloudlyConnector.announceDockerContainer( await cloudlyConnector.announceDockerContainer(
{ {
registryUrl: 'registry.losssless.com', registryUrl: 'registry.losssless.com',
@@ -15,12 +15,3 @@ tap.test('should be able to announce a container to cloudly', async () => {
'cloudly.lossless.one' '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();

View File

@@ -1,97 +1,84 @@
import { tap, expect } from '@git.zone/tstest/tapbundle'; import { assertEquals } from '@std/assert';
import * as path from 'path'; import * as path from '@std/path';
import * as smartpath from '@push.rocks/smartpath'; import * as smartpath from '@push.rocks/smartpath';
process.env.NPMTS_TEST = 'true'; // Set up test environment
process.env.NPMCI_URL_CLOUDLY = 'localhost'; 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 // Get the test assets directory
process.env.CI_REPOSITORY_URL = 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git'; const testAssetsDir = path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), 'assets/');
process.env.CI_BUILD_TOKEN = 'kjlkjfiudofiufs';
// Docker // Save original cwd and change to test assets
process.env.NPMCI_LOGIN_DOCKER = 'docker.io|someuser|somepass'; const originalCwd = Deno.cwd();
Deno.chdir(testAssetsDir);
// SSH env import type { Dockerfile } from '../ts/manager.docker/mod.classes.dockerfile.ts';
process.env.NPMCI_SSHKEY_1 = 'hostString|somePrivKey|##'; import { Szci } from '../ts/szci.classes.szci.ts';
import * as DockerfileModule from '../ts/manager.docker/mod.classes.dockerfile.ts';
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');
// ====== // ======
// Docker // Docker
// ====== // ======
let dockerfile1: npmciTypes.Dockerfile; let dockerfile1: Dockerfile;
let dockerfile2: npmciTypes.Dockerfile; let dockerfile2: Dockerfile;
let sortableArray: npmciTypes.Dockerfile[]; let sortableArray: Dockerfile[];
tap.test('should return valid Dockerfiles', async () => { Deno.test('should return valid Dockerfiles', async () => {
const npmciInstance = new npmci.Npmci(); const szciInstance = new Szci();
await npmciInstance.start(); await szciInstance.start();
dockerfile1 = new npmci.Dockerfile(npmciInstance.dockerManager, { dockerfile1 = new DockerfileModule.Dockerfile(szciInstance.dockerManager, {
filePath: './Dockerfile', filePath: './Dockerfile',
read: true, read: true,
}); });
dockerfile2 = new npmci.Dockerfile(npmciInstance.dockerManager, { dockerfile2 = new DockerfileModule.Dockerfile(szciInstance.dockerManager, {
filePath: './Dockerfile_sometag1', filePath: './Dockerfile_sometag1',
read: true, read: true,
}); });
expect(dockerfile1.version).toEqual('latest'); assertEquals(dockerfile1.version, 'latest');
return expect(dockerfile2.version).toEqual('sometag1'); assertEquals(dockerfile2.version, 'sometag1');
}); });
tap.test('should read a directory of Dockerfiles', async () => { Deno.test('should read a directory of Dockerfiles', async () => {
const npmciInstance = new npmci.Npmci(); const szciInstance = new Szci();
await npmciInstance.start(); await szciInstance.start();
return npmci.Dockerfile.readDockerfiles(npmciInstance.dockerManager).then( const readDockerfilesArray = await DockerfileModule.Dockerfile.readDockerfiles(
async (readDockerfilesArrayArg: npmciTypes.Dockerfile[]) => { szciInstance.dockerManager
sortableArray = readDockerfilesArrayArg;
return expect(readDockerfilesArrayArg[1].version).toEqual('sometag1');
}
); );
sortableArray = readDockerfilesArray;
assertEquals(readDockerfilesArray[1].version, 'sometag1');
}); });
tap.test('should sort an array of Dockerfiles', async () => { Deno.test('should sort an array of Dockerfiles', async () => {
return npmci.Dockerfile.sortDockerfiles(sortableArray).then( const sortedArray = await DockerfileModule.Dockerfile.sortDockerfiles(sortableArray);
async (sortedArrayArg: npmciTypes.Dockerfile[]) => { console.log(sortedArray);
console.log(sortedArrayArg);
}
);
}); });
tap.test('should build all Dockerfiles', async () => { Deno.test('should build all Dockerfiles', async () => {
const npmciInstance = new npmci.Npmci(); const szciInstance = new Szci();
await npmciInstance.start(); await szciInstance.start();
return npmciInstance.dockerManager.handleCli({ await szciInstance.dockerManager.handleCli({
_: ['docker', 'build'], _: ['docker', 'build'],
}); });
}); });
tap.test('should test all Dockerfiles', async () => { Deno.test('should test all Dockerfiles', async () => {
const npmciInstance = new npmci.Npmci(); const szciInstance = new Szci();
await npmciInstance.start(); await szciInstance.start();
return npmciInstance.dockerManager.handleCli({ await szciInstance.dockerManager.handleCli({
_: ['docker', 'test'], _: ['docker', 'test'],
}); });
}); });
tap.test('should test dockerfiles', async () => { Deno.test('should login docker daemon', async () => {
const npmciInstance = new npmci.Npmci(); const szciInstance = new Szci();
await npmciInstance.start(); await szciInstance.start();
return npmciInstance.dockerManager.handleCli({ await szciInstance.dockerManager.handleCli({
_: ['docker', 'test'],
});
});
tap.test('should login docker daemon', async () => {
const npmciInstance = new npmci.Npmci();
await npmciInstance.start();
return npmciInstance.dockerManager.handleCli({
_: ['docker', 'login'], _: ['docker', 'login'],
}); });
}); });
@@ -99,9 +86,9 @@ tap.test('should login docker daemon', async () => {
// === // ===
// SSH // SSH
// === // ===
tap.test('should prepare SSH keys', async () => { Deno.test('should prepare SSH keys', async () => {
const npmciModSsh = await import('../ts/mod_ssh/index.js'); const npmciModSsh = await import('../ts/mod_ssh/index.ts');
return await npmciModSsh.handleCli({ await npmciModSsh.handleCli({
_: ['ssh', 'prepare'], _: ['ssh', 'prepare'],
}); });
}); });
@@ -109,25 +96,21 @@ tap.test('should prepare SSH keys', async () => {
// ==== // ====
// node // node
// ==== // ====
tap.test('should install a certain version of node', async () => { Deno.test('should install a certain version of node', async () => {
const npmciInstance = new npmci.Npmci(); const szciInstance = new Szci();
await npmciInstance.start(); await szciInstance.start();
await npmciInstance.nodejsManager.handleCli({ await szciInstance.nodejsManager.handleCli({
_: ['node', 'install', 'stable'], _: ['node', 'install', 'stable'],
}); });
await npmciInstance.nodejsManager.handleCli({ await szciInstance.nodejsManager.handleCli({
_: ['node', 'install', 'lts'], _: ['node', 'install', 'lts'],
}); });
await npmciInstance.nodejsManager.handleCli({ await szciInstance.nodejsManager.handleCli({
_: ['node', 'install', 'legacy'], _: ['node', 'install', 'legacy'],
}); });
}); });
// make sure test ends all right // Restore original working directory after all tests
tap.test('reset paths', async () => { Deno.test('reset paths', () => {
process.cwd = () => { Deno.chdir(originalCwd);
return path.join(__dirname, '../');
};
}); });
tap.start();

View File

@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@ship.zone/szci', 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.' 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.'
} }