|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const { program } = require('commander'); |
| 4 | +const Gateway = require('../lib/proxy'); |
| 5 | +const fetchAuthData = require('../lib/settings').fetchSettings; |
| 6 | +const logger = require('../lib/logger'); |
| 7 | + |
| 8 | +program |
| 9 | + .name('pos-cli test list') |
| 10 | + .argument('<environment>', 'name of environment. Example: staging') |
| 11 | + .action(async (environment) => { |
| 12 | + const authData = fetchAuthData(environment, program); |
| 13 | + const gateway = new Gateway(authData); |
| 14 | + |
| 15 | + try { |
| 16 | + // First check if tests module is installed |
| 17 | + const modules = await gateway.listModules(); |
| 18 | + const hasTestsModule = modules.data && modules.data.some(module => module === 'tests'); |
| 19 | + |
| 20 | + if (!hasTestsModule) { |
| 21 | + logger.Error(`Tests module not found. Please install the tests module: |
| 22 | + pos-cli modules install tests |
| 23 | + pos-cli deploy ${environment} |
| 24 | +Then re-run the command.`); |
| 25 | + process.exit(1); |
| 26 | + } |
| 27 | + |
| 28 | + const response = await gateway.listTests(); |
| 29 | + |
| 30 | + if (response && Array.isArray(response) && response.length > 0) { |
| 31 | + logger.Info('Available tests:'); |
| 32 | + response.forEach(test => { |
| 33 | + const name = test.name || test; |
| 34 | + logger.Info(` - ${name}`, { hideTimestamp: true }); |
| 35 | + }); |
| 36 | + logger.Info(`\nTotal: ${response.length} test(s)`, { hideTimestamp: true }); |
| 37 | + } else if (response && response.tests && Array.isArray(response.tests)) { |
| 38 | + logger.Info('Available tests:'); |
| 39 | + response.tests.forEach(test => { |
| 40 | + const name = test.name || test; |
| 41 | + logger.Info(` - ${name}`, { hideTimestamp: true }); |
| 42 | + }); |
| 43 | + logger.Info(`\nTotal: ${response.tests.length} test(s)`, { hideTimestamp: true }); |
| 44 | + } else { |
| 45 | + logger.Info('No tests found'); |
| 46 | + } |
| 47 | + } catch (error) { |
| 48 | + logger.Error(`Failed to list tests: ${error.message}`); |
| 49 | + process.exit(1); |
| 50 | + } |
| 51 | + }); |
| 52 | + |
| 53 | +program.parse(process.argv); |
0 commit comments