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
## 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

View File

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

View File

@@ -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

View File

@@ -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();

View File

@@ -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();

View File

@@ -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.'
}