npmci/test/test.ts

130 lines
3.4 KiB
TypeScript

import { tap, expect } from '@pushrocks/tapbundle';
import * as path from 'path';
import * as smartpath from '@pushrocks/smartpath';
process.env.NPMTS_TEST = 'true';
process.env.NPMCI_URL_CLOUDLY = 'localhost'
// set up environment
process.env.CI_REPOSITORY_URL = 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git';
process.env.CI_BUILD_TOKEN = 'kjlkjfiudofiufs';
// Docker
process.env.NPMCI_LOGIN_DOCKER = 'docker.io|someuser|somepass';
// SSH env
process.env.NPMCI_SSHKEY_1 = 'hostString|somePrivKey|##';
process.cwd = () => {
return path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), 'assets/');
};
let npmci: typeof import('../ts/index.js');
tap.preTask('should import npmci', async () => {
npmci = await import('../ts/index.js');
})
// ======
// Docker
// ======
let dockerfile1: npmci.Dockerfile;
let dockerfile2: npmci.Dockerfile;
let sortableArray: npmci.Dockerfile[];
tap.test('should return valid Dockerfiles', async () => {
const npmciInstance = new npmci.Npmci();
dockerfile1 = new npmci.Dockerfile(npmciInstance.dockerManager, {
filePath: './Dockerfile',
read: true,
});
dockerfile2 = new npmci.Dockerfile(npmciInstance.dockerManager, {
filePath: './Dockerfile_sometag1',
read: true,
});
expect(dockerfile1.version).toEqual('latest');
return expect(dockerfile2.version).toEqual('sometag1');
});
tap.test('should read a directory of Dockerfiles', async () => {
const npmciInstance = new npmci.Npmci();
return npmci.Dockerfile.readDockerfiles(npmciInstance.dockerManager).then(
async (readDockerfilesArrayArg: npmci.Dockerfile[]) => {
sortableArray = readDockerfilesArrayArg;
return expect(readDockerfilesArrayArg[1].version).toEqual('sometag1');
}
);
});
tap.test('should sort an array of Dockerfiles', async () => {
return npmci.Dockerfile.sortDockerfiles(sortableArray).then(
async (sortedArrayArg: npmci.Dockerfile[]) => {
console.log(sortedArrayArg);
}
);
});
tap.test('should build all Dockerfiles', async () => {
const npmciInstance = new npmci.Npmci();
return npmciInstance.dockerManager.handleCli({
_: ['docker', 'build'],
});
});
tap.test('should test all Dockerfiles', async () => {
const npmciInstance = new npmci.Npmci();
return npmciInstance.dockerManager.handleCli({
_: ['docker', 'test'],
});
});
tap.test('should test dockerfiles', async () => {
const npmciInstance = new npmci.Npmci();
return npmciInstance.dockerManager.handleCli({
_: ['docker', 'test'],
});
});
tap.test('should login docker daemon', async () => {
const npmciInstance = new npmci.Npmci();
return npmciInstance.dockerManager.handleCli({
_: ['docker', 'login'],
});
});
// ===
// SSH
// ===
tap.test('should prepare SSH keys', async () => {
const npmciModSsh = await import('../ts/mod_ssh/index.js');
return await npmciModSsh.handleCli({
_: ['ssh', 'prepare'],
});
});
// ====
// node
// ====
tap.test('should install a certain version of node', async () => {
const npmciInstance = new npmci.Npmci();
await npmciInstance.nodejsManager.handleCli({
_: ['node', 'install', 'stable'],
});
await npmciInstance.nodejsManager.handleCli({
_: ['node', 'install', 'lts'],
});
await npmciInstance.nodejsManager.handleCli({
_: ['node', 'install', 'legacy'],
});
});
// make sure test ends all right
tap.test('reset paths', async () => {
process.cwd = () => {
return path.join(__dirname, '../');
};
});
tap.start();