UNPKG

haz-cli

Version:
44 lines (43 loc) 1.68 kB
import { Args, ux } from '@oclif/core'; import { CLIError } from "@oclif/core/lib/errors/index.js"; import * as fs from "node:fs"; import { parse } from 'yaml'; import { BaseCommand } from "../../base-command.js"; import Compose from "../../docker/compose.js"; import Env from "../../haz/env.js"; export default class Coverage extends BaseCommand { static args = { service: Args.string({ description: 'The service you want to run tests on.', required: true, }), }; static description = 'Run coverage tests on a container.'; static summary = 'Run coverage tests on a container.'; async run() { const { args } = await this.parse(Coverage); const directory = process.cwd(); const file = fs.readFileSync(directory + '/' + Env.dockerComposeFile(), 'utf8'); const composerFile = parse(file); // Ensure the service exists if (!composerFile.services[args.service]) { throw new CLIError(`The service ${args.service} does not exist in the docker-compose.yml file.`); } ux.action.start('Running tests on ' + args.service); const command = Compose.setService(args.service).run(Env.docker(args.service).coverage.split(' ')); command.stdout.on('data', (data) => { this.log(data.toString()); }); command.stderr.on('data', (data) => { this.log(data.toString()); }); command.on('exit', (code) => { if (code === 0) { ux.action.stop('Tests passed'); } else { ux.action.stop('Tests failed'); } }); } }